The storage devices are physical devices that are used in Linux to store the data, and every storage device is associated with a unique number UUID. A hard disk can have several partitions to store the data, and every partition will have a separate UUID. This UUID is required to mount the partitions in a system with hundreds of hard drives.
This write-up will provide a basic understanding of the UUID and methods to find it with the below-supporting content:
Let’s get into the basics of finding the UUID of storage devices.
What is the UUID of Storage Devices in Linux?
A UUID (Universally Unique Identifier) is a string of characters that uniquely identifies a specific system or partition in a computer. It identifies storage devices, such as hard drives, USB drives, and network interfaces. The UUID is a randomly generated number that includes hardware information about the system and is unique to each partition.
Let’s discuss the ways to find the UUID in Linux.
How to Find UUID of Storage Devices in Linux?
Several methods are utilized to find the UUID of the storage devices in Linux. This section will discuss the common methods which will get us the UUID of the partitions of the hard disk.
Method 1: Using blkid Command
The widely used method to find the UUID of a device in Linux is by using the “blkid” command, which is available by default in the system as shown below:
$ sudo blkid
The output shows the UUID for the partitions “/dev/sd3” and “/dev/sd2”. The partition “/dev/sd3” is of file system ext4, which is 32 digit Hexa decimal number, while the partition “/dev/sda1” has a vfat file system whose UUID is 8 Hexa decimal.
To get the UUID for the specific storage device (partition), we can use the blkid command with the “o” option that shows the output “value”. For example, to find the UUID of the “/dev/sd3” partition only, run the below command in the terminal:
$ blkid /dev/sda3 -s UUID -o value
The partition “/dev/sda3” UUID is displayed in the output.
Method 2: Using lsblk Command
The “lsblk” command is used to show the details of the system block devices, including the UUID of the system storage devices. For instance, to find the UUID of a device, the below command displays the Name, Size, and UUID of the system devices:
$ sudo lsblk -o NAME,SIZE,UUID
The above shows all the system devices details along with UUID.
The “f” option is sued to find the file system with the UUID of the storage devices in the system as shown below:
$ sudo lsblk -f
The output shows the file system for “/dev/sda2” and “/dev/sda3”.
Similarly, the “lsblk” command is used with “grep” to find the file system and UUID by running the below-written command:
$ sudo lsblk -f | grep -v loop
Method 3: Using “/dev/disk/by-uuid” Directory
The “/dev/disk/by-uuid” directory has the symlinks of each drive’s UUID to the “/dev” (e.g.,/dev.sda1). To get the disk UUID for the device, we can list the directory “/dev/disk/by-uuid” directory:
$ ls /dev/disk/by-uuid
Similarly, we can list the system devices with the UUID with the below command:
$ ls -lha /dev/disk/by-uuid
The output shows the storage devices along with the UUID.
Method 4: Using /etc/fstab File
Another way to find the UUID of the partitions, we can use the grep command with the “/etc/fstab” file:
$ grep UUID /etc/fstab
It shows the UUID for partitions “/dev/sd3” and “/dev/sda2”.
Note: If you have a partition formatted in ext2, ext3, or ext4, you can use the below methods:
Method 5: Using dumpe2fs Command (For ext2, ext3, and ext4 File Systems)
The dumpe2fs command can be used to get the UUID for any specific partition having the file system of ext2, ext3, and ext4. For instance, to get the UUID of the partition “/dev/sda3”, execute this command in the terminal:
Note: You can find the file system using the “lsblk -f” command.
$ sudo dumpe2fs /dev/sda3 | grep UUID
The output displays the UUID for the partition “/dev/sda3”.
Method 6: Using tune2fs (For ext2, ext3, and ext4 File Systems)
Similarly, the “tune2fs” command can be used to get the UUID for a specific storage device. For instance, the below command finds the UUID for the “/dev/sda3” partition:
$ sudo tune2fs -l /dev/sda3 | grep UUID
The UUID of the storage device “/dev/sda3” is displayed on the output.
That’s how you can find the UUID of storage devices in Linux.
The UUID of any hard disk in Linux is the unique identification number that is used to identify a specific storage device by the system. We can find the UUID of the storage device using the “blkid”, “lsblk”, “/dev/disk/by-uuid” and “/etc/fstab” methods. Moreover, we can get the UUID of the ext2, ext3, and ext4 file systems by using the “dumpe2fs” and “tune2fs” commands.