You are not logged in.
Pages: 1
Hello,
Until just a few hours ago, when I plugged my external hard drive in I had to run a script to mount it with sudo, as I couldn't get it automounted. Then I saw a workaround in some thread over here, using the udev rules proposed at the bottom of the Udev wiki article.
After a reboot, and after some hours I didn't remember I had created that rule, so I went to konsole and run my script, which returned "Disc not found". That's because it checks there is that device under /dev/disk/by-label/. As I checked afterwards, the disk was automounted on some directory under /media, but it there were no symlinks to it nor to my pendrive under /dev/disk. This is a problem as my script did something like "mount /dev/disk/by-label/$LABEL /mnt/$LABEL", and Amarok's collection is under there, so if I change the collection directory every time I reboot (or every time I plug the disk) it might be mounted on a different directory (current one is /media/usbhd-sdb1), depending on the order I plug the usb storage devices, or even random if more than one is plugged on boot (not sure about this).
I suppose this is because when I plug the disk (or pendrive) udev applies the first rule it finds, so I think a possible workaround for my problem is to change the mount directory on the udev rule. And here is where my question comes: I see NAME="%k" and then %k used as the device name under /dev (in this case sdb1). Could I use some variable to keep the label of the disk and then mount it on /mnt/$LABEL, for example? I think this way I couldn't automount any device without label, but every pendrive I've seen is labeled by default so that wouldn't be a problem.
Thank you for reading that bible, and thank you again if you answer
Bye!
Edit: maybe this thread should be under Kernel & Hardware. If so, please move it
Last edited by Surgat_ (2008-09-02 23:52:47)
Offline
Well, I have been looking through the udev manpage (which I can't find in my system, I can't understand why) and I think I need something like "$attr{file}, %s{file}", from which I can get some attribute found at the device, but I still don't know how to get the label of the partition. Any ideas?
Thank you.
Offline
I think what you were looking for may have been $env{ID_FS_LABEL}. I've got the following as my udev rules for getting automatically mounted drives with the mountpoint set to the partition label instead of just a number. Not particularly robust when there are two partitions with the same label, but I haven't gotten around to writing a fix for it yet. If it works for you, maybe we should put it on the wiki.
KERNEL=="sd[b-z]", NAME="%k", SYMLINK+="usb%m", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", SYMLINK+="usb%n", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%n"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/ln -s /mnt/usb%n /media/$env{ID_FS_LABEL}"
ACTION=="add", KERNEL=="sd[b-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 /mnt/usb%n", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[b-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,sync,dirsync,noexec,nodev,noatime /dev/%k /mnt/usb%n", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/umount -l /mnt/usb%n"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rm /media/$env{ID_FS_LABEL}"
ACTION=="remove", KERNEL=="sd[b-z][0-9]", RUN+="/bin/rmdir /mnt/usb%n", OPTIONS="last_rule"
Offline
That's what I was looking for! Thank you!
Offline
In that case, what happens if you don't have a label?
Also, can somebody tell me what advantes I would have using fstab rules only, udev rules only, or both combined? What would you guys suggest to do?
Offline
Pages: 1