The Raspberry Pi’s operating system runs from a limited size, permanently inserted microSD card. This post will show how to mount a movable external USB drive for additional space, or purely for transportation purposes.
Step 1 Check the hardware
External USB drives can be in the form of a USB stick drive or USB storage drive. With regards to additional power requirements, USB memory sticks should be fine, but most external HDDs will require either their own power supply or a USB hub to run in a stable manner.
The Raspberry Pi should be switched on after the external drive is plugged in.
To check if the USB drive is attached correctly use the
The USB drive should show up somewhere. In this example, a USB stick drive is used for demonstration.
blkid shows that a drive with the
UUID="01F7-01E5" and a boot partition name of
/dev/sda1 is connected.
The TYPE field shows the file system type and the boot partition name will be the USB drive’s mounting directory.
If TYPE is NTFS,
ntfs-3g needs to be installed:
sudo apt-get install ntfs-3g
Step 2 Creating the local mount point directory
Although any directory can be used, the root
/mnt directory is assumed to be used for mounting purposes. Assuming the mount directory will be
/mnt/usb, it can be created by using:
Note that the Linux directory structure is case-sensitive. To make it fully accessible to all users, use:
sudo chmod -R 777 /mnt/usb sudo chown pi:pi /mnt/usb
This will be the local mount point directory.
Step 3 Run the mount command
With the USB drive’s mounting directory and the local mount point directory known and prepared, the external USB drive can be mounted with:
sudo mount /dev/sda1 /mnt/usb
To test whether mounting took place correctly, use:
From this, it is visible that the
/mnt/usb directory is mounted to the
Step 4 Automounting the USB drive on boot
The USB drive can either be mounted/unmounted manually every time it is required or it can be mounted automatically at each boot.
To mount the USB drive automatically every time at each boot, the mounting command can be added to
sudo nano /etc/fstab
Ignore the existing content of the
fstab file. All that is needed is to add the new mounting entry at the bottom of the file.
# <name> <dir> <type> <options> <dump> <pass> /dev/sda1 / ext4 defaults 1 1 /dev/hdxx /usr ext4 defaults 1 1 /dev/sda5 swap swap defaults 0 0
Looking at the example
fstab file above, the columns are as follows:
- <name> is the device name or other means of locating the partition or data source. The UUID or boot partition name can be used.
- <dir> is where the data is to be attached to the file system (the local mount point directory).
- <type> is the file system type or the algorithm used to interpret the file system.
- <options>, including if the file system should be mounted at boot. In this case it will be defaults.
- <dump> is the dump frequency that adjusts the archiving schedule for the partition (used by dump). In this case, it will be 0.
- <number> is the pass number, which controls the order in which fsck checks the device/partition for errors at boot time. The root device should be 1. Other partitions (including external drives) should be either 2 (to check after root) or 0 (to disable checking for that partition altogether).
For this example add the following line to the bottom:
# <name> <dir> <type> <options> <dump> <pass> /dev/sda1/ /mnt/usb vfat defaults 0 0
Ctrl x & y to save out.
More about the
fstab file can be read on the Debian wiki.
Step 5 Unmounting the USB drive
To unmount the USB again, use:
sudo umount /mnt/usb