Jun 102012

External Storage – USB HDD

Sooner or later you will want to attach some sort of external storage to your Raspberry Pi’s USB port. We’ve already seen how to identify and mount a USB flash drive / memory stick. The procedure for mounting and using an external USB hard disk is very similar and equally easy. Until now, I’ve been using 8 Gigabyte memory sticks, but a lot of my media is on a 500 Gig HDD, so I found out how to attach and use that. I’m sharing it here as I think it may be useful to others.

Power Requirements

A device like a hard disk will almost certainly need more power than the Raspberry Pi is capable of providing from its built in USB ports. If your USB HDD takes its power from the USB port, you will have to use a powered USB hub. If your USB hard drive has its own external power supply, use that.

Mount a USB Hard Disk Drive on Raspberry Pi

First we need to find out where our system locates the device. Before you plug the USB device in, type…
tail -f /var/log/messages

You should then see something like this…

output from intial tail command

Now plug your USB hard drive into the USB port (if externally powered) or USB hub (if USB powered) and watch for new messages. This is what came up when I plugged mine in…

Tail output after plugging in USB hard disk drive

As you can see it gives you all sorts of info about the disk drive. The main part which interests us is the id that the computer gave it. In this case, sda1 (circled in red).

At this point, the tail command has served its purpose so we can kill it with


Before we can mount the drive, we need to make a directory (folder) for it. You only have to do this the first time – you can use the same directory next time as it will still be there.

sudo mkdir /media/USBHDD (where USBHDD can be anything you like)

If you are logged on as root, you can attempt to mount it as an ntfs drive

mount -t ntfs-3g /dev/sda1 /media/USBHDD

If you are logged on as the default Raspberry Pi Debian user, pi, you will need to use this command to mount the drive with read/write permission.

sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/usbdrive/

If that doesn’t work, it will give you an error message, then instead of ntfs-3g try vfat. Once you have it mounted, it’s time to explore…

cd /media/USBHDD
ls -l
(That’s both lower case letter l, not number 1)…

ls -l of mounted disk

This shows you the top level directory of the disk. You can navigate around to different directories with the cd command. cd stands for change directory. So, to change to “Audio Recording” we would need to type…

cd "Audio Recording" (we need the quotes because the directory name contains a space).

Then to look at what’s in Audio Recording…

ls -l which outputs the list of files and/or sub-directories in the directory…

ls -l gives contents of the folder

To change back up a level you can type…

cd ..

Then navigate to whichever directory you want on your hard drive and do what you wanted to do with it.


Once you’re done, before you unplug the USB lead from your drive, you need to unmount it with umount.

sudo umount /media/USBHDD

It won’t unmount if you are somewhere within the /media/USBHDD file system. If you are, type…

cd /media

and then try the umount command again.

unmounting the drive with umount

Note what happened when I forgot the sudo. (You need to use sudo or be logged in as root user to mount and unmount drives.)

Using HDD with media players

