You are not logged in.

#1 2008-08-30 01:52:26

ltpl4y3r
Member
Registered: 2008-08-23
Posts: 28

udev automounting for usb drives

I am using the howto from the wiki to setup udev rules, so that my usb drives automount to /media/.

I have run into a snag though. My ipod shuffles and one of my thumbdrives go to /dev/sdc (with no number). But, the udev rules are looking for them to have numbers. I was wondering if there was a way to alter the current rules to also automount those devices that only have the main partition.

My ruleset:

KERNEL=="sd[c-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/mkdir -p /medimediasb%n"
ACTION=="add", KERNEL=="sd[c-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 /media/usb%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usb%n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[c-z][0-9]", RUN+="/bin/umount -l /media/usb%n"
ACTION=="remove", KERNEL=="sd[c-z][0-9]", RUN+="/bin/rmdir /media/usb%n", OPTIONS="last_rule"

Thanks!

FYI: Wiki Page

Offline

#2 2008-09-04 02:34:19

ltpl4y3r
Member
Registered: 2008-08-23
Posts: 28

Re: udev automounting for usb drives

Ok, I've been chipping away at this slowly, and this is what I've come up with, thus far:

#Custom USB Mounting
#KERNEL=="sd[c-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z]*", SYMLINK+="usbdisk-%n", GROUP="users", NAME="%k
ACTION=="add", KERNEL=="sd[c-z]*", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="%N: uknown volume type", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z]*", RUN+="/bin/mkdir -p /media/%k"
ACTION=="add", KERNEL=="sd[c-z]*", PROGRAM=="/lib/udev/vol_id -t %N", RESULT=="vfat", RUN+="/bin/mount -t vfat -o rw,noauto,flush,quiet,nodev,nosuid,noexec,noatime,gid=95,dmask=000,fmask=111 /dev/%k /media/%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[c-z]*", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime,gid=95 /dev/%k /media/%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[c-z]*", RUN+="/bin/umount -l /media/%k"
ACTION=="remove", KERNEL=="sd[c-z]*", RUN+="/bin/rmdir /media/%k", OPTIONS="last_rule"

label="custom_usb"

This now mounts my drives that only show up as /dev/sdc, but it also mounts the drives that do /dev/sdc and /dev/sdc1. The only problem is, that for some reason ACTION=="add" line #2 does not keep unknown partitions from making a directory in /media. It doesn't hurt anything, and maybe I just have the extra unmounted directory in /media.

Something else I changed, was adding gid=95. This made it usable to the storage group. I thought that it should have been taken care of with the first ACTION=="add" line.

Any ideas?

Minor quirks, but seems to be working fine.

I only have one thumbdrive that is problematic with mounting the extra /media spot, so I think it just require a good formatting.

Offline

#3 2008-09-04 15:15:04

dante4d
Member
From: Czech Republic
Registered: 2007-04-14
Posts: 176

Re: udev automounting for usb drives

I think that device sd? without sd?1 isn't correctly partitioned, or is it? All my usb pens have sd?1 on them, I never tried making filesystem on the physical device itself. I don't know, but at least, if you want to make special rule for one particular device, try this:

I mount my usb devices using this rule:

KERNEL=="sd?1", ATTRS{vendor}=="Corsair", ATTRS{model}=="Flash Voyager", NAME="%k", SYMLINK+="voyager"
ACTION=="add", KERNEL=="sd?1", ATTRS{vendor}=="Corsair", ATTRS{model}=="Flash Voyager", RUN+="/bin/mkdir /mnt/voyager"
ACTION=="add", KERNEL=="sd?1", ATTRS{vendor}=="Corsair", ATTRS{model}=="Flash Voyager", RUN+="/bin/mount -t vfat -o sync,flush,uid=1000,gid=100 /dev/voyager /mnt/voyager"
ACTION=="remove", KERNEL=="sd?1", ENV{ID_VENDOR}=="Corsair", ENV{ID_MODEL}="Flash_Voyager", RUN+="/bin/umount /mnt/voyager"
ACTION=="remove", KERNEL=="sd?1", ENV{ID_VENDOR}=="Corsair", ENV{ID_MODEL}="Flash_Voyager", RUN+="/bin/rmdir /mnt/voyager"

KERNEL=="sd?1", ATTRS{vendor}=="WD", ATTRS{model}=="1600BEV External", NAME="%k", SYMLINK+="passport"
ACTION=="add", KERNEL=="sd?1", ATTRS{vendor}=="WD", ATTRS{model}=="1600BEV External", RUN+="/bin/mkdir /mnt/passport"
ACTION=="add", KERNEL=="sd?1", ATTRS{vendor}=="WD", ATTRS{model}=="1600BEV External", RUN+="/bin/mount -t vfat -o sync,flush,uid=1000,gid=100 /dev/passport /mnt/passport"
ACTION=="remove", KERNEL=="sd?1", ENV{ID_VENDOR}=="WD", ENV{ID_MODEL}="1600BEV_External", RUN+="/bin/umount /mnt/passport"
ACTION=="remove", KERNEL=="sd?1", ENV{ID_VENDOR}=="WD", ENV{ID_MODEL}="1600BEV_External", RUN+="/bin/rmdir /mnt/passport"

I execute these actions based on device name - ATTRS{vendor}=="Corsair", ATTRS{model}=="Flash Voyager".
I used Writing udev rules guide, which explains how can you find devices properties and what udev events are triggered by plugging in usb pens for example.
Similary, you can use this approach for the problematic device and keep old match pattern sd[c-z][0-9] for other devices.

Offline

Board footer

Powered by FluxBB