Thursday, October 30, 2008

UUID Mounting

If you've ever dealt with a significant number of hard drives in a Linux environment inevitably you reach the point where you need to move to a new motherboard or disk controller which will most likely result in something like this:

/dev/sdb becomes /dev/sde
/dev/sdc becomes /dev/sdf

If you use static device IDs in fstab this is going to reverse your drive mounts. In a server environment it could be more than an inconvenience if say your /private share is suddenly mounted on /public

There's pretty much no good reason to mount by a static device ID anymore. The best solution is UUID. Disk labels (e2label for example) would also be a possible solution however I've had mixed results with them personally so I stick with UUID now.

First, get the UUID of the volume: (for example) (also try blkid to get them all at once)
# vol_id --uuid /dev/sda

You'll get something like this: 5a4dea83-53a6-4189-8c6d-240ee7402d2d

In /etc/fstab mount it by UUID:
UUID=5a4dea83-53a6-4189-8c6d-240ee7402d2d /mnt/mountpoint ext3 defaults 0 0

# mount -a

That's about it. Not much to it. The hardest part is just breaking the habit of doing it the wrong way. It's easier up front but harder later on.


No comments: