You are not logged in.

#1 2010-01-25 23:13:47

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Udev still recommended?

Hello guys,

what's the right way to have access to removable devices such as usb devices since udev seems not to work in the way I was used to as it is written in the wiki down here?

I'm using dwm with simply coreutils in xterm and for some cases vifm as a term-based filemanager. So there's no way to do it with hal and a gui-based filemanager.

So my question, is udev still the right thing to handle this task or are there any other perhaps better solutions?

Best regards. smile

Last edited by orschiro (2010-01-25 23:14:27)

Offline

#2 2010-01-25 23:28:25

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 785
Website

Re: Udev still recommended?

I use autofs[1]. My system is mainly console apps. Works well for me.

[1] http://wiki.archlinux.org/index.php/Autofs

Offline

#3 2010-01-25 23:31:55

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Udev still recommended?

not sure if there's a /right/ way to do it.  i use the udev rule and it works great for me (i have a small script to create/remove that rules file to give automounting an (on|off) ability).

are you having problems with this method, or just asking about best practices?

if it's about best practices, i'm sure plenty of people here would simply say "mount /dev/sd..." tongue

Offline

#4 2010-01-26 07:30:25

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

Hello guys,

I use autofs[1]. My system is mainly console apps. Works well for me.

That goes in the right direction. But as far as I can see, I still have to determine the exact /dev/-path to a device, so it's not a real universal solution as long as I won't mention /dev/sdb1 to /dev/sdx in the config file.

are you having problems with this method, or just asking about best practices?

No I'm just asking because I think they won't write such a warning in the wiki when there's no reason to do that.

Offline

#5 2010-01-26 07:55:49

Runiq
Member
From: Germany
Registered: 2008-10-29
Posts: 1,053

Re: Udev still recommended?

Since you're using some suckless.org stuff, have you considered using skvm?

Offline

#6 2010-01-26 07:57:02

lustikus
Member
Registered: 2009-11-10
Posts: 262

Re: Udev still recommended?

you might want to try skvm  http://tools.suckless.org/skvm
I use it and it works quite well.

Offline

#7 2010-01-26 08:11:55

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,837

Re: Udev still recommended?

orschiro wrote:

No I'm just asking because I think they won't write such a warning in the wiki when there's no reason to do that.

Always remember that the wiki is written by the community, and it's possible that "they" made a mistake, or that the information "they" provided is no longer valid. Run 'locate vol_id' on your system and you will find that it still exists - it's part of the klibc-udev package.

Feel free to edit the wiki as required.

Offline

#8 2010-01-26 08:32:43

mikesd
Member
From: Australia
Registered: 2008-02-01
Posts: 785
Website

Re: Udev still recommended?

orschiro wrote:

Hello guys,

I use autofs[1]. My system is mainly console apps. Works well for me.

That goes in the right direction. But as far as I can see, I still have to determine the exact /dev/-path to a device, so it's not a real universal solution as long as I won't mention /dev/sdb1 to /dev/sdx in the config file.

True. I use /dev/disk/by-uuid and this works for me as I only want known devices to auto mount. I dabble in data recovery and don't want a random usb device auto mounted on my workstation before I can image it. Too much of a chance the file system will be written to.

An actual volume manager like skvm might suit you better. skvm was discussed on the forums[1] in the past.

[1] http://bbs.archlinux.org/viewtopic.php?id=68945

Offline

#9 2010-01-26 22:00:39

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

Thank you all for your answers. A volume manager such as skvm indeed seems to be the tool I was looking for. But just some basic question to better understand how skvm or a volume manager in general is working:

1) Mounting with user access instead of root ist working I guess?

2) How does unmounting work? Can I simply disconnect my usb/removable device or cd/dvd or do I have to manually unmount it? Even though there was write access onto the device?

3) Is it possible to mount luks-encrypted removable usb devices?

4) And finally can I remove udev or is it still needed by any other application?

