This rule works under Karmic.
Code:
SUBSYSTEM=="usb", KERNEL=="sd??", ACTION=="add", PROGRAM="/usr/local/bin/USB %k"
Little did I realize there's a great man page on udev and writing rules. And of course, if you haven't seen it, this is just about the only other comprehensive resource available.
Also, might I suggest:
...a simpler way to get the UUID of a drive? If $1 is a device file, such as /dev/sda1, then:
Code:
blkid $1 | sed -n 's/.*UUID=\"\([0-9a-z\-]*\)\".*/\1/p'
Would return the UUID without worrying about parsing ls.
You can also have udev mount the drive for you rather than waiting for HAL to do it. I use the following rule to mount all my removable media (since I don't use HAL at all).
Code:
KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_only_auto_mount_end"
ACTION=="add", PROGRAM!="/lib/initcpio/udev/vol_id --label %N", GOTO="media_by_label_only_auto_mount_end"
ACTION=="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}"
# Global mount options
ACTION=="add", ENV{mount_options}="relatime,users"
# Filesystem specific options
ACTION=="add", PROGRAM=="/lib/initcpio/udev/vol_id -t %N", RESULT=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,uid=1000,gid=1000,umask=002"
ACTION=="add", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"
ACTION=="remove", ENV{ID_FS_LABEL}=="?*", RUN+="/bin/umount -l /media/$env{ID_FS_LABEL}", RUN+="/bin/rmdir /media/$env{ID_FS_LABEL}"
LABEL="media_by_label_only_auto_mount_end"
Mind you, Ubuntu no longer carries vol_id by default.
Bookmarks