How to find UUID of Disk Storage with the simple command

Most likely, you are looking for a solution to auto-mount disk storage whenever the system gets power on instead of doing it manually. Of course, it is not feasible to mount a location every time, and what if your application or program crashes because of a missing location?

So, to avoid this type of conflict, we can leverage /etc/fstab file to automount the disk, but the question is, it asks for a UUID. From where to find the UUID of a disk, and what is a UUID? Let’s find out with a simple command.

What is UUID?

The UUID acronym stands for a universally unique identifier, and from the name, you can guess it is something related to the identification

As you know, you can mount multiple disks on your system, but how does the system identify its uniqueness?

It is a 36-character alphanumeric string that is chosen in such a way that it cannot be duplicated, and it is separated into five groups by hyphens in a format of 8-4-4-4-12.

A sample example of UUID to explain you structure 1d8c88c3-aa08-418d-b302-3f16d9933fd0.

Find UUIDs of Disks

You can use several commands to find UUID or universally unique identifier of a particular disk or complete partition.

Find UUID using blkid

The most common command to find a UUID is blkid, which is widely used, and the output is very simple. It prints details like UUID, DEVICE NAME, LABEL, BLOCKSIZE, TYPE, PARTLABLE, PARTUUID.

If you want to find the UUID of all attached disks, then pass the below command that can be run without sudo privileges, but some of the options require sudo privileges:

$ sudo blkid

The output can be cluttered if you use Snap package manager because Snap creates multiple virtual disks that don’t have UUID. To suppress that, you can run:

$ sudo blkid | grep -v "loop"

What command should I run if I want to find UUID of specific partitions?

$ sudo blkid /dev/sda9

You can use blkid command to convert UUID to find the actual device name. Before that, you should have a UUID.

$ sudo blkid -U 1d8c88c3-aa08-418d-b302-3f16d9933fd0.

A blkid command can do much. If you want to know more, use man blkid.

Find UUID using lsblk

Another command is lsblk which is mainly used to list out block devices, and you can manipulate the default command to print UUID along with the name of disks.

$ lsblk -o name,uuid

For more details, you can run the below command.

$ lsblk -f

Find UUID using ls

Although you know everything is a file in Linux, similarly, UUID is a soft link file of respective disk name, and as usual, we can use ls command to list out the UUID.

You should read: What is Hardlink and Softlink

Pass the following command to view UUID.

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

The output in cyan color is your UUID.

Find partition UUID using tune2fs

tune2fs command utility manages various filesystem parameters on Linux ext2,ext3, and ext4 filesystem, which even shows the current status of the disk.

You can run tune2fs with grep command to filter out the UUID information to get the UUID. And please change the device name as per your system to get the correct output.

$ sudo tune2fs -l /dev/sda1 | grep UUID

This command will work only if the partition is formatted in ext2, ext3, or ext4 and no other partitions are supported.

You should read: How to Determine the File System Type in Linux (Ext2, Ext3, or Ext4)?

You can also use tune2fs to generate a UUID, which we will publish soon, so please make sure to subscribe our newsletter.

Wrap up

That’s all you need to know to find or retrieve UUIDs of disk storage with a simple command. You can use more commands, but unnecessarily, why make it complicated?

Now you can paste the UUID of a specific disk to /etc/fstab to automount disk.

An NTFS partition has 16 bits of UUID compared to Linux partitions. I’m not sure what the reason is. If you are aware, then please let us know in the comment section.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments