Mount a USB Drive at Boot on Raspberry Pi¶
Give a USB SSD or hard drive a fixed path such as /mnt/usb-data so backups, media servers and file shares can find it after a reboot. This guide uses an existing ext4 data partition and an optional entry in /etc/fstab. Before starting an app that writes to the drive, verify that the path leads to the intended filesystem.
1. Find the USB filesystem UUID¶
Connect the drive to a Pi running Raspberry Pi OS with systemd. Use a drive whose files you have backed up. This procedure mounts an existing filesystem. For other filesystem types, check the appropriate mount options in the Raspberry Pi documentation. Raspberry Pi external storage documentation
Identify the USB disk by model and size. Copy the UUID of its ext4 partition. Leave the partitions mounted at / and /boot/firmware alone. A device name such as /dev/sda1 can change when you attach another drive. If the desktop already mounted the USB partition under /media, close the files and applications using it and unmount it from the file manager before continuing.
2. Add the USB drive to fstab¶
Create a dedicated, empty mount point and save a backup of the current configuration. If /mnt/usb-data already exists, inspect it and choose a new empty directory if it contains files. A mount hides any existing contents of the directory until you unmount it.
Run sudoedit /etc/fstab. Check whether the file already has an entry for your chosen UUID or path. Use one entry for this mount, replacing YOUR_EXT4_UUID with the value from lsblk.
nofaillets the system continue booting when this data drive is absent. A service with an explicit dependency on the mount can still wait for it.x-systemd.device-timeout=10ssets how long the mount job waits for the device to appear. If a known-good drive takes longer to spin up, increase this value.- The final
2puts the ext4 filesystem in the normal filesystem-check order after the root filesystem.
systemd mount options, fstab fields
3. Check the mount before rebooting¶
Leave the drive connected. If you are converting a manual mount at this path, close its open files and unmount it first so the test uses the new entry. Verify the fstab file, reload systemd, and start only the new mount. systemd-escape translates the path into the corresponding unit name.
Investigate any errors or warnings about the new entry. If it starts, check the exact mount point and compare the reported UUID with the one from step 1. Look for rw in OPTIONS if the drive is intended for writes. Repeat this check after your next reboot.
--mountpoint checks the directory itself. The command returns no match if the drive is absent and the directory is just part of another filesystem. findmnt reference
4. Check the UUID before writing backups or media¶
Run this check immediately before testing a backup or changing an app's storage path. The command succeeds only if the specified filesystem is mounted at that exact path.
If the command returns no match, stop before writing. Once it succeeds, use a subdirectory on the mounted drive for the app's files. Grant access to that subdirectory to the user or service that needs it. An empty mount point can still exist when the drive is absent. A backup script that checks only whether the directory exists can fill the Pi's system disk.
On a Pi 4B running systemd 257, a temporary fstab test produced an optional mount unit with a 10-second device timeout. In an isolated mount test, the UUID check accepted a matching ext4 mount and rejected an empty directory, a different filesystem and an incorrect UUID.
Once the drive is mounted, use your subdirectory as the path for a Samba share or media library.
Troubleshoot or undo the mount¶
If the Pi enters emergency mode after changing fstab, check the failed device or mount from a recovery shell. Recover from an fstab edit
| Symptom | First check |
|---|---|
The drive is missing from lsblk |
Check the cable, enclosure and power. Wait for the drive to initialise, then run lsblk again. |
| The drive is listed but the mount times out | Compare the partition's filesystem UUID with fstab and inspect the mount unit's log. |
| The drive is mounted but the app cannot write | Check for rw, use the app's account, and inspect permissions along the data path. |
| The mount is busy | Close files and shells using the drive and stop services writing to it before unmounting. |
To undo the setup, stop the apps using the drive, then run sudo systemctl stop "$usb_unit" in the same shell. Once the filesystem is unmounted, remove the entry you added and run sudo findmnt --verify --verbose followed by sudo systemctl daemon-reload. Refer to the backup if you need to recover the original entry.