Tiny Core Linux

General TC => General TC Talk => Topic started by: MadCat on May 15, 2011, 11:15:26 AM

Title: Automount USB rules.d Query
Post by: MadCat on May 15, 2011, 11:15:26 AM
Hello. I am currently trying to automatically have USB Devices automounted using rules under the rules.d folder. I have currently tried making a automount.rules (Which I read from another website) and adding the following below to it. But, I take this wont work because Tiny Core does not come with pmount?

# automounting usb flash drives
# umask is used to allow every user to write on the stick
# we use --sync in order to enable physical removing of mounted memory sticks -- this is OK for fat-based sticks
# I don't automount sda since in my system this is the internal hard drive
# depending on your hardware config, usb sticks might be other devices than sdb*
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 16, 2011, 09:08:56 AM
Anybody out there?
Title: Re: Automount USB rules.d Query
Post by: Guy on May 16, 2011, 09:24:38 AM
I am not completely sure what you are trying to do, but

To mount usb drives at startup, add mount commands to /opt/bootlocal.sh.
Title: Re: Automount USB rules.d Query
Post by: Rich on May 16, 2011, 09:30:41 AM
Hi MadCat
I'm not versed in writing udev rules but if the rules you have listed are correct then changing
pmount and pumount to mount and umount should make it work.
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 16, 2011, 11:33:08 AM
I am not completely sure what you are trying to do, but

To mount usb drives at startup, add mount commands to /opt/bootlocal.sh.

Im trying to get it that when you plug in a USB Device it automounts the device without having to restart Tiny Core, or am I totally on the wrong track here? :/
Title: Re: Automount USB rules.d Query
Post by: Rich on May 16, 2011, 12:03:53 PM
Hi MadCat
I got what you are trying to do, if my previous suggestion does not work, here is a post that goes
into some details of udev rules.

http://forum.tinycorelinux.net/index.php?topic=9037.msg49115#msg49115
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 16, 2011, 12:42:40 PM
Unfortunately that is only for startup "Which works btw". But I need to figure out how to get it to mount WITHOUT having to restart the terminal first. Any ideas?
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 17, 2011, 05:12:09 AM
*Bump*
Title: Re: Automount USB rules.d Query
Post by: Juanito on May 17, 2011, 05:39:59 AM
Did you try substituting mount for pmount and umount for pumount in this?

Code: [Select]
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 17, 2011, 07:47:14 AM
Did you try substituting mount for pmount and umount for pumount in this?

Code: [Select]
ACTION=="add",KERNEL=="sdb*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdb*", RUN+="/usr/bin/pumount %k"
ACTION=="add",KERNEL=="sdc*", RUN+="/usr/bin/pmount --sync --umask 000 %k"
ACTION=="remove", KERNEL=="sdc*", RUN+="/usr/bin/pumount %k"

Unfortunately doing it THAT way does not work. And mount/umount is sitting under /bin/mount and /bin/umount I believe. Not /usr/bin/mount and /usr/bin/umount. Eitherway, that only works if u plug in a Flash Drive and startup the terminal. Im needing a solution so that when I plug in Flash Drives while the terminal is on it auto mounts them without me having to mount /mnt/bla bla
Title: Re: Automount USB rules.d Query
Post by: Rich on May 17, 2011, 09:29:42 AM
Hi MadCat
As I said, I'm not versed in udev rules, but try this.

ACTION=="add",KERNEL=="sd[b-z][0-9]", RUN+="sudo /bin/mount --sync /dev/%k mnt/%k"
ACTION=="remove", KERNEL=="sd*", RUN+="bin/umount -l %k"

Then open a terminal and enter this  udevadm control --reload-rules
Plug in a memory stick and see if it is accessible under /mnt

This presumes that you have an internal drive labeled  sda  and wish to exclude it from hot plugging.
If that's not the case then  sd[b-z][0-9]  should be  sd[a-z][0-9]
Title: Re: Automount USB rules.d Query
Post by: bmarkus on May 17, 2011, 02:56:48 PM
Check 98-tc.rules in /etc/udev/rules.d

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'"
ACTION=="remove",   SUBSYSTEM=="block",   RUN+="/bin/sh -c '/usr/sbin/rebuildfstab'"
LABEL="tc.rules_end"

This rule handles block device add and remove executing rebuildfstab. Look like a good starting point.

