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.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.