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…
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…
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
CTRL-C
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
(That’s both lower case letter l, not number 1)…
ls -l
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…
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.
Unmounting
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.
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.
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!
There was a very good discussion about this in the raspberry pi forums last week
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=27&t=16748
Have a good read of that thread.
You might need to install ntfs-3g
You might need to chown/chmod the directory you’re mounting the disk to.
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. :-)
That’s where e.g. http://www.howtogeek.com/112888/3-ways-to-access-your-linux-partitions-from-windows/ comes in handy :-)
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
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
Good idea. Maybe someone else can chip in here? I haven’t done that before.
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?!?!
Brilliant tutorial just got a Pi and an old hard disk and it worked perfectly.
Thanks :-D
You’re welcome. It’s always nice to hear back from people who have found the site helpful :)
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:
Dziękuje :)
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!
Great, that’s the idea Larry. “Complete instructions that work first time” is what I’m aiming for.
[…] connected my hard-disk-drive (HDD) and set it up according to these instructions on […]
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.
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?
I hope someone else can answer some of your questions as they’re all a bit outside my experience.
I can’t help with your first or last points, but there’s been several guides written for your middle point e.g. http://elinux.org/RPi_Tutorials#Raspbian_on_Raspberry_Pi_using_SD_card_.2B_USB_memory_stick
Thanks, but that article is about splitting the OS to use a smaller ‘boot only’ SD card; using a USB stick still means a limited number of read/write cycles, so it didn’t even mention things like the swap file/partition, or any other locations used by the OS or ‘standard’ processes..
As far as Linux is concerned, there’s no difference between a “USB memory stick” and a “USB hard drive”… :-)
And did you try asking google? https://www.google.co.uk/search?q=raspberry+pi+run+from+hard+drive
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?
That just sounds plain silly for a userid value. Not come across that one. :(
You can look at /etc/passwd and /etc/group if you need to map username and group strings into their numeric equivalents.
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
help
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?
He’s using trying to use sudo mkdir, so the write permissions should be irrelevant.
Maybe the disk didn’t get mounted properly? What output do you get from typing just ‘mount’ by itself?
I missed that. Is it also possible that it’s not a FAT drive but an NTSC one?
*giggle* or it could be a PAL drive ;-)
Joking aside, if it was NTFS rather than FAT, then the mount command should have displayed an error message.
LOL of course I meant NTFS. NTSC stands for Never Twice the Same Color
LOL! John “maddog” Hall (the Executive Director of Linux International) made the same mistake in a big presentation recently which I’m now watching on youtube
http://www.youtube.com/watch?v=SOxB1IaozCA&feature=player_detailpage#t=1247
You’re in great company Alex :)
Awesome. Good catch. Just watched that. :)
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!
How is the drive powered? If it’s only powered over USB it’s likely that the Pi’s USB ports aren’t able to provide enough power for the drive to function correctly. http://elinux.org/R-Pi_Troubleshooting
Are you able to power the USB HDD with an external PSU, or from an externally-powered USB hub?
I should have anticipated that question. It’s already on a powered hub. A.
Is it possible even the powered hub isn’t providing enough power to the drive? http://shop.pimoroni.com/products/pihub has high-power USB ports.
From your bootup messages, it looks like the drive appears but then mysteriously stops working when trying to read the partition table (which obviously requires the disk to be spun up).
I’ve got a 2.5″ portable USB harddrive which beeps at me if it doesn’t get enough power… (but mine also has a socket for an external 5V power adaptor).
This is the hub — no mention of how much power is available! USB2.0
http://cpc.farnell.com/dynamode/usb-h70-1a2-0/hub-usb-2-0-7-port-with-ac-adaptor/dp/CS21973
This is the drive (also USB2.0), also no power requirement!
http://www.misco.co.uk/product/Q206585/Freecom-Mobile-Drive-Classic-II-320GB-USB-2-0-Portable-Hard-Drive
Does USB specify the power?
Dunno what else to suggest :-S
The ‘official spec’ is that USB supplies up to 500mA http://en.wikipedia.org/wiki/Usb#Power but some devices try to draw more than this.
Does the same powered hub work with the same USB drive when connected to a regular Linux PC? Do you get similar or different output in /var/log/messages ?
The fact that your drive beeps when you try connecting it to the Pi suggests that it’s a hardware problem with the drive, rather than a software problem with the Pi, but I guess it can’t hurt to try a different/updated OS on your Pi, if you haven’t already.
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??
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!
I did find that ntfs was 3 times slower than ext4 through USB. Through the network, I don’t know. CIFS works well, but I’ve never done speed tests. Live 1080p streaming is more than my wifi router really copes well with, so it depends if you’re talking wired or wifi. I doubt that the USB drive would be the limiting factor here.
It’s probably worth asking on http://www.raspberrypi.org/forum/viewforum.php?f=35 :-)
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 ?
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.
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?
Huh?! Nothing in Alex’s instructions above require your Pi to be connected to the internet…
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?
If you get sda1 – sda4 it sounds like your hard drive has multiple partitions. I’d mount them all and see what’s on them :)
Thank you for a great article :)
Wish more were as clear!
Excellent.
im stuck at
pi@raspberrypi:~ $ tail -f /var/log/messages
Oct 25 22:50:03 raspberrypi rsyslogd-2007: action ‘action 17’ suspended, next retry is Tue Oct 25 22:50:33 2016 [try http://www.rsyslog.com/e/2007 ]
Oct 25 22:50:09 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/Seagate Expansion Drive/BDMV/index.bdmv
Oct 25 22:50:09 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/Seagate Expansion Drive/BDMV/BACKUP/index.bdmv
Oct 25 22:50:10 raspberrypi kernel: [ 27.073856] EXT4-fs (mmcblk0p5): mounted filesystem with ordered data mode. Opts: (null)
Oct 25 22:50:10 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/SETTINGS/BDMV/index.bdmv
Oct 25 22:50:10 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/SETTINGS/BDMV/BACKUP/index.bdmv
Oct 25 22:53:51 raspberrypi kernel: [ 248.293361] usb 1-1.3: USB disconnect, device number 5
Oct 25 22:53:51 raspberrypi kernel: [ 248.300986] sd 0:0:0:0: [sda] Synchronizing SCSI cache
Oct 25 22:53:51 raspberrypi kernel: [ 248.301241] sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=0x01 driverbyte=0x00
Oct 25 22:53:51 raspberrypi rsyslogd-2007: action ‘action 17’ suspended, next retry is Tue Oct 25 22:54:21 2016 [try http://www.rsyslog.com/e/2007 ]
Oct 25 22:57:59 raspberrypi kernel: [ 496.886070] usb 1-1.3: new high-speed USB device number 6 using dwc_otg
Oct 25 22:57:59 raspberrypi rsyslogd-2007: action ‘action 17’ suspended, next retry is Tue Oct 25 22:58:29 2016 [try http://www.rsyslog.com/e/2007 ]
Oct 25 22:57:59 raspberrypi kernel: [ 497.028126] usb 1-1.3: New USB device found, idVendor=0bc2, idProduct=3322
Oct 25 22:57:59 raspberrypi kernel: [ 497.028151] usb 1-1.3: New USB device strings: Mfr=2, Product=3, SerialNumber=1
Oct 25 22:57:59 raspberrypi kernel: [ 497.028165] usb 1-1.3: Product: Expansion Desk
Oct 25 22:57:59 raspberrypi kernel: [ 497.028177] usb 1-1.3: Manufacturer: Seagate
Oct 25 22:57:59 raspberrypi kernel: [ 497.028189] usb 1-1.3: SerialNumber: NA8F135J
Oct 25 22:57:59 raspberrypi kernel: [ 497.030642] usb-storage 1-1.3:1.0: USB Mass Storage device detected
Oct 25 22:57:59 raspberrypi kernel: [ 497.031348] scsi host1: usb-storage 1-1.3:1.0
Oct 25 22:58:00 raspberrypi kernel: [ 498.027153] scsi 1:0:0:0: Direct-Access Seagate Expansion Desk 9401 PQ: 0 ANSI: 6
Oct 25 22:58:00 raspberrypi kernel: [ 498.028630] sd 1:0:0:0: Attached scsi generic sg0 type 0
Oct 25 22:58:00 raspberrypi kernel: [ 498.030277] sd 1:0:0:0: [sda] Spinning up disk…
Oct 25 22:58:14 raspberrypi kernel: [ 499.036166] ………….ready
Oct 25 22:58:14 raspberrypi kernel: [ 511.156873] sd 1:0:0:0: [sda] Very big device. Trying to use READ CAPACITY(16).
Oct 25 22:58:14 raspberrypi kernel: [ 511.157188] sd 1:0:0:0: [sda] 9767541167 512-byte logical blocks: (5.00 TB/4.55 TiB)
Oct 25 22:58:14 raspberrypi kernel: [ 511.191175] sd 1:0:0:0: [sda] Write Protect is off
Oct 25 22:58:14 raspberrypi kernel: [ 511.191763] sd 1:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn’t support DPO or FUA
Oct 25 22:58:14 raspberrypi kernel: [ 511.192822] sd 1:0:0:0: [sda] Very big device. Trying to use READ CAPACITY(16).
Oct 25 22:58:14 raspberrypi kernel: [ 511.281283] sda: sda1 sda2
Oct 25 22:58:14 raspberrypi kernel: [ 511.282545] sd 1:0:0:0: [sda] Very big device. Trying to use READ CAPACITY(16).
Oct 25 22:58:14 raspberrypi kernel: [ 511.283538] sd 1:0:0:0: [sda] Attached SCSI disk
Oct 25 22:58:19 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/Seagate Expansion Drive/BDMV/index.bdmv
Oct 25 22:58:19 raspberrypi org.gtk.Private.UDisks2VolumeMonitor[933]: index_parse.c:191: indx_parse(): error opening /media/pi/Seagate Expansion Drive/BDMV/BACKUP/index.bdmv
^C
pi@raspberrypi:~ $ sudo mkdir /media/THEVAULT
pi@raspberrypi:~ $ mount -t ntfs-3g /dev/sda1 sda2
mount: only root can use “–types” option
pi@raspberrypi:~ $ mount -t ntfs-3g /dev/sda1
mount: only root can use “–types” option
pi@raspberrypi:~ $ sudo mkdir /media//USBHDD
pi@raspberrypi:~ $ mount -t ntfs-3g /dev/sda1 /media/USBHDD
mount: only root can use “–types” option
pi@raspberrypi:~ $ mount -t ntfs-3g /dev/sda1 sda2 /media/USBHDD
mount: only root can use “–types” option
pi@raspberrypi:~ $ sudo mkdir /media/sharename
pi@raspberrypi:~ $ sudo mkdir /media/THEVAULT
mkdir: cannot create directory ‘/media/THEVAULT’: File exists
pi@raspberrypi:~ $ mount -t ntfs-3g /dev/sda2
mount: only root can use “–types” option
pi@raspberrypi:~ $
Thank you for this nice tutorial. I had my NTFS HDD already full with movies and I couldn’t switch to FAT32 format. Since my Raspbian automatically mounts as read only any USB drive that is connected, I had to first unmount my HDD then follow your instructions and voila, my RPI allows full access (R/W) of my NTFS HDD. Thanks again.
Installing ntfs-3g worked for me but only after sudo apt-get upgrade.