WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Automount USB with UDEV rules, Problem [SOLVED WITH RESTRICTIONS]  (Read 35895 times)

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #30 on: March 03, 2013, 07:14:00 PM »
That should not be the problem. I run a backup of /usr/local/sbin, so the link is persistent....
------------------------------------------------------------
mindmachine

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11629
Re: Automount USB with UDEV rules, Problem
« Reply #31 on: March 03, 2013, 07:38:40 PM »
Hi mindmachine
Since you say:
Code: [Select]
mount /mnt/sdb1works, the only think that comes to mind is the mount point not being created in time. Try changing the
script to this:
Code: [Select]
#!/bin/sh
rebuildfstab
while [ ! -e "/mnt/$1" ] do; sleep 1; done  # Wait for mount point to be created
mount /mnt/$1

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #32 on: March 03, 2013, 08:02:10 PM »
The problem seems another one. If I try to run the mount script from command line, it reports an error like "/mnt/ can't be found in fstab.So it seems, as if $1 isn't accepted as correct term for this. If I drasticalley change the script to mount /mnt/sdb1, it gets mounted flawlessly...
I already tried to increase the sleep thing as this problem also came to my mind, but that did not help. So it's got something to do with that $1 placeholder.

Going to bed now, will try again tomorrow evening.

Thank you and Good night!!
« Last Edit: March 03, 2013, 08:05:49 PM by mindmachine »
------------------------------------------------------------
mindmachine

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11629
Re: Automount USB with UDEV rules, Problem
« Reply #33 on: March 03, 2013, 08:06:48 PM »
Hi mindmachine
You didn't leave a space between  /mnt/  and  $1 , did you?

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #34 on: March 03, 2013, 08:11:15 PM »
No :-).
------------------------------------------------------------
mindmachine

Offline althalus

  • Sr. Member
  • ****
  • Posts: 351
Re: Automount USB with UDEV rules, Problem
« Reply #35 on: March 03, 2013, 08:11:26 PM »
The problem seems another one. If I try to run the mount script from command line, it reports an error like "/mnt/ can't be found in fstab.So it seems, as if $1 isn't accepted as correct term for this. If I drasticalley change the script to mount /mnt/sdb1, it gets mounted flawlessly...
I already tried to increase the sleep thing as this problem also came to my mind, but that did not help. So it's got something to do with that $1 placeholder.

Going to bed now, will try again tomorrow evening.

