Share this post with your friends
You can mount a partition by it's partition identifier such as
/dev/sda1 etc. But that's not flexible.
Imagine a situation where you plugged out your first hard drive and turn on your computer. Now your second hard drive will act as the first hard drive. The operating system will try to mount the second hard drive in a directory but sadly there's no second hard drive.
Imagine another situation where you have three hard drives in your system, and you switched the second hard drive with the third one. If you specify mount points on
/etc/fstab file as
/dev/sdc1 and so on. That will also mount wrong partitions in the wrong directory.
To avoid this type of situation, we can mount a partition by it's UUID(Universally Unique Identifier). It's an unique identifier that is assigned to every partition of your hard drive when you format it.
How to find the UUID of the partitions available on your system?
The answer is simple. We use the command
blkid to find the UUID of the available partitions of our system.
/dev/sda1: UUID="845b9fe2-63b2-49cf-bc05-5fd5db4c25a7" TYPE="ext2" PARTUUID="c3fd0be8-01"
/dev/sda5: UUID="avjGaH-RAOc-nq0e-mxXJ-qpeD-4mfw-3qufR1" TYPE="LVM2_member" PARTUUID="c3fd0be8-05"
/dev/sr0: UUID="2016-04-20-22-45-29-00" LABEL="Ubuntu-Server 16.04 LTS amd64" TYPE="iso9660" PTUUID="4cbe268b" PTTYPE="dos"
/dev/mapper/ubuntu--vg-root: UUID="35a51703-9aa3-471d-a199-5e8d45082ec4" TYPE="ext4"
/dev/mapper/ubuntu--vg-swap_1: UUID="8396b26a-6031-4d80-b5e1-3daad2338ac7" TYPE="swap"
/dev/sdb1: LABEL="test" UUID="cabe72aa-d932-49d7-9299-f2e01ba91cce" TYPE="xfs" PARTUUID="d3ae0bfa-01"
From the output of this command, you can find the UUIDs. I want to mount the
/dev/sdb1 has UUID
Mounting a partition on boot using UUID and /etc/fstab file:
To mount the partition
/etc/fstab file, open the file
/etc/fstab with your favorite text editor and add the following line to the end of it. Note that, I formatted the partition as XFS.
UUID=cabe72aa-d932-49d7-9299-f2e01ba91cce /testmount xfs defaults 0 0
Tested on: Ubuntu 16.04.1 LTS