Mounting USB Drive on BeagleBone

I am using angstrom, console only, kernel 3.2.5

When I plug in a USB drive it shows up as /dev/sda1. But it does not get auto-mounted.

If I change my /etc/fstab file to add this line:

/dev/sda1 /media/usbdrive vfat auto,umask=0 0 0

I have also tried:
/dev/sda1 /media/usbdrive defaults 0 0

It works fine. But if I remove the USB drive and try to reboot I get all sorts of errors. Including the “Welcome to emergency mode” message.

So what is the right way to get this to mount when a USB drive is plugged in?

A udev rule or udisks rule.

E.g. https://github.com/openembedded/meta-oe/blob/master/meta-oe/recipes-core/udev/udev-extra-rules/automount.rules combined with https://github.com/openembedded/meta-oe/blob/master/meta-oe/recipes-core/udev/udev-extra-rules/mount.sh

Although it does not appear to be as elaborate as Koen’s solution I made a new file called:

/etc/udev/rules.d/media-by-label-auto-mount.rules

with this content in it:

`

Start at sdb to avoid system harddrive.

KERNEL!=“sd[a-z][0-9]”, GOTO=“media_by_label_auto_mount_end”

Import FS infos

IMPORT{program}="/sbin/blkid -o udev -p %N"

Create a label

ENV{dir_name}=“usbhd-%k”

Global mount options

ACTION==“add”, ENV{mount_options}=“defaults,relatime”

Filesystem-specific mount options

ACTION==“add”, ENV{ID_FS_TYPE}==“vfat|ntfs”, ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"

Mount the device

ACTION==“add”, RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"

Clean up after removal

ACTION==“remove”, ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"

Exit

LABEL=“media_by_label_auto_mount_end”

`

This seems to work.

Much thanks goes to this website: https://wiki.archlinux.org/index.php/Udev#Auto_mounting_USB_devices