You are not logged in.

#26 2010-01-31 00:50:48

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

Re: Udev still recommended?

xduugu wrote:

/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

/e:
I guess it does not work because a command (mount?) fails before it can run rm.

Quoting %E{dir_name} can produce funny results though. smile
e2label /dev/sdb1 'b; /bin/rm -f /a'

$ ls -1d /media/**
/media/
/media/b_
/media/b_ /bin
/media/b_ /bin/rm -f
/media/b_ /bin/rm -f /a
/media/b_ /bin/rm -f /a/lost+found

Last edited by xduugu (2010-01-31 01:07:21)

Offline

#27 2010-01-31 02:09:47

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

Re: Udev still recommended?

I didn't try that, i just assumed it would work. but what I actually tried was "../blabla", and i guess that can be used to unmount/remove already existing mount points or folders. for instance "../mnt/whatever" will unmount and delete that directory.
BTW, i'm referring to xduugu's udev rules

Last edited by mif86 (2010-01-31 02:11:53)

Offline

#28 2010-01-31 03:21:58

n0dix
Member
Registered: 2009-09-22
Posts: 956

Re: Udev still recommended?

A general question, which are the steps i have to follow if i want to change hal with udev?

Offline

#29 2010-01-31 05:54:54

skottish
Forum Fellow
From: Here
Registered: 2006-06-16
Posts: 7,942

Re: Udev still recommended?

That's a nice set of rules xduugu. I had some trouble setting things up right before and this setup seems to working well. This is a good thing because it allowed me to finally dump pcmanfm in favor of vifm.

Offline

#30 2010-02-03 19:55:14

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

Re: Udev still recommended?

mif86 wrote:

I didn't try that, i just assumed it would work. but what I actually tried was "../blabla", and i guess that can be used to unmount/remove already existing mount points or folders. for instance "../mnt/whatever" will unmount and delete that directory.
BTW, i'm referring to xduugu's udev rules

Maybe unmounting will work. I guess this cannot be fixed by just quoting the label variable, so it would be necessary to apply basename to the label...


n0dix wrote:

A general question, which are the steps i have to follow if i want to change hal with udev?

E.g. for xorg-server you can use xorg-server-udev. But it really depends on your installed software if it's possible to completely replace hal with udev/udisks/... .


skottish wrote:

That's a nice set of rules xduugu. I had some trouble setting things up right before and this setup seems to working well. This is a good thing because it allowed me to finally dump pcmanfm in favor of vifm.

Glad you like it. wink

Offline

#31 2010-02-05 04:10:24

s3kt0r
Member
Registered: 2009-01-20
Posts: 208

Re: Udev still recommended?

Thanks for opening this thread. I created a file /etc/udev/rules.d/01.usbstuff_automount.rules, and copied xduugu's rules (thanks a lot, like skottish was, I'm looking to dump pcmanfm), and it works ok, but I think I may have made  some mistake. Whenever I connect my usbhdd (ntfs), it doesn't give me write permissions, only read. Any thoughts?

Edit: Sorry, I figured it out. My user wasn't part of 'users' group (gid=100). Dumped pcmanfm. big_smile

Last edited by s3kt0r (2010-02-05 04:18:27)


box1: Arch (linux-3.17-rc5)
box2: Gentoo (linux-3.17-rc5)
wm: subtle

Offline

#32 2010-02-05 22:30:32

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

Re: Udev still recommended?

Hello xduugu,

I have a question regarding your udev-rule especially with the use of encrypted devices.
When I plug in my external drive xterm opens with the message Enter passphrase for /dev/.tmp-block-8:16:
But I have to type in the passphrase three times until it will be accepted and I always used definitely the right password.
After that I will be asked again but this time for .tmp-block-8:17 and not 16. Is that normal behaviour?
Here my complete output.

Enter passphrase for /dev/.tmp-block-8:16: 
No key available with this passphrase.
Enter passphrase for /dev/.tmp-block-8:16: 
No key available with this passphrase.
Enter passphrase for /dev/.tmp-block-8:17:

Thank you. smile

EDIT:

And I noticed also the problem that not every usb pen drive is going to be mounted automatically due to your udev rule. Did you notice something similiar or is really every stick automatically mounted on your system?

Last edited by orschiro (2010-02-05 23:33:59)

Offline

#33 2010-02-05 23:34:47

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

Re: Udev still recommended?

orschiro wrote:

When I plug in my external drive xterm opens with the message Enter passphrase for /dev/.tmp-block-8:16:
But I have to type in the passphrase three times until it will be accepted and I always used definitely the right password.

Are you sure it succeeds? You have three tries to enter the correct password before the cryptsetup command fails. My guess is that you do not have all the required modules loaded (maybe one could parse the luks header and load these automatically).

orschiro wrote:

After that I will be asked again but this time for .tmp-block-8:17 and not 16. Is that normal behaviour?

I could not reproduce this (entered a wrong password three times). Maybe you plugged in a device containing two encrypted partitions?

Unfortunately, I could not get it to work without the temporary device name, but you can change

ACTION=="add", ENV{crypto}=="?*", PROGRAM=="/usr/bin/xterm -display :0.0 -e '/usr/sbin/cryptsetup luksOpen %N %k'"

to

ACTION=="add", ENV{crypto}=="?*", PROGRAM=="/usr/bin/xterm -display :0.0 -e 'echo Password for /dev/%k; /usr/sbin/cryptsetup luksOpen %N %k'"

to get a bit more information.

Offline

#34 2010-02-05 23:58:41

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

Re: Udev still recommended?

Hm to bring this in a right order. I just plugged in my drive. The xterm window appears and waits for the passphrase. fdisk -l as root shows the following. fdisk -l as normal user shows nothing:

[root@thinkpad bin]# fdisk -l

Platte /dev/sda: 250.1 GByte, 250059350016 Byte
255 Köpfe, 63 Sektoren/Spur, 30401 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk identifier: 0xcff304d6

   Gerät  boot.     Anfang        Ende     Blöcke   Id  System
/dev/sda1   *           1          12       96358+  83  Linux
/dev/sda2              13       30401   244099642+  83  Linux

Platte /dev/dm-0: 250.0 GByte, 249955965440 Byte
255 Köpfe, 63 Sektoren/Spur, 30388 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/dm-0 enthält keine gültige Partitionstabelle

Platte /dev/dm-1: 10.7 GByte, 10737418240 Byte
255 Köpfe, 63 Sektoren/Spur, 1305 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/dm-1 enthält keine gültige Partitionstabelle

Platte /dev/dm-2: 3221 MByte, 3221225472 Byte
255 Köpfe, 63 Sektoren/Spur, 391 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/dm-2 enthält keine gültige Partitionstabelle

Platte /dev/dm-3: 236.0 GByte, 235996708864 Byte
255 Köpfe, 63 Sektoren/Spur, 28691 Zylinder
Einheiten = Zylinder von 16065 × 512 = 8225280 Bytes
Sector size (logical/physical): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Festplatte /dev/dm-3 enthält keine gültige Partitionstabelle

/dev/sda is my internal drive, my external always used to be /dev/sdb but now it is apparently /dev/dm*. Why that?

The output is in german language, if something isn't obvious please ask.

And to answer your questions:

Are you sure it succeeds? You have three tries to enter the correct password before the cryptsetup command fails. My guess is that you do not have all the required modules loaded (maybe one could parse the luks header and load these automatically).

Yeah it succeeds. I'm typing the passphrase three times for first .temp and then once for the second with the result that it will be mounted correctly with the label to /media/label.

I could not reproduce this (entered a wrong password three times). Maybe you plugged in a device containing two encrypted partitions?

The passphrase was definitely correct, no doubt. And originally I just encrypted one partition.

Last edited by orschiro (2010-02-06 00:01:39)

Offline

#35 2010-02-06 01:13:57

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

Re: Udev still recommended?

orschiro wrote:

/dev/sda is my internal drive, my external always used to be /dev/sdb but now it is apparently /dev/dm*. Why that?

That's due to an udev rule of device-mapper (/lib/udev/rules.d/10-dm.rules) and it's the same for me.

The different behavior might come from the fact that you encrypted the whole device whereas I only encrypted a single partition. I'll check this, but you could also try to reproduce your issue when using only an encrypted partition.

Offline

#36 2010-02-06 01:26:17

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

Re: Udev still recommended?

mif86 wrote:

I didn't try that, i just assumed it would work. but what I actually tried was "../blabla", and i guess that can be used to unmount/remove already existing mount points or folders. for instance "../mnt/whatever" will unmount and delete that directory.
BTW, i'm referring to xduugu's udev rules

Finally, I gave it a trial and was able to mount to /mnt when I set the label to '../mnt/foo'. I dunno if it's possible to unmount other mount points, but it's nasty in either case.

So I went ahead and improved the rules set:
- quoted label variable
- only use the result of basename as folder name

Thanks mif86 for pointing out.

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

# Open luks partition if necessary
PROGRAM=="/sbin/blkid -o value -p -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 -p -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 -p -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"

Offline

#37 2010-02-08 08:55:13

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

Re: Udev still recommended?

Hello xduugu,

I tried your latest rule and my problem with LUKS had substantiated.

The first three times he is asking the passphrase for /dev/sdb. But only the third will be accepted.

After that he is asking once the passphrase for /dev/sdb1 and then mounts it successfully. What do you think, could you improve your rule that it handles also complete encrypted devices or should I just encrypt one partition in order to solve that problem?

Best regards

Offline

#38 2010-02-08 15:34:29

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

Re: Udev still recommended?

I'm still pretty sure that you did not manage to open the first container. Just check the content of /dev/mapper and there will be no symlink named sdb.


I tested two possible setups of an encrypted device:

1.

cryptsetup luksFormat /dev/sdb
cryptsetup luksOpen /dev/sdb sdb
mkfs.ext2 /dev/mapper/sdb
cryptsetup luksClose sdb

Works as expected. There is just /dev/sdb as there is no partition involved. One xterm window, one password.

2.

dd count=1 bs=1M if=/dev/zero of=/dev/sdb
cryptsetup luksFormat /dev/sdb
cfdisk /dev/sdb
<create partition>
cryptsetup luksFormat /dev/sdb1
mkfs.ext2 /dev/mapper/sdb1
cryptsetup luksClose sdb1

Now, both sdb and sdb1 have a luks header but only sdb1 actually contains data. This setup seems fairly weird to me since the partition table is also unencrypted as in the first setup. For this setup, two xterm windows appear (there are two luks headers) and I have to enter two passwords which may differ. One for /dev/sdb to open the empty container and one for the partition that actually contains my data. This behavior is odd (just as the device setup), but the udev rule works as intended.

Your setup seems to be the latter one (run blkid /dev/sdb* to verify). In that case, there is nothing I can do. Replacing

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"

with

KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"

would solve your issue but file systems e.g. on /dev/sdb will not be mounted automatically anymore (I've seen this only once so far). Of course, your other option is to correct your setup.

Offline

#39 2010-02-08 19:36:33

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

Re: Udev still recommended?

Hello xduugu,

I adapted my partition configuration and encrypted only /dev/sdb1. Now it is working fine with just one passphrase for the partition.

Thank you for your help. smile

Offline

#40 2010-02-19 00:05:17

gladstone
Member
Registered: 2009-01-03
Posts: 74

Re: Udev still recommended?

Can udev mount as user?

$ls /media
drwxrwxr-x 2 root users 2.0K Jan  1  1970 usbhd-sdb

It prevents Thunar from unmounting:

The volume "Music Player" was probably mounted manually on the command line.

Offline

#41 2010-02-19 01:55:50

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

Re: Udev still recommended?

I don't know anything about Thunar, but according to this site it uses hal for mounting. Thus I suppose the issue is that hal cannot unmount devices that were not mounted by hal itself. But that's just a guess. Maybe ask the thunar/xfce guys or open a new thread so that others will find your post.

Offline

#42 2010-03-01 18:47:34

jrs
Member
Registered: 2009-12-03
Posts: 23

Re: Udev still recommended?

With this thread I have come very far.. only mounting luks partitions doesn't work. It doesn't happen anything..

/dev/sdc1: LABEL="ntfs" UUID="010BCFBB34A7745D" TYPE="ntfs" 
/dev/sdc2: UUID="f05fd741-08d2-4e87-8a4c-06d48a76bf28" TYPE="crypto_LUKS" 
/dev/sdc4: UUID="44094827-9829-4fa4-8cd7-a4db41a3622d" TYPE="crypto_LUKS"
KERNEL!="sd[a-z][1-9]", GOTO="media_by_label_auto_mount_end"
ACTION=="add", PROGRAM!="/sbin/blkid -p %N", GOTO="media_by_label_auto_mount_end"

# Open luks partition if necessary
PROGRAM=="/sbin/blkid -o value -p -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"
...

The ntfs partition is mounted by this rule, the luks partitions do not open. The xterm window doesn't open either. As far as I can see everything should work, but it won't sad
Any ideas for me?

Offline

#43 2010-03-01 22:26:02

Wodzu
Member
Registered: 2009-01-25
Posts: 1

Re: Udev still recommended?

gladstone wrote:

Can udev mount as user?

$ls /media
drwxrwxr-x 2 root users 2.0K Jan  1  1970 usbhd-sdb

It prevents Thunar from unmounting:

The volume "Music Player" was probably mounted manually on the command line.

Doe anyone have solution for this?

Offline

#44 2010-03-03 10:11:50

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

Re: Udev still recommended?

jrs wrote:

With this thread I have come very far.. only mounting luks partitions doesn't work. It doesn't happen anything..

The ntfs partition is mounted by this rule, the luks partitions do not open. The xterm window doesn't open either. As far as I can see everything should work, but it won't sad
Any ideas for me?

I suppose running these commands by hand works? You could run "udevadm monitor", maybe there is something suspicious.

Edit: Forgot to add that I fixed a small bug in the rules (removed the -p flag from all the blkid commands). The updated ones can be found in this thread and in the wiki.

Last edited by xduugu (2010-03-03 10:17:11)

Offline

#45 2010-03-07 17:11:02

Devcon
Member
Registered: 2010-03-07
Posts: 9

Re: Udev still recommended?

I'm a big fan of this udev rule, but I have one small problem.  Is there a way to force it not to mount certain devices?  It remounts my system partitions to /media.  So while it works beautifully for all usb drives i've tried, it is also mounting my boot, home, and system partition which are all obviously already mounted at boot.

Thanks

Last edited by Devcon (2010-03-07 17:11:24)

Offline

#46 2010-03-07 18:56:15

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

Re: Udev still recommended?

Devcon wrote:

I'm a big fan of this udev rule, but I have one small problem.

Thanks.

Devcon wrote:

Is there a way to force it not to mount certain devices?  It remounts my system partitions to /media.  So while it works beautifully for all usb drives i've tried, it is also mounting my boot, home, and system partition which are all obviously already mounted at boot.

I wonder why this does not also happen to me. But yes, it definitely possible to exclude particular devices (see the first line for example). The easiest solution would be to change the first line

KERNEL!="sd[a-z]*", GOTO="media_by_label_auto_mount_end"

to

KERNEL!="sd[b-z]*", GOTO="media_by_label_auto_mount_end"

in case you have only one internal hard-drive and that is labeled as /dev/sda.

Offline

#47 2010-03-07 20:31:02

Devcon
Member
Registered: 2010-03-07
Posts: 9

Re: Udev still recommended?

Nice.  Works perfectly now.  Wrote a quick unmount script, and now everything works seamlessly with midnight commander.

Also, I'm using Gentoo, so perhaps something in my configuration is the reason for the different behavior.

Thanks again

Last edited by Devcon (2010-03-07 20:32:27)

Offline

#48 2010-03-11 01:55:40

EpicRag
Member
From: Lisbon/Beja, Portugal
Registered: 2008-09-01
Posts: 8

Re: Udev still recommended?

Wodzu wrote:
gladstone wrote:

Can udev mount as user?

$ls /media
drwxrwxr-x 2 root users 2.0K Jan  1  1970 usbhd-sdb

It prevents Thunar from unmounting:

The volume "Music Player" was probably mounted manually on the command line.

Doe anyone have solution for this?

Anyone?

Offline

#49 2010-03-11 01:57:32

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,400
Website

Re: Udev still recommended?

Create a new thread for the question.  This thread title does not make people think help is needed here.

Offline

#50 2010-04-14 11:26:50

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

Re: Udev still recommended?

I've updated the ruleset to fix a nasty bug that bit me yesterday. If e.g. /media/usbhd-sda1 exists and you boot your system, /dev/sda1 was mounted by this udev rule which led to an fsck error ("/dev/sda1 is mounted.") in my case.

Offline

Board footer

Powered by FluxBB