How to Add USB Storage to the Raspberry Pi

I’ve recently been looking at options for expanding the storage on my Raspberry Pi. Such choices are limited – the USB ports are often used by a keyboard, mouse or retro game controllers, while the SD card slot is naturally limited to just a single device.

In terms of expanding storage via USB devices, there are two options, but how you connect these will affect how successful you are. For instance, you might connect your USB hard disk drive or flash drive to one of the USB ports – but if that port is needed for another device, things can get tricky.

Many Raspberry Pi owners use powered USB hubs to get around this problem, and once you’ve recognized the importance of this (the computer doesn’t draw enough power to deal with the majority of USB devices) then adding a new USB device – storage or otherwise – shouldn’t be a problem.

There are a few things that you need to be aware of when expanding storage on your Raspberry Pi, however. Although there are really only two common USB storage options (flash drive and hard disk drive) you should also look out below for a very useful card-expanding trick for the Raspbian operating system.

Three Main Storage Options

You will find that in order to add, store and remove data to a Raspberry Pi, you have three main options:

  • SD/SDHC card
  • USB flash drive
  • USB hard disk drive

You can also use network drives, USB DVD-R drives and NAS devices (perhaps powered by a Raspberry Pi!) for additional storage, but those listed above should be considered your three primary options.

We’ll take a look at the three options in more detail, how they can be used most effectively and at any shortcomings or drawbacks.

Using an SD Card for Raspberry Pi Data Storage

As you will probably know if you’re using a Raspberry Pi, the SD card is the main storage option. The Pi uses this card – which should be an SDHC card for the best results – as a boot device, for running the operating system and general storage. It effectively replaces the role of a hard disk drive in standard desktop computers, although it might be considered more akin to an SSD in terms of the lack of moving parts and being low energy.

muo rasppi sd22   How to Add USB Storage to the Raspberry Pi

There are various operating systems for the Raspberry Pi. Probably the most popular is Raspbian, which by default is designed to run on a 2 GB SD card. The result of this is that when flashing a Raspbian image, all SD cards will have a partition of 2 GB, with a big chunk of the SD card storage left unused.

Fortunately there is a way around this. An expand file system feature is included in the raspi-config screen in Raspbian, and enables you to expand the size of the partition to the maximum capacity of your SD card. See 4 Tweaks to Super Charge Your Raspberry Pi for full details on how to do this.

Connecting and Mounting a USB Flash Drive

Inserting a USB flash drive won’t have the same effect as it does on an OS such as Ubuntu or Windows. Instead, you will need to manually mount the device in order to use it as additional USB storage for your Raspberry Pi.

sudo ls /dev/sd*

muo rpi usb stick   How to Add USB Storage to the Raspberry Pi

This will reveal the correct name for the USB device (either sda1 or sda2). You should then enter the following, taking care to replace [USB_DEVICE_NUMBER] with the device name as discovered above.

sudo mount -t vfat /dev/[USB_DEVICE_NUMBER]/mnt/usb

Your USB flash drive will then be mounted as a device, accessible from the file browser on your Raspberry Pi!

What About a USB HDD?

Particularly useful if you are using your Raspberry Pi as the main component of a media centre or NAS box, connecting a hard disk drive will afford a massive storage boost.

muo rasppi hdd   How to Add USB Storage to the Raspberry Pi

Also, take heed concerning the use of powered USB hubs, as mentioned above, If your USB HDD has no power supply (unlikely, but they exist) then you should use a powered USB hub. A HDD with its own power supply should be used otherwise.

Now, you might run into problems mounting a USB hard disk drive on your Raspberry Pi. In an ideal situation, this would be a case of plug-and-play, and if you have the most up-to-date Pi then you should be able to access your HDD with your minicomputer with little trouble – the device should mount automatically and everything will just work.

Without the right configuration and disk file system, however, you’ll find that the disk drive performs poorly. For instance, it is possible to use an NTFS drive with the addition of a driver, but the data transfer with this method is slow. In order to use your USB hard disk drive effectively (and exclusively on your Raspberry Pi) the EXT 4 file system must be used – so if you have any data on your HDD already, this will need to be backed up first before reformatting.

