If you use lots of disks that regularly changed or moved, it’s preferred to mount the partition using UUID. This is because OS may change device names in some situations like adding another disk. This may end with issues with booting. UUID is unique and independent from the actual device names.
In this tutorial, we are going to learn how to mount partitions using UUID in a Linux system.
Firstly, find the UUID of the device partition that is going to be mounted. You can use the following command to find the UUID of the partitions.
$ sudo blkid
Or to print UUID for a specific partition, use:
blkid /dev/sdb -sUUID -ovalue
Once the UUID is found, mount the partition permanently in fstab file.
In this example, I have used the partition /dev/sdb with its UUID af406bcd-cddb-4095-8456-fdf8dfe37665 to mount at /var/www.
If the mounting directory already exits then use that. If doesn’t, create a new directory(/var/www in this example) to mount the partition.
$ sudo mkdir /var/www
Open the /etc/fstab file using your favorite text editor.
$ sudo vi /etc/fstab
Then, append the following line at the end of the file.
UUID=af406bcd-cddb-4095-8456-fdf8dfe37665 /var/www ext4 defaults 0 0
Run mount -a to mount all filesystem or perform a reboot command to reflect the changes.
Once mounted, run the following command to check whether the partition is mounted correctly.
$ df -h
The output indicates that the partition /dev/sdb has been mounted at /var/www.
In this tutorial, we have learned how to mount a partition in Linux using UUID. Also, learned about why we use UUID and how to find the UUID of partitions. Any feedback and response will be highly appreciated.