How to Mount Partitions using UUID in Linux

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


List partition's UUID

Or to print UUID for a specific disk or partition, use:

$ sudo 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
fstab configuration file

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.

List Mounted Partitions


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.

1 thought on “How to Mount Partitions using UUID in Linux”... add one

  1. UUID's are not the only option - for example:-
    ls -l /dev/disk/by-uuid/
    11169433-051f-4b3b-bd05-7c31c85f0d47 -> ../../sda2
    ls -l /dev/disk/by-id/
    ata-Samsung_SSD_870_QVO_1TB_S5SVNG0N955653H-part2 -> ../../sda2
    ls -l /dev/disk/by-path/
    pci-0000:02:00.1-ata-1-part2 -> ../../sda2

    Provided you prefix by the appropriate path, not just /dev/, anywhere /dev/sda2 is valid, so is /dev/disk/by-id/ata-Samsung_SSD_870_QVO_1TB_S5SVNG0N955653H-part2
    and this has the advantage of identifying the manufacturer, model, serial, and partition.


Leave a Comment