How to Check the UUID of a Hard Drive in Linux Using the blkid Command

When configuring storage in Linux, relying on traditional device names like /dev/sda1 or /dev/nvme0n1p2 can be dangerous. These names can change depending on which SATA port a drive is plugged into or the order in which the kernel detects them during boot. If you mount drives using these dynamic names in your /etc/fstab file, your system might fail to boot if the drive order suddenly changes.

The safest way to reference a storage partition in Linux is by using its Universally Unique Identifier (UUID). Every formatted partition is assigned a permanent UUID that never changes, even if you physically move the hard drive to a different slot.

How to Check UUIDs Using the blkid Command

The quickest and most reliable way to find the UUID of any connected block device (hard drive, SSD, or USB flash drive) is to use the blkid command. Because this command queries low-level hardware information, it must be run with root privileges.

  1. Open your Linux Terminal.
  2. Type the following command and press Enter:
    sudo blkid
  3. Enter your administrator password when prompted.

The output will display a list of all detected partitions. Each line will look something like this:

/dev/sda1: UUID="1234abcd-56ef-78gh-90ij-klmnopqrstuv" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="abcdef12-01"

The string inside the quotes immediately following UUID= is the permanent identifier you should use in your configuration files.

How to Check the UUID of a Specific Drive

If you have many drives connected and the output of blkid is too cluttered, you can query a specific partition by appending its device name to the command.

For example, to find the UUID of the second partition on your first NVMe drive, type:

sudo blkid /dev/nvme0n1p2

This will output only the information relevant to that specific partition, making it much easier to copy and paste the UUID into your /etc/fstab file.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.