Configuring a USB HDD for the Raspberry Pi

Is your external USB hard disk drive empty? If so, you should format it in EXT4, something you can do within Raspbian with:

sudo mkfs.ext4 /dev/sda1 -L untitled

Should you first need to mount the drive (for instance, you might already have an EXT4 partition), use the following:

sudo mkdir /mnt/usbdrive

This creates a directory for the device, which is mounted with this command:

sudo mount /dev/sda1 /mnt/usbdrive

You can use the following command to list the contents of the mounted drive:

ls /mnt/usbdrive

Finally, if you plan to remove the drive while the Raspberry Pi is powered up:

sudo umount /dev/sda1

As a side note, if you don’t want to reformat your HDD with the EXT4 file system, however, you can still use NTFS with a performance hit. You’ll need a drive for this, so open Terminal and enter:

sudo apt-get install ntfs-3g

This will install the driver, enabling you to use an NTFS hard disk drive with your Raspberry Pi.

Easy to Set Up – If You Make the Right Choice

With two extended storage options for USB (plus the bonus of maximising SD card storage in Raspbian), the Raspberry Pi can have access to the same wealth of external space as a desktop computer.

muo rpi hdd   How to Add USB Storage to the Raspberry Pi

Although the ability to use a USB flash drive is useful, you will probably get the best storage and fastest results using an external USB HDD formatted with EXT4. This will need to be a dedicated drive, however, as EXT4 isn’t compatible with other operating systems. If this isn’t practical, use a hard disk drive formatted as NTFS with the ntfs-3g driver.

Extra storage provides boons in most Raspberry Pi projects, from a RaspBMC powered media centre to setting up a NAS box. Note that what we’ve discussed here is for the Raspbian OS and related builds – other (less popular) Raspberry Pi operating systems may have different commands and drivers for managing storage.

Image Credits: Vector raspberry, Flash drive via Shutterstock

The comments were closed because the article is more than 180 days old.

If you have any questions related to what's mentioned in the article or need help with any computer issue, ask it on MakeUseOf Answers—We and our community will be more than happy to help.

9 Comments -

Gerrit Bon

I Use this method as described above (powered usb-hub and usb-hdd). The extra space is used for usenet-downloads using sabnzbd.

Unfortunately, with user pi or with sudo, I’m not able to gain write-rights on my hdd. Also, the format command is not accepted. What could be the problem here?

I’m using Debian GNU/Linux.

Thanks in advance for any help! Gerrit.

Matt

I would like to use an EXT4 hard drive with my raspberry pi to play files off of (because of better speeds and such). I used Parted Magic to reformat my hard drive so that it’s EXT4 and that worked, but I can’t find a program to let me transfer files from my computer’s hard drive to the EXT4 external hard drive that I want to use on my RPi. Any ideas? The top results from Google didn’t end up working for me.

Franky

MAtt – Ext2FSD / ExtRead are two apps that allows you to write / read on windows 7.

Nick

all here needed was:

apt-get install usbmount

Ranjeet Malik

Is there any similar guide for Beagle Board Black.

Regards,

syslq

This is not PI specific. Your board runs linux and you can follow the same steps.
If you plug in more than one drive just type dmesg|grep “sd” and you’ll get an output of all drives reckognized by the system.

BR, syslq

syslq

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1389 root 20 0 4888 1140 604 R 92.9 0.3 41:58.31 mount.ntfs-3g

ntfs-3g is extremely heavy on CPU for what is basically an embedded system :).

syslq

Meh, it came out a bit “re-formated”, cpu utilization in above copy&paste from TOP output is 92.9% of cpu, durring quite heavy write process.
Just something to keep in mind.

chunkking

Thank you for the straightforward guide. I’m a linux newb -well, I know enough to be dangerous – never used an external harddrive, and am somewhat familiar with the Pi and man pages. I followed the directions for formatting a Western Digital MyBook. The latest greatest (2014-01-21) wheezy had automagically mounted the disk and would not let me do the mkfs until after I had unmounted it. Just a note for your consideration.