automounting usb flash drives on linux with udev and pmount

by Martin Monperrus

Here is a solution for automounting usb flash drives / memory sticks on linux using only udev and pmount.

1. add a file automount.rules in /etc/udev/rules.d.

2. put the following lines in it
# automounting usb flash drives
# umask is used to allow every user to write on the stick
# we use --sync in order to enable physical removing of mounted memory sticks -- this is OK for fat-based sticks
# I don't automount sda since in my system this is the internal hard drive
# depending on your hardware config, usb sticks might be other devices than sdb*
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"
3. reload the udev rules: udevadm control --reload-rules

The main advantages of this approach are:
* your system doesn't require dbus/hal/udisks/devicekit which are difficult to configure and error prone;
* you do not have to set root suid on pmount;
* you do not have to create and use a plugdev group and add users to it.

Tagged as: