LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Why my bash script isn't partitioning the first two disks? (https://www.linuxquestions.org/questions/linux-newbie-8/why-my-bash-script-isnt-partitioning-the-first-two-disks-4175678859/)

maheshn0205 07-20-2020 02:16 PM

Quote:

Originally Posted by berndbausch (Post 6147375)
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.

berndbausch 07-20-2020 02:55 PM

I had overlooked that you format the smaller disks with an MBR partition table.

You could use /sys/block/$DISK/size. Or use lsblk; see https://www.linuxquestions.org/quest...9/#post6146298.

maheshn0205 07-20-2020 03:08 PM

Quote:

Originally Posted by berndbausch (Post 6147375)
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!

berndbausch 07-20-2020 04:59 PM

Quote:

Originally Posted by maheshn0205 (Post 6147416)
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



All times are GMT -5. The time now is 07:57 PM.