Skip to content

Fix USB Drive Permission Denied on Raspberry Pi

If a USB drive is visible but an app cannot write to it, first confirm the drive is mounted where the app expects it. Then check the filesystem type and the account doing the writing. For ext4, check the permissions on the data directory. For exFAT or FAT32, check the owner and modes assigned at mount time.

Check the USB mount and the failed path

Replace /mnt/usb-data with your drive's exact mount point. Use the actual data directory in the second command, or its parent if it could not be created.

1
2
3
# Check which drive is mounted there and inspect each directory in the path.
findmnt --mountpoint /mnt/usb-data -o TARGET,SOURCE,FSTYPE,UUID,OPTIONS
namei -l /mnt/usb-data/my-app
  • No mount row. Check lsblk -o NAME,TRAN,FSTYPE,UUID,MOUNTPOINTS and use the actual mount point. An existing directory can be on the Pi's system disk when the USB drive is absent. Mount a USB drive at boot
  • Mount shows ro. Find out why the mount is read-only before changing permissions. Diagnose a read-only file system
  • Mount shows rw. Use its FSTYPE to choose the next check. For a systemd service, use the service account. For a container, check the process's UID and GID and whether its bind mount is read-only.

On ext4, grant access to the data directory

namei -l shows the owner, group and mode of every component in the path. The account needs search permission (x) on each parent directory, plus write and search permissions (w and x) in the directory where it creates files. Linux path permissions

On the Pi 4B, a temporary ext4 directory at mode 0550 rejected writes from its owner. Mode 0750 allowed them. Removing search permission on its parent blocked writes again, even with the writable directory mode intact.

For a new application, create a dedicated directory owned by the account that will write to it. Replace YOUR_USB_UUID with the verified USB partition UUID and alex with the actual account. Choose an unused directory name.

1
2
3
4
5
6
7
# Create the folder only when the intended USB partition is mounted.
usb_uuid=YOUR_USB_UUID
account=alex
data_dir=/mnt/usb-data/my-app
findmnt --noheadings --mountpoint /mnt/usb-data --source "UUID=$usb_uuid" &&
  sudo mkdir -m 0750 -- "$data_dir" &&
  sudo chown -- "$account:$(id -gn "$account")" "$data_dir"

Test local writes as that account after setup. This creates and removes one uniquely named empty file.

1
2
3
sudo -u "$account" -- sh -c '
  probe=$(mktemp -- "$1/.write-check.XXXXXXXX") && rm -- "$probe"
' sh "$data_dir"

If the test succeeds but the app still fails, check its mount and permissions in the app's own environment. A read-only media library, for example, needs directory search permission and file read permission. Jellyfin USB media library · Samba share permissions

On exFAT or FAT32, set the owner at mount time

Linux assigns ownership and permissions for these filesystems from the mount options. Find the intended account's numeric IDs with id -u alex and id -g alex. For a drive mounted through /etc/fstab, the example below gives the owner write access and the group read access. Substitute your IDs, UUID and mount point. Use vfat as the filesystem type if that is what findmnt reports for your FAT32 drive.

UUID=YOUR_USB_UUID /mnt/usb-data exfat nofail,uid=1000,gid=1000,dmask=0027,fmask=0137 0 0

dmask and fmask remove permission bits from directories and files. Here they give directories mode 0750 and regular files mode 0640. Validate the edited fstab, close applications using the drive, then unmount and mount the intended drive again. Confirm its UUID and options before repeating the write test. Linux exFAT mount options · FAT mount options

Donate