Linux 101 : Why we label a disk or a partition? - e2label, mkfs.ext4, labels, UUIDs -

We add a partition "/dev/sdb1" for example to our system, and we set an "ext4" filesystem on it using the mkfs.ext4 command:

We also add the partition to our "/etc/fstab" file, so it would be mounted automatically on reboot:

If we add a new drive to our system, or if we remove a drive from our system, the name of the devices and partitions might change. 
It might go from "/dev/sdb" to "/dev/sdc", or from "/dev/sdb1" to "/dev/sdb2" for example.

To avoid that issue we use disk labels to name our partitions - disk labels don't change -.
We can create a label for our "/dev/sdb1" partition using the below command:

We update our "/etc/fstab" file as below:

We can display the label of our partition using the below command:

We could also use the UUID, which is a - universally unique identifier - for the hard drives.

We can display the UUIDs of our hard drives using the below command:

We can use the UUID in the "/etc/fstab" file instead of the labels, as below:


Leave as a comment: