For the record:

I tried to move everything to udev and after some testing it works.

Udev rules for sd* automounting without /etc/fstab:

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usbhd%m", GROUP="users", 
OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usbhdp%n", GROUP="users", 
NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /media/usbhdp%n"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/ln -s /media/usbhdp%n 
/mnt/usbhdp%n"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/vol_id -t %N", 
RESULT=="vfat", RUN+="/bin/mount -t vfat -o 
rw,noauto,sync,dirsync,noexec,nodev,noatime,dmask=000,fmask=111 /dev/%k 
/media/usbhdp%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o 
rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /media/usbhdp%n", 
OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /media/usbhdp%n"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rm -f /mnt/usbhdp%n"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /media/usbhdp%n", 
OPTIONS="last_rule"

I have tested them with my external hd connected via IDE to USB
connector. It's 80 GB with two 30 GB vfat partitions + 20 GB 
reiserfs.

The rules will create (and destroy on removal):
1. /dev/usbhd0 (the sda device) available to all users
2. /dev/usbhdp1-3 (one per partition: sda1, sda2, sda3) also available
for all users
3. mount points for all /dev/usbhdp1-3 devices in /media/usbhdp1-3
4. symlinks from /mnt/usbhdp1-3 to /media/usbhdp1-3 so they will
be available in both /mnt and /media

No /etc/fstab items are needed. 
There are two rules one for vfat partitions with fmask (rw for everybody)
and dmask (rwx for everybody) and second for the rest of filesystems.
I had a lot of problems with detecting vfat partitions from udev but 
finally it worked.

Pmount is not very helpfull because I couldn't setup umask to 000
when it was run as root from udev. Using pmount could save a few rules 
but I would have to create a special user and run it through sudo.

I have also found this usb automounting script package:
http://usbmount.alioth.debian.org/
which is a more configurable and pretty version of the above.


For cdrom (/dev/hdc) I couldn't do much using only udev. AFAIK there
are no hotplug events available to udev that can be used to detect
cd insertion or eject. 

But I wanted to get rid of submount and then I found a tiny
application auto-eject-cdrom:
http://psydev.sourceforge.net/new/auto-eject-cdrom/auto-eject-cdrom-0.2/
I've followed this advice:
http://www.ubuntuforums.org/showthread.php?t=52548&page=3&pp=10
and made a quick pkgbuild:

pkgname=auto-eject-cdrom
pkgver=0.2
pkgrel=1
pkgdesc="Ejects cdrom and mounts/umounts it when you press eject button/insert 
new cd"
url="http://psydev.sourceforge.net/new/auto-eject-cdrom";
depends=('eject')
source=(http://psydev.sourceforge.net/new/$pkgname/$pkgname-$pkgver/$pkgname.c \
http://psydev.sourceforge.net/new/$pkgname/$pkgname-$pkgver/Makefile)
md5sums=('2db638621d1db9e67953acd026060274' '9fcc4e65448455d8a0201dc180fb44fd')

build() {
        cd $startdir/src
    sed -i "76s#umount#eject#" ./$pkgname.c
    make || return 1
    install -D -m755 $pkgname $startdir/pkg/usr/bin/$pkgname
}

umount is replaced with eject and then it works: umounts and ejects
when eject button is pressed or closes and mounts it when you
insert a new cd and press eject.

You can run it from /etc/rc.local for example:
auto-eject-cdrom /dev/hdc &

In /etc/fstab I only left this for /dev/hdc:
/dev/hdc        /mnt/cd     auto        
ro,users,noauto,unhide,iocharset=iso8859-2 0 0

and in my custom udev rules I've put:
BUS=="ide", KERNEL=="hdc", SYSFS{removable}=="1", PROGRAM="/bin/cat 
/proc/ide/%k/media", RESULT=="cdrom*", NAME="%k", GROUP="users", 
SYMLINK+="cdrom cd cdrw dvd dvdrw", OPTIONS="last_rule"

so all users have access to /dev/hdc.

Everything seems to work so far :-)

-- 
Rafal Szczepaniak (Lanrat)

_______________________________________________
arch mailing list
[email protected]
http://www.archlinux.org/mailman/listinfo/arch

Reply via email to