In Ubuntu Linux, storage drives are traditionally assigned block device names like /dev/sda1 or /dev/nvme0n1p1. However, these device names are not persistent. If you plug a USB drive into a different port, or add a new hard drive to your motherboard, the operating system might reassign the letters (e.g., changing sda to sdb). This can cause catastrophic boot failures if your /etc/fstab file relies on these shifting names.
The Importance of UUIDs
To solve this problem, Linux uses a Universally Unique Identifier (UUID). A UUID is a long string of letters and numbers uniquely generated for the specific filesystem on a partition (for example, 1b3c9a45-6d7e-8f9a-0b1c-2d3e4f5a6b7c). Unlike block device names, a UUID never changes unless you completely reformat the partition. When configuring automatic mounts in Linux, you should always use the UUID.
Method 1: Using the blkid Command
The fastest and most common method to find the UUID of all connected drives is using the blkid command in the terminal.
- Open your terminal by pressing Ctrl + Alt + T.
- Type the following command and press Enter:
sudo blkid - Enter your administrator password when prompted.
The output will list all recognized partitions. Look for the partition you need (e.g., /dev/sda1) and find the section that reads UUID="your-unique-string-here". Be careful not to confuse it with the PARTUUID (Partition UUID), which serves a different purpose.
Method 2: Using the lsblk Command
If the output of blkid is too cluttered, you can format the output into a clean, easy-to-read tree structure using lsblk.
- Open the terminal.
- Type the following command and press Enter:
lsblk -o NAME,SIZE,FSTYPE,UUID,MOUNTPOINT - You do not need
sudoprivileges for this command.
This will display a neatly formatted table showing your drive names, their size, filesystem type, and their associated UUID in a dedicated column.
Method 3: Finding UUIDs via the GUI
If you prefer not to use the command line, you can find the UUID using the graphical “Disks” utility built into Ubuntu.
- Press the Super key and search for Disks.
- Open the application.
- Select your drive from the left-hand menu.
- Click on the specific partition in the Volumes graph.
- Look beneath the graph. You will see the UUID clearly listed next to the UUID label. You can even highlight and copy the text directly from this window.