Discopter Pi Guide

Chapter 17: Mounting External Storage

If you've taken the advice of this guide, you're using a smaller sized SD card, somewhere in the range of 32 or 64GB at most. The advantages of this approach were explained in Chapter 1. This chapter will go over how to configure an external storage device. Your personal files (movies, games, books, music, documents) will go onto this drive and be accessible by the programs and services running on your SD card.

A quick note on file systems. This guide will be using ext4. If you are configuring the storage to work on and for your Raspberry Pi, using the most advanced native Linux file system is definitely the way to go. It does however mean that you won't be able to use the storage device on a Windows machine, unless you download specific software to do so. If cross-OS compatability is an absolute must, then wherever you see ext4, replace with exfat, which while not as performant as ext4, will work on every operating system.

Step 1: Prepare the Device

  1. Unplug any other USB devices from the Pi, if there are any.
  2. Plug the external storage device into your Pi. Your Pi may have two USB 3.1 or 3.2 ports (blue or green color). Use one of those if it does.
  3. Identify the device. It should be sda, if it's a standard USB drive. If you're using an NVMe drive, it'll be labelled nvme0 instead.
    lsblk
  4. Configure the device with the parted command. If for some reason the above command produced anything other than sda, replace sda with its actual label.
    sudo parted /dev/sda
  5. Create a GPT partition table. This will completely erase all files on the device and create a primary ext4 partition using the entire disk.
    mklabel gpt
    mkpart primary ext4 0% 100%
    quit
  6. Format the partition. Again, replace sda1 with sdb1 if applicable, or whatever your devices partition is labelled as.
    sudo mkfs.ext4 /dev/sda1

Fun fact: The "sd" in sda, sdb, etc., stands for SCSI disk (pronounced "scuzzy"). The protocol is now used for SATA and USB connections as well. NVMe connections use a different protocol, so they aren't labelled an "sd" device.

Step 2: Configure Automount

  1. Create the mount point. This example will place it in the current user's home directory.
    mkdir ~/external_storage
  2. Copy the UUID of the partition. This is the number Linux uses to identify the file partition.
    sudo blkid /dev/sda1
  3. Edit the fstab file. This file governs automount points at startup.
    sudo nano /etc/fstab
  4. Add this line to automount the partition.
    UUID=<UUID identified above, no quotes> /home/<username>/external_storage ext4 defaults 0 2
  5. Mount all filesystems defined in fstab:
    sudo mount -a
  6. Check if it is mounted correctly.
    df -h
  7. Reboot. You should be able to access the drive in the mount point set.

Replace ~/external_drive with whatever you plan on using. Mounting to the /mnt or /media top level directories is pretty common and can have some advantages. Placing in your home directory makes sense if you're just using it as a file system, i.e., how most people use external storage. If you want applications to be able to read and write to it, some may run as system accounts. If the mount point is in your home directory, then you'll have to grant access to your entire home directory to these system accounts, which you might not want to do. NextCloud, for example, relies on the www-data user account. If it can't access your external storage, which it can't if it's in your home directory unless you give it full access to it, then you won't be able to use it to read/write documents in NextCloud.

This is why understanding the Linux file system is so important. What goes for your home directory is doubly so for files and folders owned by root. If you're trying to use external storage for a service like NextCloud or Jellyfin, pay close attention to the file permissions.