In Linux, is it possible to get a listing of drives' disk space usage that also shows volume labels?

1

I know about df, of course, but df does not output volume labels. I have 5 USB hard drives plugged into my NAS box, and would love to know which is which.

Current df output:

Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              27G  2.2G   24G   9% /
none                   56M  476K   55M   1% /dev
none                   60M     0   60M   0% /dev/shm
none                   60M  332K   59M   1% /var/run
none                   60M     0   60M   0% /var/lock
none                   60M     0   60M   0% /lib/init/rw
/dev/sde1             150G  102G   48G  68% /media/usb0
/dev/sdb1             299G  196G  103G  66% /media/usb1
/dev/sdc1             233G  183G   51G  79% /media/usb2
/dev/sdd1             233G  209G   25G  90% /media/usb3
/dev/sdf1             150G  101G   49G  68% /media/usb4

DavidH

Posted 2012-05-31T20:32:55.147

Reputation: 173

Have you looked into using fdisk -l ? – PenguinCoder – 2012-05-31T20:44:46.873

Strangely, fdisk -l isn't showing me any volume labels. It is giving me lots of nice info about partitions, though... – DavidH – 2012-05-31T23:05:42.507

Answers

1

Sure. Here's a shell one-liner that wraps df with the information from blkid:

df | while read line; do dev=${line%% *}; \
  blkid -s LABEL $dev | sed 's/.*LABEL=//; s/"//g'; \
  echo "$line"; done

That will print the label before each line from df, when there is a label. You can play around with it to suit the formatting to taste.

Greg Price

Posted 2012-05-31T20:32:55.147

Reputation: 176

0

You can use df to find out the disk space information and use blkid -o list to obtain information about the disk labels and UUIDs.

# blkid -o list
device     fs_type label    mount point    UUID
-------------------------------------------------------------------------------
/dev/sda1  ext4             /              2ea411b8-f6eb-456b-9ac8-efc1f264bee4
/dev/sda5  swap             <swap>         e5732469-d123-4f24-948b-ab356576c140

You have to be root to see the label and UUID values.

Marco

Posted 2012-05-31T20:32:55.147

Reputation: 4 015

Funny... blkid isn't reading my filesystem's label although I can see it with e2label. – devius – 2012-05-31T22:55:24.267

Thanks. There isn't any way to get both volume labels and disk space usage back from the same utility, is there? It's easy enough to cross-reference between the two when I'm running them manually, but I'm trying to write a nightly script that will send me a disk space report for each drive (and include volume labels). – DavidH – 2012-05-31T23:05:32.770