Last edited by orschiro (2010-01-26 23:23:49)

Offline

#10 2010-01-26 23:33:57

harryNID
Member
From: P3X-1971
Registered: 2009-06-12
Posts: 117

Re: Udev still recommended?

Hi all,

orschiro
I use that rule too and after everything started borking up I ran across the warning message from the wiki page you posted. Well I was bound and determined to get it working again so I cobbled this together. It's not perfect and I found out that I had to change the naming scheme as the old naming scheme wouldn't work correctly. This seems to be working for me maybe it will work for you too.

Your drives should mount like this now:

/mnt/usbsda1/
/mnt/usbsda2/
etc.

I only cobbled the "/mnt" version so if you want the one symlinked to "/media" you'll have to do your homework but it shouldn't be bad. Just use the original version and sub the new parts from my rule. See note below before you proceed!

mkdir -p /etc/udev/rules.d/01.usbdrive_automount.rules

KERNEL=="sd[a-z]", NAME="%k", SYMLINK+="usb%k", GROUP="users", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", SYMLINK+="usb%k", GROUP="users", NAME="%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mkdir -p /mnt/usb%k"
ACTION=="add", KERNEL=="sd[a-z][0-9]", PROGRAM=="/sbin/blkid -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%k", OPTIONS="last_rule"
ACTION=="add", KERNEL=="sd[a-z][0-9]", RUN+="/bin/mount -t auto -o rw,noauto,async,noexec,nodev,noatime /dev/%k /mnt/usb%k", OPTIONS="last_rule"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/umount -l /mnt/usb%k"
ACTION=="remove", KERNEL=="sd[a-z][0-9]", RUN+="/bin/rmdir /mnt/usb%k", OPTIONS="last_rule"

Hope it works for you!!  Drop a line if you try it and it works for you.

Note: After actually checking the wiki page again it seems as if the rules were changed recently. What I cobbled together uses the rule that was previously on that page. As this indeed works for me I don't know how it will work for you. I guess the only way is to try. Also don't forget to restart udev after adding this.


In solving a problem of this sort, the grand thing is to be able to reason backward. That is a very useful accomplishment, and a very easy one, but people do not practice it much. In the everyday affairs of life it is more useful to reason forward, and so the other comes to be neglected. There are fifty who can reason synthetically for one who can reason analytically.  --Sherlock Holmes

Offline

#11 2010-01-27 07:30:18

lustikus
Member
Registered: 2009-11-10
Posts: 262

Re: Udev still recommended?

harryNID wrote:

Hope it works for you!!  Drop a line if you try it and it works for you.

Note: After actually checking the wiki page again it seems as if the rules were changed recently. What I cobbled together uses the rule that was previously on that page. As this indeed works for me I don't know how it will work for you. I guess the only way is to try. Also don't forget to restart udev after adding this.

I tried it and it works for one of my usb sticks, but not for the other and not for my sd card reader either.

Offline

#12 2010-01-27 10:34:26

xduugu
Member
Registered: 2008-10-16
Posts: 280

Re: Udev still recommended?

I guess the warning in the wiki is due to mkinitcpio 0.6 which will remove all the klibc-* stuff. Basically, you have to replace /.../vol_id with /sbin/blkid.

For example, my updated udev file (mount to /media, use label if available, luks support) looks like this now:

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid %N", GOTO="media_by_label_auto_mount_end"

# Open luks partition if necessary
PROGRAM=="/sbin/blkid -o value -s TYPE %N", RESULT=="crypto_LUKS", ENV{crypto}="mapper/", ENV{device}="/dev/mapper/%k"
ENV{crypto}!="?*", ENV{device}="%N"
ACTION=="add", ENV{crypto}=="?*", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /usr/sbin/cryptsetup luksOpen %N %k'"
ACTION=="add", ENV{crypto}=="?*", TEST!="/dev/mapper/%k", GOTO="media_by_label_auto_mount_end"

