Raspberry Pi 2, Auto-Mounting USB
February 25, 2015
Identify the drive, in this case it's /dev/sda1
with a UUID of E033-1109
and type FAT:
sudo blkid
# /dev/sda1: LABEL="ELEMENTS" UUID="E033-1109" TYPE="vfat"
Create a dir it will be mounted at:
sudo mkdir /mnt/usbel
Own it:
sudo chown -R pi:pi /mnt/usbel
You could manually mount it
sudo mount -o uid=pi -o gid=pi -t vfat /dev/sda1 /mnt/usbel
But let's auto-mount it instead:
sudo vim /etc/fstab
Add add the following line to the bottom, it should all be on one line:
UUID=E033-1109 /mnt/usbel vfat auto,users,rw,uid=1000,gid=100,umask=0002 0 0
```
We're mounting the drive by its UUID to ensure we always get the correct drive. We're setting `rw` to allow read-write permissions, `uid=1000` sets the user to "pi" (see the `id` command), `gid=100` sets the group to "users" (again, see the `id` command) and `umask=0002` sets `rwxrwxr-x` permissions on the mount.
_For more details on the possible permissions, see [What is umask](http://www.cyberciti.biz/tips/understanding-linux-unix-umask-value-usage.html) and [fstab permissions explained](http://www.omaroid.com/fstab-permission-masks-explained/)._
We can reapply our mounts with `sudo mount -a` before we `sudo reboot`.
I had issues where this just wouldn't mount on reboot. I'd have to `sudo mount -a` manually. I found a [few](http://www.raspberrypi.org/forums/viewtopic.php?p=690531) [different](https://github.com/raspberrypi/linux/issues/824) [threads](https://bugs.launchpad.net/ubuntu/+source/util-linux/+bug/367782) where Raspberry Pi 2 users were encountering the same issues, which seems to be caused by a bug in Linux/Debian. A permanent fix will apparently be in Debian's "Jessie" release, but until then adding a _delay_ works to give the USB drive to initialise:
```
sudo vi /mount/cmdline.txt
```
Add to the end (others report `5` works, but I needed to up it to `10`):
```
rootdelay=10
```