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.
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
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
vfat. Once you have it mounted, it’s time to explore…
cd /media/USBHDD (That’s both lower case letter l, not number 1)…
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…
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…
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.