Home > Operating Systems > Automount drives based on UUID

Automount drives based on UUID

I wanted to be able to automatically mount my drives by adding them to fstab. I have done it before, but I have used the /dev/sdb1 syntax. I have noticed a problem when I unplug the drives, and plug them back into a different SATA controller. When I do that it changes the /dev/sd## to something else. I have learned that if you use the UUID in the fstab, then this issue doesn’t really arise.

First off is to determine the UUID of the drives that you have mounted. Enter the following in the command line.

sudo blkid

It will return something like

/dev/sda1: UUID="6413b21e-ec40-4d80-8103-da8ea5fbbd30" TYPE="ext4" 
/dev/sdd1: UUID="08ae0157-7718-4e3d-be15-11a3b2802148" TYPE="ext3" 
/dev/sdd5: UUID="e580e4fe-4aed-4ea9-bcac-8ab9220414db" TYPE="swap" 
/dev/sdb1: LABEL="Seagate320" UUID="ce09b320-c7b3-4d7c-a192-a2d55208473c" TYPE="ext3"

You can also run “sudo fdisk -l” if you want more information about the different /dev/sd## drives. Otherwise if you can tell from the results which UUID you want then theres no need for “sudo fdisk -l”. The drive I am going to add to fstab is the “Seagate320” drive.

sudo gedit /etc/fstab

Add the following to the fstab file

# My Local Drives
UUID=ce09b320-c7b3-4d7c-a192-a2d55208473c /media/Seagate320/ ext3    defaults,errors=remount-ro 0       1

Next time you reboot the drive will automatically be mounted.

Categories: Operating Systems Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.