Distroname and release: Debian Squeeze

Using UUID to mount devices


Due the fact that devices dev names can change, in example a external harddisk it is very nice to use UUID to mount devices, instead of the device name, so you do not get "broken" defined mount points.
You put in an external harddisk or usb-pen and it is regonized as /dev/sda. The next time you put it in, it is regonized as /dev/sdb, because we have another device using /dev/sda, and therefor the fstab is "broken".

This can be avoided by using UUID istead of "dev names" in the fstab file.

Finding the UUID

There are several ways of finding the UUID: ls -l /dev/disk/by-uuid
blkid < device >

I will be using the blkid here, because this is working everytime. For some reason /dev/disk is not on some systems and installations.

Simply use the command, with or without parameters.

Here is an output with the command without parameters
/dev/sda1: UUID="8af29dc8-9431-4f01-acce-518529976f09" TYPE="ext3"
/dev/sda5: TYPE="swap"
And a command with parameters which will only show the specific partition.
#blkid /dev/sda1
/dev/sda1: UUID="8af29dc8-9431-4f01-acce-518529976f09" TYPE="ext3"
Now then you have the UUID, we can continue with configuring the fstab file.

Configuring fstab

This is very easy, just add the device, or edit an existing line with UUID from blkid. In the example below, the original line is commented out.
# /etc/fstab: static file system informations.
# <file system> <mount point>  <type>   <options>     <dump>     <pass>
proc            /proc          proc     defaults      0          0
#/dev/sda1      /              ext3     errors=remount-ro 0      1
UUID=8af29dc8-9431-4f01-acce-518529976f09      /              ext3     errors=remount-ro 0      1
That should be it. Now save the file, and you should be up and running. Here it is the root filesystem that we have changed, so a reboot is required, so we can check if it is working.
If you have done it with an USB disk, then you just can test by trying to mount it.
Copyright LinuxLasse.net 2009 - 2017 All Rights Reserved.

Valid HTML 4.01 Strict Valid CSS!