UUID on Linux fstab file

Written by
Date: 2010-09-02 10:36:30 00:00

UUID stands for Universally Unique IDentifier and it is used in Linux to identify disk in the /etc/fstab file.

This way, the order of the disk in the motherboard can be changed, not affecting the mount point they will have.

As can be seen, it is a good idea to have fstab using UUID instead of the /dev/xdx way to identify the disks.

Let’s learn how to add disks, to your fstab file using UUID.

List the UUIDs

There are two ways of doing this:

ls -l /dev/disk/by-uuid/

Being the output

lrwxrwxrwx 1 root root 10 Sep  2 10:54 11b7eb1f-79d5-4bfe-8aa5-9235e6cccbfe -> ../../sda1
lrwxrwxrwx 1 root root 10 Sep  2 10:54 340cf4e2-4ee7-490c-a169-5045ebff4fac -> ../../sdb4
lrwxrwxrwx 1 root root 10 Sep  2 10:54 37ea6741-c1b0-4297-9f23-b36417b3c109 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Sep  2 10:54 5b0a6c7b-d936-4470-a645-2b68db32d2c1 -> ../../sdb3
lrwxrwxrwx 1 root root 10 Sep  2 10:54 6db36bd8-0778-4b35-a0bd-66487002cbe0 -> ../../sdb2
lrwxrwxrwx 1 root root 10 Sep  2 10:54 afdc3ca9-c06e-452a-8e42-2b35ad9dac65 -> ../../sda2



Being the output

/dev/sda1: UUID="11b7eb1f-79d5-4bfe-8aa5-9235e6cccbfe" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sda2: LABEL="/home" UUID="afdc3ca9-c06e-452a-8e42-2b35ad9dac65" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb1: UUID="37ea6741-c1b0-4297-9f23-b36417b3c109" TYPE="swap" 
/dev/sdb2: UUID="393ac665-f5c2-488d-b601-b59ba1d5675b" SEC_TYPE="ext2" TYPE="ext3" 
/dev/sdb3: UUID="5b0a6c7b-d936-4470-a645-2b68db32d2c1" TYPE="ext2" 
/dev/sdb4: UUID="340cf4e2-4ee7-490c-a169-5045ebff4fac" SEC_TYPE="ext2" TYPE="ext3" 

Now that you have the UUID edit the /etc/fstab file and make it look like this:

UUID=340cf4e2-4ee7-490c-a169-5045ebff4fac / ext3 defaults 0 1
UUID=37ea6741-c1b0-4297-9f23-b36417b3c109 swap swap defaults 0 0
UUID=5b0a6c7b-d936-4470-a645-2b68db32d2c1 /boot ext2 defaults 0 1
UUID=6db36bd8-0778-4b35-a0bd-66487002cbe0 /home ext3 defaults 0 1

Instead of:

/dev/sdb4 / ext3 defaults 0 1
/dev/sdb1 swap swap defaults 0 0
/dev/sdb3 /boot ext2 defaults 0 1
/dev/sdb2 /home ext3 defaults 0 1