Replace it with a new rule set:

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/local/sbin/xxx %k'"
ACTION=="remove",   SUBSYSTEM=="block",   RUN+="/bin/sh -c '/usr/local/sbin/yyy %k'"
LABEL="tc.rules_end"

Here we are calling two shell scripts. Do not forget to reload rules with

Quote
sudo udevadm control --reload-rules

Now, the related scripts.

xxx is mounting partition after rebuildfstab:

Quote
#!/bin/sh
rebuildfstab
sleep 3
mount /dev/$1 /mnt/$1

yyy is executing umount and removes the mounting directory in /mnt:

Quote
#!/bin/sh
umount /mnt/$1
sleep 1
rmdir /mnt/$1
rebuildfstab

sleep commands are for safety, maybe it can be removed or delay changed-

Try, it works. Simple, isn't it ?
Title: Re: Automount USB rules.d Query
Post by: tinypoodle on May 17, 2011, 04:02:30 PM
And mount/umount is sitting under /bin/mount and /bin/umount I believe. Not /usr/bin/mount and /usr/bin/umount.

Have you considered symlinking?
Title: Re: Automount USB rules.d Query
Post by: tinypoodle on May 17, 2011, 04:05:58 PM
When you plan to automount USB flash drives, have you also planned for the case of filesystems being unclean?

Which filesystem types do you plan to automount?
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 19, 2011, 12:13:00 AM
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/local/sbin/xxx %k'"
ACTION=="remove",   SUBSYSTEM=="block",   RUN+="/bin/sh -c '/usr/local/sbin/yyy %k'"
LABEL="tc.rules_end"

Done so. Created 2 files called xxx.sh and yyy.sh in /usr/local/sbin as it was required. So now my 98-tc.rules basically looks like the following below.

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/local/sbin/xxx.sh %k'"
ACTION=="remove",   SUBSYSTEM=="block",   RUN+="/bin/sh -c '/usr/local/sbin/yyy.sh %k'"
LABEL="tc.rules_end"


Quote
sudo udevadm control --reload-rules

Then added the following to the 2 files

Quote
xxx.sh

#!/bin/sh
rebuildfstab
sleep 3
mount /dev/$1 /mnt/$1

yyy.sh

#!/bin/sh
umount /mnt/$1
sleep 1
rmdir /mnt/$1
rebuildfstab

Result. It doesn't work... It doesn't even seem to get as far as rebuildfstab since no drives are even recognized when you insert a USB... What a mission to get USB to automount :S

Title: Re: Automount USB rules.d Query
Post by: MadCat on May 19, 2011, 06:08:43 AM
After trying for a few days I have come to the conclusion its time for me to move onto another Distro. Tiny Core seems great but Ive already spent a few days just trying to get USB to Automount. Ive decided to move on and try Thin Station, and to my relief comes in @ 8MB ISO, USB Automounting and RDesktop which I am able to redirect USB Devices. And to my amazement I got it all working in under 10minutes... So no offense to Tiny Core, but if anybody else gets stuck trying to get a Thin Client going, there you go.
Title: Re: Automount USB rules.d Query
Post by: alu on May 20, 2011, 01:15:28 AM
why not using hal and dbus (extensions in repos) instead with a backup, which should give you what you want within a minute?
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 20, 2011, 07:09:18 AM
why not using hal and dbus (extensions in repos) instead with a backup, which should give you what you want within a minute?

Doesant work on Tiny Core...
Title: Re: Automount USB rules.d Query
Post by: alu on May 20, 2011, 09:40:04 AM
?? did you try them ? and did you do a backup for the extension and related files to be loaded on boot ? i must confess that i used them once on 2.x versions of TC and can not speak for 3.x, but they did work.

maybe a question/suggestion: every usb should be mounted as sda, sdb, sdc etc. did you try a script loaded on boot with a command like: sudo mount -a /dev/sd*

how many usb should you mount on boot? if it is always the same ones, you can customize it with a script loaded on boot. i think that microcore with such a (backed up) script should be not go beyond 8 MB.

Title: Re: Automount USB rules.d Query
Post by: bmarkus on May 20, 2011, 09:44:13 AM
With udev you do not need to deal with device name. It is provided by udev as %k variable, see my demo script above. For testing you can write it to a file for example to see what happens inserting an usb. Also, use udevadm's monitor function to see what is going on.

