Mount partitions in Linux using GUID

If you’ve ever managed a linux machine, you’ve likely manually editied the /etc/fstab file to automatically mount filesystems.  If you manually specify it’s location (/dev/sdb1) you may know that adding other devices can change location, meaning you will need to change your fstab.

If you’ve looked at modern Linux distributions, you may notice that the fstab file does not contain any /dev devices, but instead uses the partition’s GUID.  From what little reading I’ve done, I’ve found this is a feature of ext2 and up filesystems.  A /etc/fstab in a recent version of Ubuntu will show you that you need to run blkid to print the UUID for a device, and then use GUI= as a prefix in place of the device location.  Run blkid as SU (sudo blkid) and you will see something like this: 

[email protected]:~$ sudo blkid
/dev/sda1: UUID=”818bded8-51fc-4c02-be9e-abb99517c905″ TYPE=”ext4″
/dev/sda5: UUID=”283cf494-e3be-441d-b098-034869407e6e” TYPE=”swap”
/dev/sdb1: LABEL=”cr48_home” UUID=”cab2cac5-fb0d-4afb-9561-66f97c939412″ TYPE=”ext4″
In this case, I want to use the /dev/sdb1 device as my home directory, so in my /etc/fstab file I’ve added the following.
UUID=cab2cac5-fb0d-4afb-9561-66f97c939412 /home         ext4          0 errors=remount-ro      1
Now the partition will automatically be mounted to /home reguardless to it’s device location.  
If you’re using an old Linux install that’s been updated many times, your fstab file may still be using the device instead of it’s UUID.  It’s a good idea to fix this while you can.  It’s not uncommon to reboot with a new disk installed and it changing the address of all of your exising devices.

Leave a Reply