Linux 101 : Disk labels and UUIDs



When we attach a disk to a system, it gets assigned a device name "/dev/sdb" for example
If we add a disk drive, or we switch the connectors, the naming of the drives changes and could cause disks not to mounted,...
To avoid this we use UUIDs or labels with the disks. 

Displaying the UUID of disks:

We can display the UUID of different disks using the below command:


We could use the UUID in the "/etc/fstab" as below:


Using labels in the "/etc/fstab" file:

We start by creating a ext4 partition of 100MB as below:



We can check the creation of the new partition using the below command:



Then we create a ext4 filesystem on the new partition "/dev/sdb1":


Attaching a label to our partition:

We attach a label to our partition using the below command:


We could also use the "e2label" command.

We can then check it using:


Then we can add a line in the "/etc/fstab" file, to enable our partition to be mounted at boot time


We can use the "mount -a" command to check if our fstab file is free of mistakes.
The "mount -a" command tries to mount all the devices listed in the "/etc/fstab" file.

Comments

Leave as a comment:

Archive