If you are using XBMC via OpenELEC, Raspbmc etc. your hard drive will be detected automatically. If you are using Omxplayer from the command line in Debian or Arch, you’ll need to mount the drive as above.

  51 Responses to “How to mount and use a USB hard disk with the Raspberry Pi”

  1. Great tutorial.

    I have my usb hard drive mounted and working in raspbmc. The problem i’m having is that i can’t write to the usb drive as the Pi user. As root user, it’s no problem. I’m a linux newbie.

    What do i need to do to enable write access for any user? Thanks!

  2. Good tutorial but it could be improved with editing the /etc/fstab imo, and why do you assume people have ntfs disks ? I personnaly don’t recommand NTFS for RPi storage as it doesn’t support permissions and stuff.. I think a linux format should be advised (like ext3) to people that want to add stoage to their RPi !
    Keep up this blog, really nice for begginners !

    • The thing is I’m writing out of my own Raspberry Pi experiences and I had a bucket load of trouble messing about with the fstab. It might have been a quirk of the early releases of Raspbian, it might have been the famous “USB issue” or it might have been my specific HDD. I don’t know. I wrote it this way because it works for me.

      NTFS is very popular with Windows users. It’s also the default format when you buy a lot of USB HDDs. I agree with you that EXT4 is much better if you only want to use the HDD with your Pi. I reformatted mine into EXT4 and got a huge performance increase (something like 3 times faster). But EXT4 is not so great if you still want to be able to use the device with a Windows machine. :-)

    • I had the following in my /etc/fstab:
      UUID=bcf2865d-cea5-4d21-9dc5-8d232ae85e41 /mnt/usbdrive ext3 defaults 0 2
      My pi would not finish the boot sequence when the disk was powered off: it displayed a warning (which I only saw after hooking it up to my TV, because networking was not yet started!) that I had to press “Ctrl-D” to skip mounting it.

      So unless there’s an option to only mount if it’s available, I’d advise against it.

      One more thing: I tried mounting /dev/sda1, but that device name can change (e.g. /dev/sdb1), so the UUID (which you can find by running blkid) is more robust because it stays the same.

      • I found the right option in man mount -8:
        nofail Do not report errors for this device if it does not exist.
        So this should work:
        UUID=bcf2865d-cea5-4d21-9dc5-8d232ae85e41 /mnt/usbdrive ext3 defaults,nofail 0 2
        See man fstab for details

  3. I have found this very informative as a complete novice. What could be done to assist someone like me is to explain what the steps are if you attach a new drive – ie a drive straight out of the box. Following the steps outlined the drive shows as:
    Bus 001 Device 016: ID I52d:2329 etc

    I can’t seem to find any reference for a beginner on how to initialise the drive! So that it reads sda: sda1

  4. The Seagate USB3 500Gb HDD is seen and accessible straight up using fedora remix for the RPi – when I started up, with the drive connected, fedora displayed an icon for the drive, described it as Seagate and allowed me to open it. Once open it had a number of directories and files pre-installed.

    My experience with raspbian on the other hand was not a success. RISC OS pi has also baulked with an error message telling me that it doesn’t recognise ‘this DOS format’ – is there still a size limit on the HDD that RISC OS can access/read?!?!

  5. Brilliant tutorial just got a Pi and an old hard disk and it worked perfectly.

    Thanks :-D

  6. For those who got error:
    mount: unknown filesystem type 'ntfs-3g'
    There is a need to install ntfs-3g:
    sudo apt-get install ntfs-3g
    Very good tutorial anyway :yes:

  7. I finally got my Raspbmc running and stable on WiFi. The next step was media. I followed your steps and mounted a USB stick that contained some of my photos. The mounting (and later unmounting) worked perfectly. The next step was to set up a slide show of the photos using XBMC. It worked very well. That helped me move to a slide show display of photos from this Windows laptop over the WLAN.
    The value of your steps is that they are complete with screen shots that prove the steps will work. And, steps that work allow me to progress quickly to getting my media center Pi working.
    Thank you Alex!

  8. […] connected my hard-disk-drive (HDD) and set it up according to these instructions on […]

  9. Thank you for doing this. The more information in step by step the better. This is suppose to be a beginners platform for kids. It is incomplete in a central repository sense and people have to look everywhere to get things. So thank you for your efforts. I spent a frustrating weekend trying to locate openSSL-dev files for inclusion in my C programs. I only found them by some blog like this one off subject that also used them and they listed the steps in finding them for their project. We should all chip in as your doing and list all we can about developing software and hardware for the platform and making all the information accessible so that kids not unix experts can have success with their efforts. Otherwise the Pi will struggle on its main mission. It is a powerful platform. Thank you Alex for your contribution.

  10. I just got a USB HDD connected to my Pi, and I can mount it manually, but adding a line to /etc/fstab doesn’t mount it at startup. I’ve tried the last parameter as 0 and 2, but neither has worked.
    Once I can get it to mount, the next thing I would like to do is make the system use the HDD (after bootup) rather than the SD card, to reduce read/write cycles.. Perhaps this could be added to your instructions? (I’ve got Apache running, too; I would appreciate seeing some information on its configuration options.. and how does linux deal with permissions on a FAT partition?

  11. When I sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda1 /media/usbdrive/ I get an error that says ‘uid option needs a decimal value’

    Has anyone ran into this problem?

  12. I let it ride. but will not let me create folders nor access

    pi@raspberrypi ~ $ sudo mount -t vfat -o uid=pi,gid=pi /dev/sdb1 /media/disco
    pi@raspberrypi ~ $ cd /media/disco/
    pi@raspberrypi /media/disco $ ls -l
    total 0
    pi@raspberrypi /media/disco $ sudo mkdir prueba
    mkdir: no se puede crear el directorio «prueba»: Error de entrada/salida


    • You probably don’t have write permissions in the mount location.

      One of the ways round this is to creat a subdirectory under /home/pi and mount your disk there, then give it whatever permissions you want.

      There’s probably another way (there always is), perhaps you can change the permissions in /media/disco using chmod and/or chown so that pi can write files?

  13. tail -f /var/log/messsages displays nothing extra when plugging in a usb freecom drive which works without problems on other windows and linux machines. The drive just starts beeping?

    From /var/log/messages on reboot with freecom plugged in:

    Dec 26 11:51:39 raspberrypi kernel: [ 5.728293] scsi 0:0:0:0: Direct-Access Freecom Mobile Drive XXS PQ: 0 ANSI: 2 CCS
    Dec 26 11:51:39 raspberrypi kernel: [ 5.753933] sd 0:0:0:0: [sda] 625142448 512-byte logical blocks: (320 GB/298 GiB)
    Dec 26 11:51:39 raspberrypi kernel: [ 5.781794] sd 0:0:0:0: [sda] Write Protect is off
    Dec 26 11:51:39 raspberrypi kernel: [ 5.801318] sd 0:0:0:0: [sda] Write cache: disabled, read cache: enabled, doesn’t support DPO or FUA
    Dec 26 11:51:39 raspberrypi kernel: [ 6.125013] usb 1-1.3.2: USB disconnect, device number 7
    Dec 26 11:51:39 raspberrypi kernel: [ 6.152490] sd 0:0:0:0: [sda] Unhandled error code
    Dec 26 11:51:39 raspberrypi kernel: [ 6.161892] sd 0:0:0:0: [sda]
    Dec 26 11:51:39 raspberrypi kernel: [ 6.169491] Result: hostbyte=0x01 driverbyte=0x00
    Dec 26 11:51:39 raspberrypi kernel: [ 6.178695] sd 0:0:0:0: [sda] CDB:
    Dec 26 11:51:39 raspberrypi kernel: [ 6.186685] cdb[0]=0x28: 28 00 00 00 00 00 00 00 08 00
    Dec 26 11:51:39 raspberrypi kernel: [ 6.216513] sda: unable to read partition table
    Dec 26 11:51:39 raspberrypi kernel: [ 6.242469] sd 0:0:0:0: [sda] READ CAPACITY failed
    Dec 26 11:51:39 raspberrypi kernel: [ 6.251639] sd 0:0:0:0: [sda]
    Dec 26 11:51:39 raspberrypi kernel: [ 6.276624] Result: hostbyte=0x01 driverbyte=0x00
    Dec 26 11:51:39 raspberrypi kernel: [ 6.291853] sd 0:0:0:0: [sda] Sense not available.
    Dec 26 11:51:39 raspberrypi kernel: [ 6.360469] sd 0:0:0:0: [sda] Attached SCSI disk

    Can anyone translate and advise how to mount the drive on RPi? Thanks!

  14. yoo beautifull but on my system, hdd “sda1″mount automaticly on ee…………….not possible to mount that on another place but no possibility to acces neither wats wrong??

  15. Great tutorial Thanks!
    one question: I would like to mount an HDD with ntfs ad XBMC and Samba on Model B (with or without overclock). do you think it is enough good to stream also 1080p or it would be better to move on xfs or oher linux file systems?
    Many Thanks for your advice!

  16. My NTFS USB disk (/dev/sda1) gets suddenly mounted by raspbmc on /media/mylabel_ (with an trailing underscore) and therefore the XBMC library fails to find the movie files. How can I make sure my USB disk gets always mounted on /media/mylabel ?

  17. Thank you very much for such a clear tutorial.

    I was going crazy since firts time I connected my hard drive to my raspberrt pi running raspbmc everything went ok. But aftewards, weeks after, rp didnt find my hdd.

    I follow your instructions and so far, so good.

    pi@raspbmc:~$ sudo blkid
    /dev/mmcblk0p1: UUID=”A899-D65C” TYPE=”vfat”
    /dev/mmcblk0p2: UUID=”4e4803b9-caf8-4c13-9108-3e2405804aea” TYPE=”ext4″
    /dev/sda1: LABEL=”Elements” UUID=”1ADC8962DC893951″ TYPE=”ntfs”
    pi@raspbmc:~$ sudo mkdir /media/Elements
    pi@raspbmc:~$ sudo mount -t ntfs-3g /dev/sda1 /media/Elements

    So, Thank you.

  18. I was so surprised when my TV remote worked as I did not know that technology, however I don’t get an IP at all. It’s the same cable that I use on my other computer, so I know it works.

    Funny thing is, I don’t need internet… I just need it to mount my External USB hard drive (which has it’s own power supply). I wanted to do the above, but I can’t since I don’t have internet.

    Any ideas?

  19. When I plug in my USB hard drive I get sda1 sda2 sda3 sda4 not just one specific section. Is this a sign it’s not partitioned correctly or something along those lines or something else. Also any idea what i then add in to mount my hard drive as this tutorial uses sda1 but I have no idea what to use?

  20. Thank you for a great article :)
    Wish more were as clear!

Leave a Reply