Thank you and Good night!!
It would be a big help, I think, to copy and paste bits of command line sessions so people can see exact error messages, and the actual command that you ran. Did you include the device name when running the mount script from command line? (That's what the %k in the udev rule does)

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11629
Re: Automount USB with UDEV rules, Problem
« Reply #36 on: March 03, 2013, 08:14:44 PM »
Hi althalus
Excellent points.

@mindmachine: As suggest by althalus, does:
Code: [Select]
xxx sdb1work?

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #37 on: March 03, 2013, 08:20:31 PM »
Yeah, I totally agree, but I do use a very minimalistic install of TC and access the internet from another machine. That would make me write down every input/output instead of copy paste. So please have mercy with me. I could transfer it by USB, if I could, lol!!!

But to make it clear. Something between ntfs-3g and udev doesn't work as expected. So /mnt/$1 (without space inbetween) is not recognized and I get an "mount: can't find /mnt/ in /etc/fstab". $1 is obviously completely ignored. Using ext3 and ext4 filesystems, it works.

Have got to correct me. If I run "sudo sh /foo sdb1" it gets actually mounted. But why the bl**** He** doesn it work by using the script when it is called by 98-udev-rule ???

Another edit (I found the wysiwyg editor now, sorry for the mess in earlier posts, took wrong button for editing, gotten very late yesterday):
By fiddling around with this again, I noticed the following:
Running the usb-mount script in /usr/local/sbin
Quote
#!/bin/sh
rebuildfstab
sleep 3
mount /mnt/$1
and increasing the sleep time also delays creation of fstab. So if I increase up to ten, then a rebuild fstab is available after 10 seconds. So may it be, that the given mount command doesn't find the correct entry in fstab and therefore can't mount an ntfs-drive?
Mount point in fstab is available just after ten seconds then, but there is no entry in mtab, so running
Quote
sudo usb-mount sdb1
does mount sdb1 correctly with rw permission but NOT when called by script. sdb1 again is created in /mnt/ but is, of course, empty.
Would it make sense, to try something like
Quote
KERNEL=="ram*", SUBSYSTEM=="block", GOTO="tc.rules_end"
KERNEL=="loop*", SUBSYSTEM=="block", GOTO="tc.rules_end"
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/sh -c '/usr/sbin/rebuildfstab'", RUN+="/bin/sh -c '/usr/local/sbin/usb-mount %k'"
ACTION=="remove", SUBSYSTEM=="block", RUN+="/bin/sh -c '/usr/local/sbin/usb-umount %k'"
LABEL="tc.rules_end"
and remove the rebuildfstab command from the usb-mount script? Is it possible to run two commands as follw ups in an udev rule?

And what finally drives me completely nuts is, that using the script on ext3 ext4 drives is working as expected.
 
« Last Edit: March 04, 2013, 07:49:20 AM by mindmachine »
------------------------------------------------------------
mindmachine

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #38 on: March 05, 2013, 05:58:16 PM »
Okay I did trace down the problem, but don't find a proper solution, perhaps someone could help.

I split the rebuildfstab-command and the usb-mount command within the udevrule like this:
Quote
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/sh -c '/usr/sbin/rebuildfstab'", RUN+="/bin/sh -c '/usr/local/sbin/usb-mount %k'"
my usb-mount script looks like this:
Quote
while [ ! -e "/mnt/$1" ]
do
sleep 1
done
mount /mnt/$1

Then I used "top" to watch whats happening, when plugging in an USB-Stick. So this is happening (removed PID and stuff):
Quote
/bin/sh -c /usr/local/sbin/usb-mount sdb
{exe} ash /usr/local/sbin/usb-mount sdb
As you can see "%k" from 98-tc-rules does hand over sdb, but not the correct number, so the scripts stays in a loop and drive doesn't get mounted, as there is no "sdb" in fstab, just an "sdb1".

How could this be handled?
------------------------------------------------------------
mindmachine

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #39 on: March 06, 2013, 02:20:16 PM »
%PUSH%  :o
------------------------------------------------------------
mindmachine

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11629
Re: Automount USB with UDEV rules, Problem
« Reply #40 on: March 06, 2013, 03:12:35 PM »
Hi mindmachine
First of all, nice detective work figuring out %k was not returning a partition. A similar problem was noted here, you
might recognize the author:  http://xfce.10915.n7.nabble.com/Help-to-get-automount-working-4-10-td11681.html
He states:
Quote
USB stick used during test is formatted on WINDOWS xp and doesn't have
correct partition table, it is why LINUX is handling it as /dev/sdc.
If you haven't already read it, this may be of some use:
http://forum.tinycorelinux.net/index.php/topic,9037.msg49251.html#msg49251

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #41 on: March 06, 2013, 04:34:47 PM »
Thanks for your reply. It was driving me nuts.
Anyway, the sticks were created by gparted on a Linux machine, still they did not work. Attaching an archos mp3-Player works :-), a simple USB-device does not.

I already tried to use %k%n, as I read somewhere that %n (in spite of being obsolete) would return the correct partition number. That did not work somehow. Script wouldn't work for Vfat stuff, anyway.
Nicking the udev methods and scripts from another distro woulden't be an option? But Tinycore wouldn't be that tiny afterwards anymore, maybe?? :-)

I'll do some more reading, but as far as a quick check brought up, Bela also hasn't found a proper solution yet?
Anyway, now I've got at least some new ideas to work on. As long as we get the correct block device via %k, we might be able to use this information to run a query for the correct number for mounting.

Thanks again!



------------------------------------------------------------
mindmachine

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #42 on: March 06, 2013, 04:42:46 PM »
by the way
Quote
nice detective work
that's my day to day job :-) (Forensics)
------------------------------------------------------------
mindmachine

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11629
Re: Automount USB with UDEV rules, Problem
« Reply #43 on: March 06, 2013, 05:11:54 PM »
Hi mindmachine
Maybe something like this:
Code: [Select]
while [ ! -e "/mnt/$1*" ]
do
sleep 1
done
for i in `ls /mnt/$1[1-9]
sleep 1
do
mount /mnt/$i
done
This is untested and I'm a lousy scripter so some of my syntax may be incorrect. The idea is that when the first loop
finds any entry that begins with $1, it drops down to the second loop which mounts everything that begins with $i.
The extra sleep command is there in case the drive has multiple partitions to allow rebuildfstab to finish finding
everything.

Offline mindmachine

  • Newbie
  • *
  • Posts: 45
Re: Automount USB with UDEV rules, Problem
« Reply #44 on: March 06, 2013, 05:16:27 PM »
I will try this and report, what happened. Excellent idea, though!! I was thinking of something like this, but been more on the UDEV side, but of course, your solution is much more straight forward!
------------------------------------------------------------
mindmachine