Title: usb_flash_Drive automount Subject: Howto Make udev rule for automounting usb flash drive # I am using gentoo, so I had to install a few things: emerge udev dbus hal # Next I had to add a custom udev rule that comes before other rules cat >> /etc/udev/rules.d/10-local.rules <<'EOF' ######################################################################## # usb flash drive # creates/remove /media/usb-* mount point, # mounts /dev/sd[a-z][0-9] as user=ivman, group=plugdev # unmounts when media is removed ################### # By default, give mountpoint a generic name (i.e. usb-sda1, usb-sdb1, etc ) ACTION=="add", KERNEL=="sd[a-z][0-9]", ENV{mountpoint}="usb-%k" # Re-assign mountpoint to filesystem label if it isn't blank ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -l %N", RESULT!="", ENV{mountpoint}="usb-%c" # I'm really not sure what this is for... need to check ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="$env{mountpoint}", GROUP="users", MODE="0000", NAME="%k" # Make the mount point ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p --mode 000 /media/$env{mountpoint}" ################### # Two way so mount # 1.If filesystem is vfat, mount with one set of options # If filesystem is other, mount with different set of options #ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,quiet,nodev,nosuid,noexec,noatime,dmask=000,f #ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/$env{mountpoint}", OPTIONS="last_rule" # 2. Just mount everything with pmount ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/usr/bin/sudo -u ivman /usr/bin/pmount -w -u 000 /dev/%k /media/$env{mountpoint}" ################### # Change ownership ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/chmod -R 777 /media/$env{mountpoint}" ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/chown -R ivman:plugdev /media/$env{mountpoint}", OPTIONS="last_rule" ################### # When device is removed, unmount and delete mountpoint ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/$env{mountpoint}" ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/$env{mountpoint}", OPTIONS="last_rule" EOF # # NOTE: After adding a udev rule, one does not need to restart udev #