http://www.reuk.co.uk/Mount-USB-Memory-Stick-on-Raspberry-Pi.htm

Find out how to mount a USB flash drive on your Raspberry Pi

If you are using your Raspberry Pi to play music or video you will soon run out of storage on the SD card which holds the operating system. The easiest way to increase the capacity of the Raspberry Pi to store your media files is with a USB flash drive memory stick. These are very cheap to buy and typically available in sizes up to 128GB; though at the time of writing (Aug 2013) the most cost effective size of good quality drives is 16GB or 32GB. (Click here for SanDisk 32GB Cruzer Blades from £13)

USB flash drive memory stick for Raspberry Pi

If you have a free USB port on your Raspberry Pi then insert your memory stick. If you do not have a free port (because of your mouse and keyboard) then you will need a USB hub. Plug the hub into your Raspberry Pi, and then plug the memory stick and other peripherals into the hub. If you are going to be inserting and extracting the memory stick frequently then it is better to use a USB hub even if you have a free port on the Raspberry Pi, to reduce wear and tear on the Raspberry Pi.

Assuming you are using the standard Raspbian (e.g. Raspbian “Wheezy“) version of Linux on your Raspberry Pi, the memory stick will automatically be detected and given the id sda1. You can check that your memory stick has been correctly identified by entering the command.

ls -l /dev/sda1

and you should see something like the following:

…if the USB memory stick has not been identified then you will instead see:

ls: cannot access /dev/sda1: No such file or directory

Next you need to create a sub-directory in the /media directory on your Raspberry Pi so that the memory stick can be mounted.

sudo mkdir /media/usb

…where you can replace usb with your choice of name if you want, but keep it short as you will probably end up typing it a lot.

Mount USB Flash Drive on Raspberry Pi

Assuming you are logged in as user pi, enter the following command to mount your USB memory stick to /media/usb:

sudo mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usb

Now you can confirm you can see the contents of the memory stick with the command ls -l /media/usb which should generate a list of the files and directories on the stick.

To check how much memory you have available on the memory stick (and also on your Raspberry Pi SD card), enter the command df.

Using df command to check free storage space on Raspberry Pi USB memory

Look down the file system ID column to find the line with /dev/sda1 or look down the Mounted on column to find the line with /media/usb. In the example above an 8GB USB flash drive has been mounted and is shown to be 18% full. (Use the command df -BM for the same information on your file system but with all memory size values given in MB for better clarity.)

Unmount USB Flash Drive from Raspberry Pi

Before you disconnect the USB memory stick from the Raspberry Pi, you must first unmount it with the following command:

sudo umount /media/usb

.

Brief Notes on Rebooting

If you shutdown or reboot your Raspberry Pi, any USB memory sticks mounted in the way described above will be no longer be mounted when the Pi reboots – i.e. you will not be able to access the files on the memory stick until you enter the mounting command. If you plan to keep the USB memory stick permanently or semi-permanently attached to the Raspberry Pi, then it is better to have this occur automatically when the Pi reboots. There are many ways to achieve this, but here is a simple one using Cron.

Enter the command sudo crontab -e to edit your cron tasks file. Use the arrow keys to move down to the end of this file and add the following line:

@reboot mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usbGet USB drive to mount automatically at reboot with Raspberry Pi using cron

Now press ctrl-x, then y, then enter to save the changes. This will automatically mount the attached USB drive /dev/sda1 to the directory /media/usb for the user pi when the Raspberry Pi is rebooted.