Wednesday, April 29, 2009

Automatically mounting drives in Ubuntu

I know there's a number of guides out there that show you how to do this, but I always seem to end up combining a number of them to actually get what I want. What I want is the drive to be mounted once I'm logged in (I don't really care when, so long as it's instantly usable).

Here's how I do it

  1. Use sudo blkid to get info about the drive you want to be mounted.

  2. Make the folder that it's going to be mounted in. I normally put a folder in /media/ which has the same name as the drive. This keeps things simple and won't break any symlinks already in place. You do, however, need to unmount the drive first, and of course to make a new folder in /media you'll need to either be root or use sudo.

    I usually do this with:

    sudo mkdir /media/Data

  3. Edit /etc/fstab (you'll need to be sudo) to add the following lines:

    UUID=$DRIVE-ID $FOLDER $TYPE defaults,umask=000 0 0

    This line specifies where to find the drive where to mount it and how. You need to replace $DRIVE-ID with the UUID number for the drive you got from blkid, replace $FOLDER with the full path to the folder you want the drive to be mounted in and $TYPE with the type of filesystem used on the drive, which you can also get from blkid.

    I usually add a comment line, so I know what's happening, then this becomes:

    # /dev/sda5 - Data
    UUID=4820-8D15 /media/Data vfat defaults,umask=000 0 0

That's it. Now whenever you start Ubuntu your drive will already be mounted. If you want to mount it now without rebooting then you can tell Ubuntu to mount everything in the fstab now by using:

mount -a