# Global mount options
ACTION=="add", ENV{mount_options}="noatime,users"
# Filesystem specific options
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s TYPE %E{device}", RESULT=="vfat|ntfs", ENV{mount_options}="%E{mount_options},utf8,gid=100,umask=002"

# Get label
ACTION=="add", PROGRAM=="/sbin/blkid -o value -s LABEL %E{device}", ENV{dir_name}="%c"
# use basename to correctly handle labels such as ../mnt/foo
ACTION=="add", PROGRAM=="/usr/bin/basename '%E{dir_name}'", ENV{dir_name}="%c"
ACTION=="add", ENV{dir_name}!="?*", ENV{dir_name}="usbhd-%k"

ACTION=="add", ENV{dir_name}=="?*", RUN+="/bin/mkdir -p '/media/%E{dir_name}'", RUN+="/bin/mount -o %E{mount_options} /dev/%E{crypto}%k '/media/%E{dir_name}'"
ACTION=="remove", ENV{dir_name}=="?*", RUN+="/bin/umount -l '/media/%E{dir_name}'", RUN+="/bin/rmdir '/media/%E{dir_name}'"
ACTION=="remove", ENV{crypto}=="?*", RUN+="/usr/sbin/cryptsetup luksClose %k"
LABEL="media_by_label_auto_mount_end"

However, I'm not sure if I should use blkid's cache or not (-p flag)...

edit:
Changelog
20100303
removed blkid's -p flag as it makes blkid always return the return code 0 even if there is no filesystem on that specifiy device / partition.

20100205
updated rules set. see http://bbs.archlinux.org/viewtopic.php? … 73#p702773

Last edited by xduugu (2010-03-03 10:07:00)

Offline

#13 2010-01-27 10:54:16

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

Hello xduugu,

nice rule you created there. Is this also working with sd-cards or just with usb devices?

When I want to have sync-support then I could easily add it to 'ACTION=="add", ENV{mount_options}="noatime,users"'?

Last edited by orschiro (2010-01-27 10:58:18)

Offline

#14 2010-01-27 11:08:08

xduugu
Member
Registered: 2008-10-16
Posts: 280

Re: Udev still recommended?

orschiro wrote:

nice rule you created there. Is this also working with sd-cards or just with usb devices?

Maybe. It works for my internal card reader (block files are also called sd[a-z]*), but according to the wiki, sd cards might be named mmcblk[0-9]p[0-9]. The latter naming scheme is currently not supported.

orschiro wrote:

When I want to have sync-support then I could easily add it to 'ACTION=="add", ENV{mount_options}="noatime,users"'?

Yeah, simply add your options there.

Last edited by xduugu (2010-01-27 11:12:56)

Offline

#15 2010-01-27 13:52:27

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

Allright I'll give it a try.

Eventually just one question. When I don't use the sync option, then I can't simply disconnect removable devices but have to unmount them manually with "umount ..."?

Offline

#16 2010-01-27 19:09:14

xduugu
Member
Registered: 2008-10-16
Posts: 280

Re: Udev still recommended?

I usually run "sync" before unplugging the device when I've written data to it. No perfect solution, but still one command less than when using pmount. wink
Umount should work,too, but has to be run as root and I think the directory in /media will not be removed because the udev rules also tries to umount the device which will obviously fail.

Offline

#17 2010-01-27 19:34:10

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

Hello xduugu,

haven't known that running "sync" is already enough. Great thank you for that. Your rule is working perfectly, even with my encrypted usb-hdd.

One last thing. How could I achieve to automatically mount my cdrom/dvd-device when a cd/dvd is inserted? Is that also done with udev?

I simply want to have it automatically mounted to /media as everything else and when I push the eject button to be ejected directly without unmounting it.

Last edited by orschiro (2010-01-27 19:34:50)

Offline

#18 2010-01-28 08:45:24

xduugu
Member
Registered: 2008-10-16
Posts: 280

Re: Udev still recommended?