It is a 5 minutes lesson.
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 20, 2011, 09:46:24 AM
?? did you try them ? and did you do a backup for the extension and related files to be loaded on boot ? i must confess that i used them once on 2.x versions of TC and can not speak for 3.x, but they did work.

maybe a question/suggestion: every usb should be mounted as sda, sdb, sdc etc. did you try a script loaded on boot with a command like: sudo mount -a /dev/sd*

how many usb should you mount on boot? if it is always the same ones, you can customize it with a script loaded on boot. i think that microcore with such a (backed up) script should be not go beyond 8 MB.



Yea, myself and another guy tried to get it working. Refused to mount USB when the terminal was on... Best we could get was Mounting USB @ Start which basically defeated the point of wanting to turn Tiny Core into a Thin Client OS. Eitherway it seem ThinStation is the way to go...
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 20, 2011, 09:47:37 AM
With udev you do not need to deal with device name. It is provided by udev as %k variable, see my demo script above. For testing you can write it to a file for example to see what happens inserting an usb. Also, use udevadm's monitor function to see what is going on.

It is a 5 minutes lesson.


You fail to realize your script refused to get to the rebuildfstab command, go test it and see...
Title: Re: Automount USB rules.d Query
Post by: bmarkus on May 20, 2011, 10:14:35 AM
With udev you do not need to deal with device name. It is provided by udev as %k variable, see my demo script above. For testing you can write it to a file for example to see what happens inserting an usb. Also, use udevadm's monitor function to see what is going on.

It is a 5 minutes lesson.


You fail to realize your script refused to get to the rebuildfstab command, go test it and see...

Well, it was tested becuse submitted. Also, you are missing to relize that working with linux requires self education, testing, etc. An investment. Seems a specialized system like TC is not for you. That's fine, but if you are not willing to do so, better to use something else instead of being negative.
Title: Re: Automount USB rules.d Query
Post by: MadCat on May 20, 2011, 10:20:43 AM
With udev you do not need to deal with device name. It is provided by udev as %k variable, see my demo script above. For testing you can write it to a file for example to see what happens inserting an usb. Also, use udevadm's monitor function to see what is going on.

It is a 5 minutes lesson.


You fail to realize your script refused to get to the rebuildfstab command, go test it and see...

Well, it was tested becuse submitted. Also, you are missing to relize that working with linux requires self education, testing, etc. An investment. Seems a specialized system like TC is not for you. That's fine, but if you are not willing to do so, better to use something else instead of being negative.

No, It does not work... And I am not being negative. Anyways, I am going to refrain from posting since this I have already achieved my goal. Goodbye
Title: Re: Automount USB rules.d Query
Post by: tinypoodle on May 20, 2011, 11:20:42 AM
As the questions of Reply #13 have been ignored I am not that unhappy that indiscriminate automounting doesn't work easily.

Coping with the potential consequences might take more than just some quick scripting...
Title: Re: Automount USB rules.d Query
Post by: alu on May 20, 2011, 01:03:44 PM
let's be positive, you should try a bit with linux and tc/mc is not often that easy, the learning curve can be a bit demanding, but it pays off. i have had similar problems with automount on several tiny client, and it was easy to set them up with bela's similar proposal or one of others like mines. feel free to get another try just in order to train, and tc/mc is good a that.
Title: Re: Automount USB rules.d Query
Post by: BigBas on October 21, 2011, 05:44:19 AM
Hi Guys,

I have also been wanting to automount usb sticks on tinycore and came across this thread. I have to add that the info from "bmarkus" DOES work. Initially the scripts wouldn't work and i was having the same issue as MadCat but i found the solution was file permissions.

Once i had applied executable permisions to the 2 script files with the chmod command it works!

I know this is an old thread but it helped me and may help someone else.

Thanks  for the great forum and keep up the good work. :)
Title: Re: Automount USB rules.d Query
Post by: bmarkus on October 21, 2011, 06:03:50 AM
BigBas,

thanks for the confirmation it works. I will add it to WiKi.

Title: Re: Automount USB rules.d Query
Post by: innominate on April 21, 2013, 08:08:37 AM
Hi,

For whatever it's worth, this worked fine for me and is exactly what I was looking for.

Thanks Béla et al!

Cheers,
Title: Re: Automount USB rules.d Query
Post by: Johannj2 on January 05, 2021, 11:47:43 AM
Thanks bmarkus,

10 years later and this information is still useful, thanks for the help.

Regards
Johann