Skip to contentSkip to conversation

UDEV Rule for usb/firewire removable storage media

DISCUSSION Roger 1 participant 1 message Jan 21, 2010

lore
Share & tools
lore

Roger

author
#0 lore raw

I'm trying to create a udev rule to simulate gnome-volume-manager as I'm straying away from Gnome with using a slimmer desktop (DWM).

Here's what I have so far that works. (Notice, I snipped some of this from archlinux. ;-)

Any ideas, cleanup suggestions or pointers??

--- Begin UDEV Rule ---

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

# left out sda and sdb devices because those are my system hard drives &
not removable!!!
# Any better ideas??

# UDEV Add/Mount Section
#
# Global mount options
ACTION="add", ENV{mount_options}="relatime,users"
# Filesystem specific options
ACTION="add", PROGRAM="/sbin/blkid -o udev -s LABEL /dev/%k", RESULT="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid0,umask2"

# Find folder partition label or folder usb id name ACTION="add", PROGRAM="/sbin/blkid -o udev -s LABEL /dev/%k", ENV{dir_name}="$env{ID_FS_LABEL}"
ACTION="add", PROGRAM!="/sbin/blkid -o udev -s LABEL /dev/%k", ENV{dir_name}="usbhd-%k"

# Mount the device
# Uncomment to send debug notice to logger
#ACTION="add", RUN+="/usr/bin/logger Adding sd device file" ACTION="add", RUN+="/bin/mkdir -p /media/$env{ID_FS_LABEL}", RUN +="/bin/mount -o $env{mount_options} /dev/%k /media/$env{ID_FS_LABEL}"

# UDEV Remove/Unmount Section
#
# Uncomment to send debug notice to logger #ACTION="remove", ENV{dir_name}="?*", RUN+="/usr/bin/logger Removing and umounting sd device file"

# Find folder partition label or folder usb id name ACTION="remove", PROGRAM="/sbin/blkid -o udev -s LABEL /dev/%k", ENV{dir_name}="$env{ID_FS_LABEL}"
ACTION="remove", PROGRAM!="/sbin/blkid -o udev -s LABEL /dev/%k", ENV{dir_name}="usbhd-%k"

# Umount the device
ACTION="remove", ENV{dir_name}="?*", RUN+="/bin/umount -l /media/% E{dir_name}", RUN+="rmdir /media/%E{dir_name}"

LABEL="media_by_label_auto_mount_end"

--- End of UDEV Rule ---

Signature · 2 lines
Roger
http://rogerx.freeshell.org