Debian – Automount USB drives with no GUI requirement (halevt replacement)

automountingdebianlinuxmountusb

For minimal installations of Debian, I have been using halevt to enable automounting of USB drives. Halevt is reliable and requires no configuration aside from installing the package. Now, halevt has been removed from Debian Testing and I'm looking for a replacement, but none of the alternatives seem to be as straightforward.

What utility for automounting USB drives would be the most lightweight, simple, and stable?

EDIT: I was never able to get udev working the way I wanted. The problem is that udev rules are always run as root, so media are mounted as root. It is possible to hard-code mounting as a specific user, but it seems you can't make a rule that mounts as current user. According to the documentation, it should be possible with the MODE value, but it doesn't seem to be implemented in Debian. So, if automounting is required, I still have to use halevt. Otherwise, I use pmount.

Best Answer

The disk-based features of HAL were replaced by udev and udisks.

There is a full example of how to use udev to do this on the Automounting UDisks wrappers page:

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

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

# Import FS infos
IMPORT{program}="/sbin/blkid -o udev -p %N"

# Get a label if present, otherwise specify one
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"

# Global mount options
ACTION=="add", ENV{mount_options}="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"

For more information about udev:

There are also a few options based on udisks that would be the new equivalent of halevt:

I couldn't find any of those in the testing repository, so you might have to find a third-party apt repository, or follow their instructions to compile the software on your own machine.

Related Question