orschiro wrote:

One last thing. How could I achieve to automatically mount my cdrom/dvd-device when a cd/dvd is inserted? Is that also done with udev?

I simply want to have it automatically mounted to /media as everything else and when I push the eject button to be ejected directly without unmounting it.

I'm not sure about this, because I do not know if udev can differentiate between an empty cd drive and a loaded one. If it is able to, the automount part would work. I am, however, pretty sure you cannot use the eject button while a cd is mounted. Unfortunately, I cannot help you with this since I do not own an optical drive (optical drives are sooo 2000 smile )

Offline

#19 2010-01-28 10:40:53

lustikus
Member
Registered: 2009-11-10
Posts: 262

Re: Udev still recommended?

thanks for sharing your rules, xduugu.
I tried them both on my desktop and laptop and they are working fine, sd card reader included.

Offline

#20 2010-01-28 15:29:22

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

I'm not sure about this, because I do not know if udev can differentiate between an empty cd drive and a loaded one. If it is able to, the automount part would work. I am, however, pretty sure you cannot use the eject button while a cd is mounted. Unfortunately, I cannot help you with this since I do not own an optical drive (optical drives are sooo 2000  )

Unfortunately it still happens that I get disks instead of removable drives with some necessary data on it. Or just think of films and music. wink

Well so I won't come around to use a volume manager for this task? Or perhaps just a right configured hal?

Anyway can autofs be considered as a volume manager?

Last edited by orschiro (2010-01-28 16:01:12)

Offline

#21 2010-01-28 17:17:39

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Udev still recommended?

orschiro wrote:

Unfortunately it still happens that I get disks instead of removable drives with some necessary data on it

I don't know about anyone else, but i don't do any mounting of optical media (CD/DVDs).  by pointing whatever program i'm using to /dev/sr0 everything works fine.

if it's a data disc ofcourse i have to mount /dev/sr0 /media/whatever to get at the files themselves, but for cda's or dvd's i just use /dev/sr0 directly.  works with mplayer, abcde, etc no problem.

Offline

#22 2010-01-29 11:12:02

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Udev still recommended?

if it's a data disc ofcourse i have to mount /dev/sr0 /media/whatever to get at the files themselves, but for cda's or dvd's i just use /dev/sr0 directly.  works with mplayer, abcde, etc no problem.

You're right. That's working flawlessly. Well and for mounting there's obviously no other way than using a volume manager. thank you all for your response.

Offline

#23 2010-01-30 21:58:12

mif86
Member
Registered: 2008-01-27
Posts: 16

Re: Udev still recommended?

This rule is working nicely, however it allows for exploitation by setting a malicious label. for instance LABEL="; rm -rf / ;"

Offline

#24 2010-01-31 00:40:39

xduugu
Member
Registered: 2008-10-16
Posts: 280

Re: Udev still recommended?

Did you actually manage to exploit this? Just tried "; /bin/rm -f /a" and it did not remove the file a in root. However, mounting does not work either. If this is really an issue it should also be fixed on the wiki page where it originally comes from.

/e:

I tried
e2label /dev/sdb1 '; rm -f /a ;'
e2label /dev/sdb1 '; /bin/rm -f /a'
e2label /dev/sdb1 '; /bin/rm -f /a;'
e2label /dev/sdb1 'a; /bin/rm -f /a'
e2label /dev/sdb1 'a; rm -f /a'

None of these worked.

I think it's the same as for

echo a; echo b

vs.

test='a; echo b'
echo $test

Last edited by xduugu (2010-01-31 00:50:04)

Offline

#25 2010-01-31 00:46:30

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Udev still recommended?

a label like "; /bin/rm -f /a" might do it.

logically it should work; as i read it, udev (as root) would run:

RUN+="/bin/mkdir -p /media/; /bin/rm -f /a"

i'm not getting concerned or anything, but it /should/ execute the rm right?

Offline

Board footer

Powered by FluxBB