Why my bash script isn't partitioning the first two disks?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
Distribution: CentOS, Ubuntu, Windows Server, VMWare
Posts: 8
Original Poster
Rep:
Quote:
Originally Posted by berndbausch
fdisk output is hard to parse, leading to an overly complex program. Instead of fdisk, use /sys/block to generate a list of disks. Instead of computing disk sizes, use percentages in the parted commands.
EDIT: I just noticed you do the latter now. Good! But you don't need the capacity anymore and can you remove the case.
Hello Berndbausch. Thank you so much for reply. If you see my previous script, I commented out the #disk_size, here I'm partitioning the drives using disk_capacity such as TiB, GiB. Even though when I generate a list of disks from /sys/blocks who do I partition based on disk_capacity or the size? Sorry, if I'm asking too many questions.
Distribution: CentOS, Ubuntu, Windows Server, VMWare
Posts: 8
Original Poster
Rep:
Quote:
Originally Posted by berndbausch
fdisk output is hard to parse, leading to an overly complex program. Instead of fdisk, use /sys/block to generate a list of disks. Instead of computing disk sizes, use percentages in the parted commands.
EDIT: I just noticed you do the latter now. Good! But you don't need the capacity anymore and can you remove the case.
My requirement is to do a disk partition based on capacity, if the disk is in TiB it has to do gpt and if it is in GiB it has to be msdos. So if I remove the case, how do the disk's get partitioned? Can you post a syntax if possible to get an idea?
Thanks!
My requirement is to do a disk partition based on capacity, if the disk is in TiB it has to do gpt and if it is in GiB it has to be msdos.
I had overlooked this detail. I would do it like this:
Code:
cd /sys/block
for disk in sd[a-z] sd[a-z][a-z]
do
if (($(cat $disk/size) < 2000000000))
then label=msdos
else label=gpt
fi
parted -s ${disk} mklabel $label
parted -s ${disk} -a min mkpart primary xfs 0 100%
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.