Auto mount USB Hard Drive at Boot

To make my external USB Hard Drive auto mount at the same mount point on every boot [especially important if you use scripts to copy backups to it] then follow these instructions..

First create a mount point in the directory /mnt , open a terminal and type;

~$ sudo mkdir /mnt/USB-HD

replace USB-HD with whatever you want to see in the Places list as the name of your Hard Drive.

Now check where the HD is currently mounted, if you navigate to /media you should find that your USB HD is mounted as something like /media/disk, now open a Terminal and type;

~$ mount

You should see something like this, and need to search for the line which includes your disks mount point in my case /media/disk;

/dev/sda1 on / type ext3 (rw,relatime,errors=remount-ro)

tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)

proc on /proc type proc (rw,noexec,nosuid,nodev)

sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)

varrun on /var/run type tmpfs (rw,nosuid,mode=0755)

varlock on /var/lock type tmpfs (rw,noexec,nosuid,nodev,mode=1777)

udev on /dev type tmpfs (rw,mode=0755)

tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)

devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)

fusectl on /sys/fs/fuse/connections type fusectl (rw)

lrm on /lib/modules/2.6.28-11-generic/volatile type tmpfs (rw,mode=755)

/dev/sdb1 on /home type ext3 (rw,relatime)

securityfs on /sys/kernel/security type securityfs (rw)

binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)

gvfs-fuse-daemon on /home/martin/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=martin)

/dev/sdg1 on /media/disk type ext3 (rw,nosuid,nodev,uhelper=hal)

As you can see my USB Drive is mounted on the last line at /dev/sdg1

Now make a backup of the fstab file which controls the mount points of your file system by adding a .bak to the end of the copied file with;

~$ sudo cp /etc/fstab /etc/fstab.bak

then open the fstab file with;

~$ sudo gedit /etc/fstab

and adding the new line at the bottom of the list as follows, changing the /dev & /mnt options to match your own above;

/dev/sdg1 /mnt/USB-HD auto auto,user,rw,exec 0 0

then re saving the file.

My HD is formatted as an ext3 but the 1st auto in this line checks to see what the disk is formatted as, but you can change it to the actual format if you wish. Now reboot your PC and [fingers crossed] your External HD will mount as USB-HD.

Advertisements

Tags: , , , , ,

16 Responses to “Auto mount USB Hard Drive at Boot”

  1. Stephen Says:

    Worked Great! Thanks for the great post!
    Using Ubuntu Server 9.04 w/ a fat32 USB drive

  2. Sheevaplug – automount USB drive at boot « Martin’s Ubuntu Blog Says:

    […] solution, see here for my post on setting up the fstab file to mount your USB drive. When you edit the fstab on the […]

  3. Alan Says:

    Worked for me on Ubuntu 10.04, thanks!

  4. apostolis Says:

    not working for me :/ it mounts as /mnt/usb-hd but it doesn’t mount automatically….

    • wobblybob9 Says:

      Hi apostolis, which version of ubuntu are you using and can you post the results of the command $ mount from a terminal and your fstab

  5. Flipper Says:

    Thanks for the article wobblybob9. I’ve now got my external drive auto-mounting properly, and my Oracle database sitting on it starting cleanly on boot as well. I’m a happy camper.

  6. pcurtis Says:

    Works very well for me on Ubuntu 10.04 and I will be using on 11.04 and Kubuntu 11.04 so I can get an early mount with the correct permissions for MediaTomb to run at startup in daemon mode.

    I would however note that one Must have the USB drive plugged in or the boot-up needs intervention to continue when the drive is not found and even if you then plug it in it will not mount through nautilus (only checked in U10.04).

    I also discovered to my surprise that fstab does not like mount point folder names which have spaces even if you quote them in fstab (again only checked in U10.04).

    Overall a very useful, clear and well presented set of information in your blog – I had a sense of Déjà Vu reading it as I am currently working on MediaTomb and in the last couple of days have been ‘rescuing’ a 12 year old Toshiba Portege with Kubuntu as well as your coverage of many other learning curves I have also had to climb over the last 5 years – see http://www.pcurtis.com/ubuntu.htm .

  7. Frans Says:

    Instead of a space, use 40 (the octal representation of the ASCII-code for the space character). For example, //lnas1/disk401 is equivalent to “//lnas1/disk 1”.

  8. format disk drive Says:

    Great post. I was checking continuously this blog and I’m inspired! Extremely useful information specially the ultimate phase 🙂 I handle such information much. I was looking for this particular info for a very long time. Thanks and best of luck.

  9. Ashish Says:

    What if the USB HDD is formatted in ntfs ? Will the tutorial still help? Mine is NOT mounting inspite of changes in fstab…kindly help !!

  10. yarrah Says:

    Hi thanks for the help

    However this solution gives me permission error after the mounting. The mounting works, but no write permission

    thanks

  11. Raj Says:

    Thanks mate – much appreciated – my backups are now guaranteed to work properly.

  12. Professor Satchafunkilis Says:

    Wouldn’t one want to use the drive’s uuid instead of its /dev path, since its /dev path can change, e.g. should the drive ever become unplugged? Even across reboots w/o the drive becoming unplugged, I don’t think there is a guarantee that the system wouldn’t assign a different device file. Now my question is, is my reasoning correct and can uuid’s be used in fstab in place of the device file for usb drives?

  13. XBMC Auto Start on Ubuntu | Greg Stephens Blog Says:

    […] that store media for XBMC, you may need to insure that these drives are mounted before XBMC starts. Martin’s Ubuntu Blog post on this subject describes in more detail the following steps to do […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: