4

I am looking through the various *fdisk and *parted utilities along with a few others. I am searching for a utility (or collection of utilities) that will list the size, in bytes, of all of the disks and partitions on a machine. Bonus points for any additional information on the drive or partition such as make/model/label/filesystem. It should also be able to report the size of drives with no partition table installed

  • plain fdisk
    • ✗ No GUID Partition Table support
    • ✗ Not in bytes, no flags to allow for it
  • sfdisk
    • ✗ No GUID Partition Table support
    • ✓ Flag to support Megabytes (close)
  • parted
    • ✓ Does support GPT
    • ! Option to control unit only works on one disk at a time
    • ✗ Rounds to largest possible unit
  • lshw
    • ✗ Doesn't show partition info
    • ✗ Rounds to highest unit
    • ✗ No option to control units
  • pvdisplay / pvs
    • ✗ Only works on disks that are part of LVM2 array
    • ✗ Doesn't show disk info if partition is volume used in array
    • ✓ Does have flags to set unit to bytes
Huckle
  • 7,258

1 Answers1

3

parted has a command to control units used, and it is called ... unit:

$ sudo parted /dev/sda unit B p    
Model: ATA ST500DM002-1BD14 (scsi)
Disk /dev/sda: 500107862016B
Sector size (logical/physical): 512B/4096B
Partition Table: msdos

Number  Start          End            Size           Type      File system
lags
 1      1048576B       105906175B     104857600B     primary   ntfs
oot
 2      105906176B     62914559999B   62808653824B   primary   ntfs
 3      62914560000B   95126814719B   32212254720B   primary   ext4
 4      95127862272B   500107837439B  404979975168B  extended
 5      95127863296B   127340118015B  32212254720B   logical   btrfs

From man parted:

unit unit
     Set unit as the unit to use when displaying locations and
     sizes,  and for interpreting those given by the user when
     not suffixed with an explicit unit.  unit can be  one  of
     "s"  (sectors),  "B" (bytes), "kB", "MB", "GB", "TB", "%"
     (percentage of device  size),  "cyl"  (cylinders),  "chs"
     (cylinders,  heads, sectors), or "compact" (megabytes for
     input, and a human-friendly form for output).

parted, while an excellent tool for modifying things, is somewhat deficient when it comes to presentation. lsblk is much better in this regard, it shows the relationship between the disks, partitions and constructs over the disks (such as RAID or LVM volumes).

By default, it does not show labels, and outputs most data without needing sudo; however labels need sudo. To show the disk information in bytes, one can use the -b option:

sudo lsblk -ba -o NAME,TYPE,LABEL,SIZE,MOUNTPOINT
muru
  • 207,228