WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Automount USB rules.d Query  (Read 24365 times)

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Automount USB rules.d Query
« 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"

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #1 on: May 16, 2011, 09:08:56 AM »
Anybody out there?

Offline Guy

  • Hero Member
  • *****
  • Posts: 1089
Re: Automount USB rules.d Query
« Reply #2 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.
Many people see what is. Some people see what can be, and make a difference.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #3 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.

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #4 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? :/

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #5 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

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #6 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?

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #7 on: May 17, 2011, 05:12:09 AM »
*Bump*

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Automount USB rules.d Query
« Reply #8 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"

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #9 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

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #10 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]
« Last Edit: May 17, 2011, 09:47:48 AM by Rich »

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Automount USB rules.d Query
« Reply #11 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 ?
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Automount USB rules.d Query
« Reply #12 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?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: Automount USB rules.d Query
« Reply #13 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?
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline MadCat

  • Newbie
  • *
  • Posts: 12
Re: Automount USB rules.d Query
« Reply #14 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

« Last Edit: May 19, 2011, 12:30:20 AM by MadCat »