Locate Disks in Ubuntu with findfs: Target UUID & LABEL

Introduction

Hardware device enumeration on Linux systems can fluctuate unpredictably across reboots, controller re-indexing, or storage reconfigurations. Relying on volatile node paths like /dev/sda1 or /dev/nvme0n1p2 introduces risk into automation scripts and mount operations. This guide explores the findfs utility, demonstrating how to reliably map persistent filesystem identifiers—such as UUIDs and volume labels—to concrete device paths for rock-solid partition discovery and resilient /etc/fstab management.

Understanding findfs and Inspecting Block Device Metadata

To inspect the hierarchy of attached storage subsystems alongside their associated filesystem signatures and persistent metadata tokens, execute lsblk -f.

Displaying block storage topology and filesystem identifiers

When an administrator requires detailed low-level hardware attributes—such as filesystem types (TYPE), partition identifiers (PARTUUID), and labels (PARTLABEL)—the blkid utility queries the libblkid cache directly:

Querying block device attributes with blkid

Operating as a lightweight frontend to the blkid library, the findfs command resolves an identifier specification (LABEL, UUID, PARTUUID, or PARTLABEL) directly into its corresponding canonical device path under /dev/.... This abstraction guarantees that administration tasks remain immune to shifts in physical device indexing.

⚙️ [Supported Identification Tags & CLI Flags]

-h, --help : Print utility usage syntax and exit.
-V, --version : Display software release details and terminate.
LABEL=<value> : Match the storage node configured with the designated filesystem label.
UUID=<value> : Locate the block device matching the unique filesystem UUID.
PARTLABEL=<value> : Trace the partition designated by the specified partition label.
PARTUUID=<value> : Resolve the partition bound to the given partition UUID.

Inspecting available findfs command options

Resolving Filesystem Device Paths via UUID

To extract the primary active filesystem UUID from the host and store it in an environment variable for testing, execute TARGET_UUID=$(lsblk -no UUID | grep -v '^$' | head -n 1) && echo "Target UUID: $TARGET_UUID".

Capturing active volume UUID into a shell variable

Feeding this retrieved identifier to findfs in the key-value format UUID=<value> triggers a lookup that returns the exact underlying device file. Systems lacking a valid UUID configuration on the target node will emit no device node.

Resolving concrete block device node from UUID

To evaluate how error handling operates when a signature fails to resolve against registered block devices, query an invalid dummy identifier via findfs UUID=00000000-0000-0000-0000-000000000000 || true. Appending || true prevents non-zero exit codes from aborting automated pipelines while exposing the standard lookup error.

Handling invalid identifier lookups safely

Practical Exercise: Virtual Disk Creation and LABEL-Based Resolution

Isolate the testing workspace by provisioning a dedicated directory and entering it using mkdir -p /tmp/findfs_test && cd /tmp/findfs_test.

Preparing isolated sandbox environment

Next, allocate a zeroed 64MB raw image file to serve as a virtual block device by executing dd if=/dev/zero of=test_disk.img bs=1M count=64.

Provisioning raw image storage file

Format the container image with an ext4 filesystem while applying a custom volume tag named MY_BACKUP via mkfs.ext4 -F -L MY_BACKUP test_disk.img.

Formatting ext4 partition with custom label

Attach the virtual disk image to the next available system loop device, saving the allocated device path into a variable via LOOP_DEV=$(losetup --find --show test_disk.img) && echo "Attached to: $LOOP_DEV".

Attaching disk image to loopback infrastructure

Query the active block device path using its volume descriptor with findfs LABEL=MY_BACKUP. This resolves the virtual volume to /dev/loopX immediately, proving that human-readable tags eliminate the need to memorize complex UUID strings or track dynamic device numbers.

Resolving loop device via filesystem label

Once verification is complete, dismantle the loop interface and scrub the scratch workspace using losetup -d "$LOOP_DEV" && cd / && rm -rf /tmp/findfs_test.

Detaching loop device and wiping sandbox files

Enhancing Storage Automation and /etc/fstab Reliability

Persistent mounting setups defined in /etc/fstab should favor declarative identifiers over raw kernel names. Inspect whether the existing system configuration relies on persistent tokens by running grep -E 'UUID|LABEL' /etc/fstab || true. Deploying these persistent attributes guarantees that drive reordering during storage controller resets never interrupts system initialization.

Checking persistent identifiers in fstab

In dynamic scripting workflows, one often needs to trace an active mount point back to its raw storage node. Combine findmnt and findfs to isolate the root filesystem (/) device dynamically via ROOT_DEV=$(findfs UUID="$(findmnt -no UUID /)") && echo "Root device: $ROOT_DEV".

Determining root storage device dynamically

With the active hardware node resolved in $ROOT_DEV, audit the volume capacity and real-time usage metrics in human-readable terms with df -h "$ROOT_DEV".

Verifying storage metrics on resolved block device

Leveraging findfs alongside persistent UUIDs and volume labels establishes predictable, error-free disk management workflows across modern Ubuntu environments. Implementing these practices shields enterprise servers and automated deployments against storage topology drift.