Social Icons

How to setup mount / auto-mount USB Hard Drive on Raspberry Pi

Follow the simple steps in the order mentioned below to have your USB drive mounted on your Raspberry Pi every time you boot it.

*These steps works both on Raspbian Wheezy & Jessie*

These steps are required especially if your are setting up a Samba share, or a 24x7 torrent downloader, or alike where your Raspberry Pi must have your external storage already mounted and ready for access by the services / daemons.

Step 0.
Plug in your USB HDD / Drive to Raspberry Pi
If you are using a NTFS formatted drive, install the following
sudo apt-get install ntfs-3g

Step 1.
Log on pi using ssh terminal and execute:
ls -l /dev/disk/by-uuid/

You will see something like the following:

lrwxrwxrwx 1 root root 10 Jan  1  1970 0AC4D607C4D5F543 -> ../../sda1
Note down the value of the UUID --> 0AC4D607C4D5F543

Step 2.
Create a location for mount point:
sudo mkdir /media/NASDRIVE

Give proper permission:
sudo chmod 770 /media/NASDRIVE

Step 3.
Get the uid, gid for pi user and group with id command (usually 1000)

Step 4.
Mount the USB Drive and then check if it is accessible at /media/NASDRIVE
sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda1 /media/NASDRIVE

Note:
ntfs-3g for NTFS Drives
vfat for FAT32 Drives
ext4 for ext4 Drives

Step 5.
Now, we will configure RasPi to do this after every reboot:
Take a backup of current fstab and then edit
sudo cp /etc/fstab /etc/fstab.backup
sudo nano /etc/fstab

Add the mount information in the fstab file (replace UUID with your own):
UUID=0AC4D607C4D5F543 /media/NASDRIVE ntfs-3g uid=1000,gid=1000,umask=007 0 0

Step 6.
Reboot
sudo reboot

Step 8. (Optional, required if using as data storage for owncloud)
If you are configuring ownCloud's data directory on your NAS drive, it should be having a 770 permission for www-data user. You can simply add user www-data to pi group, since its already having 770 as permission as set above in fstab.

sudo usermod -a -G pi www-data


