Linux 101 : Avoid disk naming issues - the UUID "Universally Unique Identifier" -



When we usually mount a device, we use its name, for example:


The device name might change and lead to problems because of the change of the locations of files in that device.

For example if we add another disk, our device "/dev/sda2" might change to "/dev/sda3", while our newly installed device might get the name "/dev/sda2".

To solve this problem, we can identify our mounted filesystems by their UUIDUniversally Unique Identifier -, which doesn't change. 

When we create a filesystem using the "mke2fs" tool, it generates a UUID identifier for that filesystem.

To display our devices, their filesystems and UUID, we use the below command:


To mount a filesystem using its UUID instead of its name, we use the following:


Remark:

We usually use the name of the device when using the ""mount" command on the command line, and we usually use the UUID in the "/etc/fstab" file:


The "/etc/fstab" is the file the system reads to know which devices to mount. The above line mounts the device using its UUID on the "/" directory.

The udevd daemon detects and manages the device when it is added to a system.

We could also change the UUID of a filesystem if for example, we made a copy of that filesystem in the "/dev/sda6" partition and we wanted to give it a different identifier from the original one.

For that purpose, we could use the "tune2fs" tool as follows:


The above command generates a random UUID for the "/dev/sdc6" partition.
After changing the UUID, we could mount our device again.

Comments

Leave as a comment:

Archive