Unmounted Disk Labels
Luke Hebert
- 2 minutes read - 267 wordsYou have a server with a dozen or so disks, and you want to know which labeled volumes are sitting idle without mounting each one individually. The command below walks through every symlink in /dev/disk/by-label/, resolves it to the underlying block device, checks /proc/mounts, and prints only the labels that are not currently in use.
The Command
for DISKLABEL in $(find /dev/disk/by-label/ -type l); do
RES=$(readlink -f "$DISKLABEL")
grep -q "^$RES" /proc/mounts || echo "$RES (${DISKLABEL#*/})"
doneHow It Works
- Find labeled devices.
find /dev/disk/by-label/ -type lreturns every symlink in the by-label directory. Each symlink name is the filesystem label you assigned withe2label,xfs_admin -L, or a similar tool. - Resolve the real device.
readlink -ffollows the symlink chain to the actual block device (for example,/dev/sdb1). - Check the mount table.
grep -q "^$RES" /proc/mountssilently succeeds if the device appears as a mount point. The||ensures theechoonly runs when the device is not found. - Print the label.
${DISKLABEL#*/}strips the leading/dev/disk/by-label/path so the output is clean, like/dev/sdb1 (DATA).
Example Output
/dev/sdb1 (DATA)
/dev/sdc1 (BACKUP)Each line tells you the block device and the human-readable label, making it easy to decide whether to mount, repurpose, or remove the volume.
Tips
- Run the command as a regular user; it only reads
/proc/mountsand the/dev/disksymlinks, so no root privileges are needed. - If you want the opposite list (devices that are mounted), simply remove the
||and thegrep -qguard, or invert the logic with&&. - Pair this with
lsblk -o NAME,LABEL,MOUNTPOINTfor a quick visual cross-check.