You are not logged in.
/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.
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
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
A general question, which are the steps i have to follow if i want to change hal with udev?
Offline
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
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...
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/... .
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.
Offline
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.
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
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.
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
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).
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
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
/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
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
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
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
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
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
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
Any ideas for me?
Offline
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
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
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
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
I'm a big fan of this udev rule, but I have one small problem.
Thanks.
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
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
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
Create a new thread for the question. This thread title does not make people think help is needed here.
Offline
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