LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-20-2020, 02:16 PM   #16
maheshn0205
LQ Newbie
 
Registered: Oct 2019
Location: Fremont, CA
Distribution: CentOS, Ubuntu, Windows Server, VMWare
Posts: 8

Original Poster
Rep: Reputation: Disabled
Smile


Quote:
Originally Posted by berndbausch View Post
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.
 
Old 07-20-2020, 02:55 PM   #17
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
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.

Last edited by berndbausch; 07-20-2020 at 02:56 PM.
 
Old 07-20-2020, 03:08 PM   #18
maheshn0205
LQ Newbie
 
Registered: Oct 2019
Location: Fremont, CA
Distribution: CentOS, Ubuntu, Windows Server, VMWare
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by berndbausch View Post
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!
 
Old 07-20-2020, 04:59 PM   #19
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by maheshn0205 View Post
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Split a file into two - the first being the first two lines and the second the rest jasonws Linux - General 2 11-02-2010 04:32 AM
LFS Boot Problem(LILO,Two Distributions in Two Hard Disks) 51dunk Linux From Scratch 4 06-11-2007 08:57 AM
Two distros, two hard disks - boot scheme rabidundead Linux - Hardware 16 04-07-2004 08:52 PM
Two boot loaders in two hard disks qnguyendang Linux - General 1 02-06-2003 08:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration