Its funny how, even after many years of working with Linux and other Unix-like systems, every now and then a little utility comes up that you never knew about.
blkid is one of those little utilities that is wonderfully
handy, and now I find myself using it all the time.
Run blkid on its own and it prints out all the block devices, with any filesystem lablels and uuid's that are found:
[catalina ~]# blkid /dev/hda3: LABEL="SWAP-hda3" TYPE="swap" /dev/hda2: LABEL="/" UUID="d9a928b6-36ed-46ba-b5f8-aef78f710851" TYPE="ext3" /dev/hda1: LABEL="/boot" UUID="63c9d7bd-0e53-4ee8-9069-328d536c07fc" TYPE="ext3"
It fits in just perfectly in shell scripts too, using the
format to give you something you can source into your script and set variables
[[email protected] ~]# blkid -o export /dev/sda9 LABEL=/home UUID=c42e9220-6df7-44d7-93bb-78f0a339b356 TYPE=ext3
And you can similarly search for a label or uuid and convert it to a device name (although keep in mind - filesystem labels and uuids are not necessarily unique!)
This all seems a bit pointless if you are running a modern desktop environment that helpfully automounts external devices for you. But should you find yourself writing code managing storage on headless systems, or if you are diagnosing a problem on a system and want a quick view of the devices and filesystems that are connected, blkid is just great.