Got this tricks from Arch guy somewhere on the internet. I did this thing because the default KDE shipped with Slackware does not do the automount job well, at least on my machine. This tricks uses udev. Here is my addition of udev rule:

bowo@pcxthinkslack:~$ cat /etc/udev/rules.d/10-my-media-automount.rules
# /etc/udev/rules.d/10-my-media-automount.rules

# start at sdb to ignore the system hard drive
KERNEL!="sd[c-z]*", GOTO="my_media_automount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"

# import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"

# get the label if present, otherwise assign one based on device/partition
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="%k"

# create the dir in /media and symlink it to /mnt
ACTION=="add", RUN+="/bin/mkdir -p '/media/%E{dir_name}'"
# create a symbolic link to /media/{usb_folder} on desktop
ACTION=="add", RUN+="/bin/ln -s '/media/%E{dir_name}' '/home/bowo/Desktop/%E{dir_name}'"

# global mount options
ACTION=="add", ENV{mount_options}="relatime"
# filesystem-specific mount options (777/666 dir/file perms for ntfs/vfat)
ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},gid=100,dmask=000,fmask=111,utf8"

# automount ntfs filesystems using ntfs-3g driver
ACTION=="add", ENV{ID_FS_TYPE}=="ntfs", RUN+="/bin/mount -t ntfs-3g -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"
# automount all other filesystems
ACTION=="add", ENV{ID_FS_TYPE}!="ntfs", RUN+="/bin/mount -t auto -o %E{mount_options} /dev/%k '/media/%E{dir_name}'"

#remove the symbolic link to ~/{usb_folder}
ACTION=="remove", RUN+="/bin/rm -rf '/home/bowo/Desktop/%E{dir_name}'"
# clean up after device removal
ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"

# exit
LABEL="my_media_automount_end"

(I’m to lazy too describe it in more human readable sentence :D ) This rules will also create a symlink to device mount point on my Desktop which is quite usefull if you use folder view on your Desktop. As a bonus, I’ve created also a rules that will set the symlink icon to usb-removable-media. Here is the rules and the bash script:

root@pcxthinkslack:/home/bowo/Build/tp_acpi# egrep -v '^#|^$' /etc/udev/rules.d/81-create-usb-icon.rules
KERNEL!="sd[c-g]*", GOTO="my_media_automount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="my_media_automount_end"
IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
ENV{ID_FS_LABEL}=="", ENV{dir_name}="%k"
ACTION=="add", RUN+="/home/bowo/Apps/create-usb-icon.sh '%E{dir_name}'"
LABEL="my_media_automount_end"
root@pcxthinkslack:/home/bowo/Build/tp_acpi# cat /home/bowo/Apps/create-usb-icon.sh
#!/bin/bash
/usr/bin/echo  "[Desktop Entry]" > "/home/bowo/Desktop/$1/.directory"
/usr/bin/echo  "Icon=drive-removable-media-usb" >> "/home/bowo/Desktop/$1/.directory"

=-=-=-=-=
Powered by Blogilo