36 comments:

  1. at stage 3 it says... 'Mount is denied because the NTFS volume is already exclusively opened.
    The volume may be already mounted, or another software may use it which
    could be identified for example by the help of the 'fuser' command.' what does thsi mean and what do i do

    ReplyDelete
  2. ,it says this at stage 3'Mount is denied because the NTFS volume is already exclusively opened.
    The volume may be already mounted, or another software may use it which
    could be identified for example by the help of the 'fuser' command.' what do i do

    ReplyDelete
    Replies
    1. Sorry for late reply, but I guess your drive is getting auto mounted before you are trying to mount it. Disable x-mode (GUI) before you start working.

      Delete
    2. can you elaborate on how to disable the x-mode (newbie here). I am having this same issue...

      Delete
    3. I disabled the GUI and still received this same message, any solutions?

      Delete
  3. Thank you very much for your tutorial.
    I have three usb disks connected to Raspberry. I followed your instructions, but
    1) at raspberry power on, sdb1 is connected to disk 2 not disk 1 and viceversa
    2) if I make a reboot, all work fine

    Any idea?

    thanks

    ReplyDelete
    Replies
    1. Are you using UUID to mount the USB drive as shown above? UUID is unique and it should not mount any other device in that case.

      Delete
  4. Hi !

    Thanks for share this info.

    I have one problem, I can mount my ntfs usb without problem and I added the standard usual line in the fstab (without using the UUID) and everything works fine, if I use mount -a the system mounts the nfts drive but retarting the drive disappears I tried your procedure but when I use this command :

    ls -l /dev/disk/by-uuid/

    I only receive information from the SD card not from the nfts drive I tried mounted and unmounted with same result.

    Any idea?

    Thanks !

    ReplyDelete
  5. That was the only "how to" that actually worked for the arch on raspberry pi.
    The only thing I did was to discard "-o uid=pi,gid=pi".

    Thanks!

    ReplyDelete
  6. Hi Abhishek Mitra,

    I am trying to use the Owncloud 7 with and external HDD, and I followed your tutorial "How to setup ownCloud 7 on Raspberry Pi" and after that I followed this tutorial to be able to use my external ntfs HDD, but when I try to specify the "Data Folder" on the admin settings fist page of Owncloud, appears an error saying: "Error while trying to create admin user: SQLSTATE[HY000] [14] unable to open database file" ...what could I am doing wrong?

    In Data Folder options I put /media/NASDRIVE is it correct?

    Thank you!

    ReplyDelete
    Replies
    1. This is definitely due to a permission issue. Owncloud is not having proper permission to write to your storage / data folder you have configured.

      Whatever path you put in Data Folder of owncloud it must be existing and writable by owncloud. If you have followed the permission steps mentioned in both the guide, I guess the issue should not have occurred. Try cross-checking the permissions set.

      Delete
    2. Hi Abhishek,
      After I apply the "sudo chmod 770 /media/NASDRIVE" again, it worked!
      Thank you

      Delete
    3. Hi guys,

      I just had the same problem as Anonymous, I re-applied the sudo chmod 770 /media/NASDRIVE command again and got the same message as previously mentioned by Anonymous but this time I ALSO got another relating to the .htaccess file, see below:

      Error

      Error while trying to create admin user: SQLSTATE[HY000] [14] unable to open database file
      Security Warning

      Your data directory and files are probably accessible from the internet because the .htaccess file does not work.
      For information how to properly configure your server, please see the documentation.

      Delete
    4. Hi Abishek,

      I realised what the problem was: I had the incorrect UUID, I re-did the steps in this tutorial and I can now enter my Owncloud instance.

      The problem I see now is that in the ADMIN section of owncloud it says this:

      "This server has no working internet connection. This means that some of the features like mounting of external storage, notifications about updates or installation of 3rd party apps don´t work. Accessing files from remote and sending of notification emails might also not work. We suggest to enable internet connection for this server if you want to have all features."

      Do you happen to know how to get around this? I am using my RasPi connected to my laptop via an ethernet cable, but internet sharing via ethernet is switched on...

      any help greatly appreciated, as always - THANKS!

      p

      Delete
  7. This has been the most helpful page I've seen for getting my USB drive mounted on my Pi. Thank you for the very specific steps. Cheers!

    ReplyDelete
  8. Hi Abhishek,

    Thanks for the marvelous tutorial! Do you think it's wise to disable "write caching" on the external drive (so there's less risk of data corruption in case of power failure), or just mount it with the default options?

    Cheers!

    ReplyDelete
    Replies
    1. Though I somewhat agree with you, but not very sure of the actual implications. You can try reading more on this here http://www.raspberrypi.org/forums/viewtopic.php?f=66&t=89360

      Delete
  9. Do you have to use SSH to log in or can you do this from the terminal?

    ReplyDelete
  10. Can you please explain step 5 a bit more.
    Where do you get the UUID?
    Add the mount information in the fstab file (replace UUID with your own):
    UUID=0AC4D607C4D5F543 /media/NASDRIVE ntfs-3g uid=1000,gid=1000,umask=007 0 0

    ReplyDelete
    Replies
    1. You probably missed on the Step.1 itself...

      Delete
  11. ls -l /dev/disk/by-uuid/

    I only receive information from the SD card not from the nfts drive I tried mounted and unmounted with same result.

    My drive is USB 3.0 1tb ext4

    ReplyDelete
  12. sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda1 /media/NASDRIVE fails because as the drive always automounts as soon as you plug the drive in.

    ReplyDelete
  13. Very useful guide!

    However, I run into a problem after reformatting my drive to ext4 (for performance).

    It seems that fstab refuse to use uid=1000,gid=1000 for ext4 partitions!

    How do I make permissions to work with samba now?

    ReplyDelete
    Replies
    1. I ran into the same problem. On "ls -al" in /media I noticed that the owner and group for the directory the USB drive is mounted (for me it's "owncloudhdd") was still shown as "root root". So I did a "sudo chown pi:pi /media/owncloudhdd", and it seems to work.

      Delete
  14. I am trying to do this to mount NAS drive attached to my router. The mount works fine but doesn't auto mount on reboot. How do I get UUID for this?

    ReplyDelete
  15. good tutorial.
    Succinct and yet thorough.
    Thank you :-)

    ReplyDelete
  16. hello, I am having a little bit of an issue. i followed all of this and continued on to set up with samba. all works great but i am having a permissions issue when trying to access on my web server from the browser. i can access all other samba shares but when i try this one, i get a forbidden message. could someone please help? thanks.

    ReplyDelete
  17. I have done all this but was this suposed to add my hard dist to my owncloud server ?? because I added a 500gb hard disk but the own cloud is still telling me that i only have 3 gb of space.

    ReplyDelete
  18. I have the same issue as Anonymous wrote in April. After a reboot the HD woun't mount automaticly, but it mounts nicely if I write this command: sudo mount -t ntfs-3g -o uid=1000,gid=1000,umask=007 /dev/sda5 /media/NASDRIVE . Can someone help? :-)

    ReplyDelete
  19. Good tutorial, but I don't like it that my HDD keeps spinning all the time. Is there a way to make it go to sleep when it's not used in a while?

    ReplyDelete
    Replies
    1. Well sorry for replying late, However based on my observation in my setup the HDD goes to sleep automatically when not accessed for certain period of time. It automatically spins up from sleep when accessed again. I haven't made any config or settings for that.

      Delete
  20. If you're editing /etc/fstab and you have drive names, username, passwords, etc. which contain spaces, you may want to try replacing them with '\040' as escaping backslashes and quotes doesn't seem to be permitted in the fstab file

    ReplyDelete
  21. Thanks for tutorial, i had a little bit of trouble with step 4 before i realized i was missing a space in Step 4 eg."/dev/sda1 /media/NASDRIVE".

    ReplyDelete