How to Find UUID of a Disk in Linux

Disk UUIDs are often used in /etc/fstab, automation scripts, and configuration management because they stay stable even if device names like /dev/sda or /dev/vdb change. This guide shows several practical ways to retrieve the UUID of a disk or partition on a Linux system.

1. Check /dev/disk/by-uuid

One of the most direct methods is to look at the special directory that exposes block devices by their UUID:

ls -l /dev/disk/by-uuid/

The output will show a list of symbolic links where the file name is the UUID and the target is the underlying block device, for example:

lrwxrwxrwx 1 root root 10 Jan 31 10:00 50216b20-ddb4-4a36-b306-d028b09d7807 -> ../../sda1
lrwxrwxrwx 1 root root 10 Jan 31 10:00 92df6435-4bce-4d8a-9a12-123456789abc -> ../../sda2

In this case, 50216b20-ddb4-4a36-b306-d028b09d7807 is the UUID of /dev/sda1, and 92df6435-4bce-4d8a-9a12-123456789abc is the UUID of /dev/sda2.

2. Use blkid to print UUIDs

The blkid utility scans block devices and prints filesystem metadata, including UUIDs and filesystem types.

List all detected devices with their UUIDs:

bashsudo blkid

Typical output may look like:

/dev/sda1: UUID="72C0DE8EC0DE57C5" TYPE="ntfs" LABEL="windows"
/dev/sda2: UUID="30fcb748-ad1e-4228-af2f-951e8e7b56df" TYPE="ext4"
/dev/vdb1: UUID="bfc23045-3e53-4853-99c6-6d9df90f3578" TYPE="ext4"

To query a specific device, pass it as an argument:

sudo blkid /dev/sda2

This prints a single line with the UUID and other attributes for that partition only.

3. Show UUIDs with lsblk

The lsblk command can display a tree of block devices together with filesystem information, including labels and UUIDs.

Run:

bashlsblk -f

Example output:

NAME   FSTYPE LABEL   UUID                                 MOUNTPOINT
sda
├─sda1 ntfs windows 72C0DE8EC0DE57C5 /mnt/windows
└─sda2 ext4 30fcb748-ad1e-4228-af2f-951e8e7b56df /
vdb
└─vdb1 ext4 bfc23045-3e53-4853-99c6-6d9df90f3578 /mnt/data

This format is convenient when you want to see the full layout of a disk, its partitions, and where they are mounted, all in one place.

On systems with many loop devices (for example, desktop distributions using snaps or multiple images), you can filter them out:

bashlsblk -f | grep -v loop

4. Check UUIDs already used in /etc/fstab

If you are troubleshooting mounts or preparing to edit /etc/fstab, it is useful to see which UUIDs are already configured there.

bashgrep UUID /etc/fstab

You might see lines such as:

textUUID=30fcb748-ad1e-4228-af2f-951e8e7b56df /          ext4 defaults 0 1
UUID=bfc23045-3e53-4853-99c6-6d9df90f3578 /mnt/data  ext4 defaults 0 2

After that, you can cross‑check these values with the output of lsblk, blkid or /dev/disk/by-uuid/ to understand which physical or virtual device each entry refers to.

5. When and why to use UUIDs

Using UUIDs instead of raw device paths gives you more robust and predictable mounts in several scenarios:

  • Persistent entries in /etc/fstab, so the system mounts the correct filesystem even if /dev/sda becomes /dev/sdb after hardware changes or reordering.
  • Cloud and VPS environments, where virtual disks can attach in a different order between reboots.
  • Hosts with multiple disks, RAID arrays, or complex storage stacks, where relying only on device names is fragile.

In real environments, it is common to combine these tools:

  • Use lsblk -f to get a quick overview of all disks, partitions, filesystem types and mount points.
  • Use blkid when you need a precise, script‑friendly way to read UUIDs and filesystem metadata.
  • Use /dev/disk/by-uuid for a direct mapping between a UUID string and a device node, especially in low‑level scripts and system configuration.

This set of commands covers most typical cases where you need to find the UUID of a disk or partition in Linux.

Rork
Rate author
Linux Hub
Add a comment