Skip to content

Instantly share code, notes, and snippets.

@ianfinch
Created February 19, 2020 17:41
Show Gist options
  • Save ianfinch/bea6b96856de10579e43e6707ad386e9 to your computer and use it in GitHub Desktop.
Save ianfinch/bea6b96856de10579e43e6707ad386e9 to your computer and use it in GitHub Desktop.
Add a USB drive to a Raspberry Pi (Raspbian)
Find USB device ...
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Feb 9 01:26 093F-C00F -> ../../sda1
lrwxrwxrwx 1 root root 15 Feb 9 01:26 2ab3f8e1-7dc6-43f5-b0db-dd8364731d4e -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 15 Feb 9 01:26 5203-D7B4 -> ../../mmcblk0p1
The one we are looking for is "/sda"
Now create a mount point ...
$ sudo mkdir /media/usb
$ sudo chown -R <USER>:<GROUP> /media/usb
And now manually mount the drive ...
$ sudo mount /dev/sda1 /media/usb -o uid=<USER>,gid=<GROUP>
This will mount the drive so that the specified ordinary user can write to it. Omitting the
"-o uid=<USER>,gid=<GROUP>" would only allow root to write.
To unmount ...
$ umount /media/usb
To set up automount, need to add this line to /etc/fstab ...
UUID=093F-C00F /media/usb vfat auto,nofail,noatime,users,rw,uid=<USER>,gid=<GROUP> 0 0
The UUID value needs to match the one from the initial "ls" command, the "nofail" option allows the boot
process to proceed if the drive is not plugged in. The "noatime" option stops the file access time being
updated every time a file is read from the USB stick (improves performance).
To unmount a drive added via automount, need to use sudo ...
$ sudo umount /media/usb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment