Auto-mount using udev

I have an entry for my new shiny USB drive in /etc/fstab. But I like my USB drive to auto-mount when it is plugged in (and unmount when appropriate). Here comes udev.

In /etc/udev/rules.d/50-usb.rules:

SUBSYSTEM=="block", DEVTYPE=="disk", DEVNAME=="/dev/", ACTION=="add", RUN+="/bin/mount -a"
SUBSYSTEM=="block", DEVTYPE=="disk", DEVNAME=="/dev/", ACTION=="remove", RUN+="/bin/umount /dev/%k"

To list the environment variables available for matching in udev, use udevadm monitor --environment

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s