List size of all disks and partitions in bytes
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
Related videos on Youtube
Huckle
Updated on September 18, 2022Comments
-
Huckle over 1 year
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
- plain fdisk
-
Huckle over 9 yearsBut for some reason known only to the people who wrote it, parted will do this only for one disk at a time. The -l option ignores any attempt to use the unit command.
-
muru over 9 years@Huckle the
-l
ignores all commands. -
muru over 9 years@Huckle Anyway,
parted
doesn't seem to print labels. So you'll probably need to use something likelsblk
, and so while you're using it, you could loop over the entries of typedisk
in its output. -
Huckle over 9 yearsActually looks like
lsblk -ba
does what I want, even tells me which volumes are used in which lvm logical volumes. Submit that as an answer and I'll accept it. -
muru over 9 years@Huckle edited to add
lsblk
as well. -
Huckle over 9 yearsThe output format for
lsblk
is infuriating! The output table from either the-l
or the-i
invocations are not delimited, they're fixed width. That wouldn't be so bad, except that headers for purely numeric columns (size, MIN-IO) have right justified headers while all the others are left justified. This makes it nearly impossible to determine the column widths. -
muru over 9 years@Huckle What is it you're trying to do, exactly?
-
Huckle over 9 years
-
muru over 9 years@Huckle Try this command if you get a chance:
sudo parted <<<'unit B p all q'
-
Huckle over 9 yearsWorks until it hits the first unpartitioned disk (or in my case the first whole-disk LVM volume) at which point it throws an error
Error: /dev/sda: unrecognised disk label
and stops printing.