[parted-devel] Is this a bug? "parted /dev/sda print 1"

Brian C. Lane bcl at redhat.com
Wed Nov 11 16:35:43 UTC 2015


On Wed, Nov 11, 2015 at 11:59:18AM +0000, Gareth Randall wrote:
> Hi,
> 
> I was expecting the command "parted /dev/sda print 1" to display information
> just on the first partition of /dev/sda. Instead it exits without printing
> anything.
> 
> This expected behaviour was implied (to me) by the NUMBER option in the
> --help message below:
> 
> # ./parted --help
> ...
>   print [devices|free|list,all|NUMBER]     display the partition table,
>         available devices, free space, all found partitions, or a particular
>         partition
> ...

As far as I can tell it has never been implemented. I have it on my list
of things to eventually implement, but it's more of an oversight than a
bug.

 
> (Incidentally, my use case is that I need a simple command to test whether
> there are any partitions already on a device, and just return a yes or no.)

You could use 'parted -s -m /dev/blah p' and parse the output:

sudo parted -s -m /dev/blah p
Error: /dev/blah: unrecognised disk label
BYT;
/dev/blah:16.0GB:scsi:512:512:unknown:Lexar USB Flash Drive:;

echo $?
1


vs.

sudo parted -s -m /dev/blah p
BYT;
/dev/blah:16.0GB:scsi:512:512:gpt:Lexar USB Flash Drive:;
1:1049kB:2097kB:1049kB::p1:;

echo $?
0

That only reflects parted's view of the disk. The system's view could be
different (it shouldn't, but these days with udev races, who knows). It
may be more reliable to see if the system has any partitions at
/dev/blahX

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)



More information about the parted-devel mailing list