You are not logged in.

#1 2010-03-05 00:37:56

shefla
Member
From: France
Registered: 2010-03-05
Posts: 19

[SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

SOLUTION SUMMARY:

   - Using gdm
          GDM will grant you necessary rights when logging

   - Without using GDM
          The following line must be in your .xinit.rc file
                    exec ck-launch-session gnome-session
          The "ck-launch-session" command will grant you necessary rights

For more explanation regarding "ck-launch-session" command, follow this link :
          http://www.freedesktop.org/wiki/Software/ConsoleKit

------------------------------------------------------------------

Hi,

Please find below a description of my problem with UDEV and unmounting usb drive.

Explanation

I have added a rule to UDEV in order to have my USB drive automounted when I plug it.
The auto mount work fine from a normal user session.

The problem is : I am unable to unmount my usb drive from a normal user session.

In Gnome with a normal user, right click on the drive then "Unmount"
          --> Unable to unmount 4.0 GB Filesystem
                Not Authorized

In Gnome with a normal user, right click on the drive then "Eject"
          --> Unable to eject 4.0 GB Filesystem
                Failed to eject media; one or more volumes on the media are busy.

In Gnome with a normal user, right click on the drive then "Safely Remove Drive"
          --> Unable to stop drive
                Failed to eject media; one or more volumes on the media are busy.

In Gnome with the "Disk Utility" tool with a normal user
          --> Error unmounting device
                Permission denied.
                Not Authorized

In a terminal with a normal user, "umount /dev/sdb1"
          --> umount: /dev/sdb1 is not in the fstab (and you are not root)

If I execute the above command as root, it is working fine, my drive is properly unmounted.


Some information

uname -a --> Linux myhost 2.6.32-ARCH #1 SMP PREEMPT Tue Feb 23 19:24:08 UTC 2010 i686 Intel(R) Pentium(R) D CPU 2.80GHz GenuineIntel GNU/Linux

Gnome 2.28.2

udevd --version --> 151

lsusb --> Bus 002 Device 004: ID 054c:0243 Sony Corp. MicroVault Flash Drive

mount --> /dev/sdb1 on /media/usbhd-sdb1 type vfat (rw,noexec,nosuid,nodev,noatime,utf8,gid=100,umask=002)

grep shefla /etc/group --> lp:x:7:daemon,shefla
                                       video:x:91:shefla
                                       audio:x:92:shefla
                                       optical:x:93:shefla,hal
                                       storage:x:95:shefla,hal
                                       power:x:98:shefla

"/etc/udev/rules.d/11-media-by-label-auto-mount.rules" file I have created for automount.
          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'"
          =="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"

Question

Thanks you for having read this explanation.

Could you please let me know how a normal user can unmount an usb driver automatically mounted by udev ?
Do you think there is a way to unmount it for gnome (graphical way) ?

Thanks

Shefla

Last edited by shefla (2010-03-15 18:01:00)

Offline

#2 2010-03-11 13:40:55

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

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Or put another way...

Can udev mount as user?

Offline

#3 2010-03-11 17:18:42

Painless
Member
Registered: 2006-02-06
Posts: 233

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Out of interest, what is the output from:

ls -l /dev/sdb1

and

ls -l /media

?

Offline

#4 2010-03-11 19:11:08

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

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

$ ls -l /media
drwxrwxr-x 12 root users  16K Jan  1  1970 CENTRIOS
$ ls -l /dev/sdb1 
brw-rw---- 1 root disk 8, 17 Mar 11 19:07 /dev/sdb1
$ groups
tty disk wheel cron video audio optical storage camera users vboxusers

Relevant thread: Udev still recommended?, of which I (and probably the OP) use this Udev rule.

Offline

#5 2010-03-12 10:06:27

fabertawe
Member
From: Lloegr
Registered: 2009-11-24
Posts: 279

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Something odd's recently happened here...

I started using a Udev rule as I couldn't get any joy with USB drives under Gnome. The other day I started fiddling with it to see if I could fix the unable to unmount as you're not root problem and ended up commenting the whole thing out. Now USB mounting/unmounting works perfectly!

Can anyone explain that?! wink


Ryzen 9 5950X, X570S Aorus Pro AX, RX 6600, Arch x86_64

Offline

#6 2010-03-12 15:28:54

Painless
Member
Registered: 2006-02-06
Posts: 233

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Well I was actually asking shefla, but never mind.  smile   I can unmount USB drives without any problems, so FWIW here is my output:

$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
...
udev                     10240       276      9964   3% /dev
...
/dev/sdb1              1968636   1542020    426616  79% /media/5D6F-2040
$ ls -l /dev/sdb1
brw-rw---- 1 root storage 8, 17 Mar 12 15:24 /dev/sdb1
$ ls -l /media
...
drwx------ 5 rob  rob  4096 Jan  1  1970 5D6F-2040

Offline

#7 2010-03-12 16:47:39

anonymous_user
Member
Registered: 2009-08-28
Posts: 3,059

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Im having the same problem but with Thunar. The message it gives when trying to unmount is "The volume "Linux" was probably mounted manually on the command line."

$ ls -l /media
...
drwxr-xr-x 11 kevin kevin 4096 Jan 30 10:02 Linux
drwxrwxr-x  1 root  users 4096 Mar 12 08:44 Windows

Offline

#8 2010-03-13 01:16:40

shefla
Member
From: France
Registered: 2010-03-05
Posts: 19

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Hi Painless, Hi everybody,

Sorry to haven't answered yet, my job didn't let me a lot of free time.
This weekend I have more time to look at this issue.

Please find below requested info.

[shefla@myhost ~]$ ls -l /dev/sdb1
brw-rw---- 1 root disk 8, 17 Mar 13 02:02 /dev/sdb1

[shefla@myhost ~]$ ls -l /media
total 16
drwxr-xr-x 2 root root  4096 Feb 26 05:56 cd
drwxr-xr-x 2 root root  4096 Feb 26 05:56 dvd
drwxr-xr-x 2 root root  4096 Feb 26 05:56 fl
drwxrwxr-x 5 root users 4096 Mar 13 02:03 usbhd-sdb1

[shefla@myhost ~]$ groups
lp video audio optical storage scanner power users

[shefla@myhost ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
...
udev                   10M  452K  9.6M   5% /dev
...
/dev/sdb1             3.8G  525M  3.3G  14% /media/usbhd-sdb1

When I log through GDM then the problem does not exists anymore. Everything is fine.
It seem GDM "automatically give some rights" for the session.

When I am not using GDM (I directly start gnome-session), then I am unable to mount or unmount flash drive.
To be able to do it, I have to add the above udev rule file.

Do somebody know which rights / permissions / ... are granted by gdm when logging ?

Thanks and regards

Last edited by shefla (2010-03-15 17:27:35)

Offline

#9 2010-03-13 20:53:27

Painless
Member
Registered: 2006-02-06
Posts: 233

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

How do you start gnome-session from startx/.xinitrc?  Try using:

exec ck-launch-session gnome-session

Offline

#10 2010-03-14 02:40:00

shefla
Member
From: France
Registered: 2010-03-05
Posts: 19

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Hi Painless,

I was using

exec gnome-session

I have tested with

exec ck-launch-session gnome-session

It works great.

I feel a little bit stupid when I see a so simple answer ...
Anyway thanks.

2 last questions before closing this topic :
What does the "ck-launch-session" do exactly ?
Could this be risky from a security point of view ? (I think it is not more risky than using gdm, I just want to confirm this)

Thanks for your help

Regards

Shefla

Offline

#11 2010-03-15 16:58:57

Painless
Member
Registered: 2006-02-06
Posts: 233

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

"ck-launch-session" is part of the ConsoleKit package.  Not sure how it ties in with udev, though  smile

Offline

#12 2010-03-15 17:42:10

shefla
Member
From: France
Registered: 2010-03-05
Posts: 19

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Hi Painless,

I have quickly read some parts of this website earlier, but I didn't find the answer I expected.
I will try to read carefully the doc when I will have some time to spent to it.

Anyway, many thanks for your help. I close this thread.

Shefla

Offline

#13 2010-03-15 17:48:18

kgas
Member
From: Qatar
Registered: 2008-11-08
Posts: 718

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

pcmanfm also complains about the devices mounted thro' udev rules and won't get unmounted. If you take care about the files saving etc just unplug the device.

Offline

#14 2010-03-15 17:56:22

shefla
Member
From: France
Registered: 2010-03-05
Posts: 19

Re: [SOLVED] Unable to unmount USB drive (automatically mounted with UDEV)

Agreed Kgas,

This is a quite old school but safe method when you take care of the writing operation.

But I prefer a clean solution because my girl friend also use this machine, and I am pretty sure she will be confused if she does not found the Unmount menu.

Anyway thanks for your help.

Regards

Shefla

Offline

Board footer

Powered by FluxBB