Adding USB Storage
Last updated
Last updated
You can add extra disk storage to an Iron Pi using an off-the-shelf USB flash disk or external hard drive. However, mapping the storage into your environment takes a few manual steps.
Start by plugging the USB disk into one of the Iron Pi's USB ports. Run the lsblk
command to see the raw disk. In the example below, the USB disk is listed as sda
, and the detected capacity if 14.3GB. It's normal for the detected capacity to be a bit below the drive's nominal capacity.
The disk has one partition, sda1
. We will use that partition name in the next step when creating the filesystem.
mmcblk0
is the Iron Pi's built-in flash drive. Do not try to format mmcblk0
as an external disk!
If you want to use the USB drive to move files between the Iron Pi and a Windows or Mac computer, you should stick with a FAT32 filesystem, which is how most USB flash drives come formatted from the factory. If you want to use FAT32, you can skip the ext4 filesystem creation step below.
ext4
filesystemIf you want to use the USB drive to run applications on the Iron Pi, it's best to format it with a native Linux filesystem.
To create a Linux filesystem on your USB disk, run:
sudo mkfs -t ext4 <PARTITION>
In this example, our partition is /dev/sda1, so our command would be:
sudo mkfs -t ext4 /dev/sda1
To access an external drive in Linux, you need to mount the disk, which means attaching it to the operating system's logical file tree.
The /mnt
directory is a common place to mount external drives. In this example, we'll create a directory called /mnt/usb
and mount the USB drive there.
sudo mkdir -p /mnt/usb
Once we've created the mount point, let's try mounting the filesystem to it. The command to do that is:
sudo mount <PARTITION> <MOUNT POINT>
In this example, our command would be:
sudo mount /dev/sda1 /mnt/usb
After mounting the disk, run the df -h
command to check that it's properly attached. In the example below, you can see that /dev/sda1
is mounted to /mnt/usb
and has a capacity of 14GB.
If you want the disk to automatically mount each time the device boots, you will need to add an entry to the /etc/fstab file. Run sudo nano /etc/fstab
to edit that file.
In the editor, add a line with the following contents:
<PARTITION> <MOUNT POINT> <FILESYSTEM TYPE> defaults 0 2
Put a tab beween each field. In this example, our entry is:
/dev/sda1 /mnt/usb ext4 defaults 0 2
Type ctrl-X
to save and exit. Run sudo reboot
to reboot the device, and then run df -h
after rebooting to ensure that your disk mounted correctly.