LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Partitioning wildcards (https://www.linuxquestions.org/questions/linux-newbie-8/partitioning-wildcards-863775/)

bahua 02-19-2011 02:25 PM

Partitioning wildcards
 
I'm building a p2v script for work, and in order to make it work I need a noninteractive command that will create a partition out of all the remaining space on a disk.

Example, with a drive that ends with 8552:

Code:

parted /dev/sda mkpart primary 102 8552
Only, it's going to depend every time, what that 8552 is. What I really want is a wildcard to tell parted(or whatever noninteractive partitioning tool I'm using) just to allocate all the remaining free space. Something like:

Code:

parted /dev/sda mkpart primary 102 *
-or-

Code:

parted /dev/sda mkpart primary 102 -1
Except, of course, one that will work, as these do not. :)

Am I up the creek here? Has anyone here ever dealt with this?

SJ-AvatarSmith 02-19-2011 04:01 PM

Yes...but...
 
Yes, I've run into this before, the answer was to use fdisk under awk to extract the size, I'll dig thru my archives and post a snippet when I get a moment of time. Alternatively you may want to look int lshw if you know the device name of the storage you can get its total size there, where as cat /proc/parttions does not give you a size.

Reuti 02-19-2011 04:42 PM

When there is no unit mentioned it defaults to megabyte. But it's possible to specify a different unitn there, i.e. something like 100%

bahua 02-27-2011 11:28 AM

I found a solution. It's sloppy but it works.

Code:

END=`parted /dev/sda print | grep ^Disk | awk '{ print $3}' | sed -e 's/MB$//'`
parted /dev/sda mkpart primary 1 101 mkpart primary 102 $END

It'll have to do.


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