I've recently been looking at options for expanding the storage on my Raspberry Pi (UK). 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-sd2

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

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

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

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