automount working

Yay, automounting now works. I no longer have to manually mount my usb stick every time now that udev has the rules to take care of it. Actually found the rules here: http://forums.gentoo.org/viewtopic-t-720401.html. The rules are below, plus comments of my own understanding of the code.

# Example udev rules for automounting usb volumes. Pulled from
# http://forums.gentoo.org/viewtopic-t-720401-highlight-automount.html
# To be placed in /etc/udev/rules.d/

# Match the mounted volume
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"

# Add the volume
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"

# Create the mount point
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n"

# Some udev magic runs this mount command if vfat is detected, else it falls
# through to the next rule, which tries to autodetect the fstype
ACTION=="add", KERNEL=="sd[b-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,dmask=000,fmask=111 /dev/%k /mnt/usb%n", OPTIONS="last_rule"

# Mount the volume
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /mnt/usb%n", OPTIONS="last_rule"

# Rules for umounting volume
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n"

# Clean up
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"

I just put the rules in place, plugged in my usb stick, and there it was, automounted on /mnt/usb1.

I’m running fluxbox and the setup is coming together pretty nicely now. Next that would be nice to have is suspend working, though shutdown and bootup are really so nice and quick that I could do without it.

Advertisements