WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

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

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Automount USB rules.d Query
« on: December 27, 2021, 08:29:24 AM »
Hi,
i already saw the thread http://forum.tinycorelinux.net/index.php/topic,9622.0.html and the scripts working fine.

but i have one problem, how to mount the new attached USB drive not to /mnt/$1 but to other directory
for example to /test/$1 or /mnt/test/$1

this is from my mount script
Code: [Select]
mount /dev/$1 /mnt/$1
what i want is:
Code: [Select]
mount /dev/$1 /mnt/test/$1 or
Code: [Select]
mount /dev/$1 /test/$1
can't find the option there for


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #1 on: December 27, 2021, 10:02:12 AM »
Hi Rabie
If you are looking for auto mounting, here is the solution I came up with:
http://forum.tinycorelinux.net/index.php/topic,23337.0.html
I've been running it for a couple of years now.

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #2 on: December 27, 2021, 11:41:23 AM »
Hi Rabie
If you are looking for auto mounting, here is the solution I came up with:
http://forum.tinycorelinux.net/index.php/topic,23337.0.html
I've been running it for a couple of years now.

Hi Rich,

are u running it on TC 10x_86x ?
Because there are different things in my system (TC 10.1 64x)

$ Path returns this:
Code: [Select]
tc@box:/opt/Scripts$ $ PATH
-sh: /home/tc/.local/bin:/usr/local/sbin:/usr/local/bin:/apps/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/sysconfig/tcedir/ondemand: not found

and the date is in:
Code: [Select]
/bin/datein the Script:
Code: [Select]
/usr/local/bin/date "Already changed it"


This is my /etc/udev/rules.d/98-tc.rules: (See Attachments)

I made the Script executable and ran it manualy (after i attached an USB drive), but it gives nothing, not even the log (i changed the log to /tmp/automount.log)

Edit:
I installed ntfs-3g.tcz and checked that those are not running (parted, gdisk, mkfs, or fsck)
« Last Edit: December 27, 2021, 11:44:54 AM by Rabie »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #3 on: December 27, 2021, 01:51:46 PM »
Hi Rabie
... $ Path returns this: ...
That's the path you see as user  tc.  The path a script launched by udev is different.

Quote
... and the date is in ...
The date as listed is correct. it states:
Code: [Select]
# coreutils version of date is required if sub-second timing is desired.
[ -e /usr/local/bin/date ] && alias date='/usr/local/bin/date'
Using coreutils is optional. This alias only gets set if  /usr/local/bin/date  exists.

Quote
... This is my /etc/udev/rules.d/98-tc.rules ...
After you make changes to udev rules, you need to run:
Code: [Select]
sudo udevadm control --reload-rules
udevadm trigger

Quote
... I made the Script executable and ran it manualy (after i attached an USB drive), ...
You can't run it that way. When udev detects a USB drive getting plugged in, it calls  automount.sh %k  where  %k
is the designation (sda, sdb, sdc, etc.) assigned to your device. It also sets certain environmental variables that
the script test for.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #4 on: December 27, 2021, 02:14:39 PM »
Hi Rabie
One more thing. The script auto mounts, it does not auto unmount, no system does. You should always unmount
a device before removing it.

The little icon at the bottom of the screen that looks like a disk drive is the  MountTool.  Single click it to launch it.
When you plug in a USB device,  automount.sh  will update the  MountTool  to display the newly mounted partitions.
After you are done, unmount the partitions. When you unplug the USB device,  automount.sh  will again update the
MountTool  to no longer display your device.

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #5 on: December 27, 2021, 02:31:29 PM »
Hi Rabie
One more thing. The script auto mounts, it does not auto unmount, no system does. You should always unmount
a device before removing it.

The little icon at the bottom of the screen that looks like a disk drive is the  MountTool.  Single click it to launch it.
When you plug in a USB device,  automount.sh  will update the  MountTool  to display the newly mounted partitions.
After you are done, unmount the partitions. When you unplug the USB device,  automount.sh  will again update the
MountTool  to no longer display your device.


Hi Rich,
that i understand

but i need to get the Script to work first.

Quote
After you make changes to udev rules, you need to run:
sudo udevadm control --reload-rules
udevadm trigger
i did reload the rules but still no changes.
Code: [Select]
tc@Box:~$ sudo udevadm control --reload-rules&
tc@Box:~$
[1]+  Done                       sudo udevadm control --reload-rules
tc@Box:~$
tc@Box:~$ udevadm trigger
tc@Box:~$


The Script doesn't create the Log so i can see what is going on.
and doesn't mount the USB Drive when i plug in.

Code: [Select]

drwxr-sr-x    6 root     staff          120 Dec 27 23:15 ./
drwxr-sr-x   17 root     staff          400 Dec 27 23:15 ../
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda1/
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda2/
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda3/
drwxr-xr-x    4 root     root          4096 Dec  8  2020 sdc1/
the above listed Drives are already mounted while booting

When i manualy refresh mnttool:
Code: [Select]

drwxr-sr-x    7 root     staff          140 Dec 27 23:29 ./
drwxr-sr-x   17 root     staff          400 Dec 27 23:15 ../
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda1/
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda2/
drwxr-sr-x    2 root     staff           40 Dec 27 23:15 sda3/
drwxr-xr-x    4 root     root          4096 Dec  8  2020 sdc1/
drwxr-sr-x    2 root     staff           40 Dec 27 23:29 sdd1/

Edit:
do you know if this Possible
Quote
but i have one problem, how to mount the new attached USB drive not to /mnt/$1 but to other directory
for example to /test/$1 or /mnt/test/$1
« Last Edit: December 27, 2021, 02:36:31 PM by Rabie »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #6 on: December 27, 2021, 06:19:20 PM »
Hi Rabie
In the script, find this line:
Code: [Select]
# ---- End Functions ---- #and change it to this:
See attached file.

This will write a message to what  $DEBUGLOG  is pointing to. You did uncomment the  DEBUGLOG=  line, right?
After you modified  98-tc.rules, you ran a backup on it, right? Otherwise changes will be lost upon rebooting.
The USB device you plug in must be formatted in order to be mounted.

... i did reload the rules but still no changes.
Code: [Select]
tc@Box:~$ sudo udevadm control --reload-rules&
tc@Box:~$
[1]+  Done                       sudo udevadm control --reload-rules
Why did you background (&) that command?

Quote
... do you know if this Possible ...
/etc/fstab, the MountTool app, and any Tinycore scripts involved in mounting default to /mnt. You can create other
mountpoints and and use them if needed:
Code: [Select]
mkdir -p stuff/i/like
Code: [Select]
sudo mount /dev/sdd1 stuff/i/like

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #7 on: December 28, 2021, 03:30:25 AM »
Hi Rich,

Quote
In the script, find this line:
# ---- End Functions ---- #
and change it to this:
See attached file.

i did that (See Attachment)

Quote
You did uncomment the  DEBUGLOG=  line, right?
Yes!
Quote
After you modified  98-tc.rules, you ran a backup on it, right? Otherwise changes will be lost upon rebooting.
i did that also saved in /opt/.filetool.lst
Quote
Why did you background (&) that command?
Code: [Select]
nano /opt/.filetool.lst
/etc/udev/rules.d/98-tc.rules
in bootlocal did put the reload command and copied the line to test, i didn't mean to background it, but it doesn't give any feedback anyway

Code: [Select]
tc@box:~$ sudo udevadm control --reload-rules
tc@box:~$ udevadm trigger
tc@box:~$


Code: [Select]
nano /opt/bootlocal.sh
sudo udevadm control --reload-rules&

Quote
The USB device you plug in must be formatted in order to be mounted.
i don't think so, because with my old script it did work without formatting it,  but i formated it now to test and nothing happens  :-\

Edit:

when i remove the ENV from "/etc/udev/rules.d/98-tc.rules"
Code: [Select]
ENV{ID_FS_TYPE}=="?*" maybe i need to export it as an environment variable ?

the script do create the log:
Code: [Select]
tail -f /tmp/automount.log
12:41:25.%N sdb1 automount.sh started
12:41:25.%N sdb automount.sh started
12:41:53.%N sdb automount.sh started
12:41:53.%N sdb1 automount.sh started
12:43:27.%N sdb1 automount.sh started
12:43:27.%N sdb automount.sh started
12:43:34.%N sdb automount.sh started
12:43:34.%N sdb1 automount.sh started

but sdb doesn't appear in /mnt
Code: [Select]

total 4
drwxr-sr-x    6 root     staff          120 Dec 28 12:37 ./
drwxr-sr-x   17 root     staff          400 Dec 28 12:06 ../
drwxr-sr-x    2 root     staff           40 Dec 28 12:06 sda1/
drwxr-sr-x    2 root     staff           40 Dec 28 12:06 sda2/
drwxr-sr-x    2 root     staff           40 Dec 28 12:06 sda3/
drwxr-xr-x    4 root     root          4096 Dec  8  2020 sdd1/
« Last Edit: December 28, 2021, 03:52:27 AM by Rabie »

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #8 on: December 28, 2021, 04:10:04 AM »
Code: [Select]
udevadm monitor --env

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #9 on: December 28, 2021, 08:11:20 AM »
Hi Rabie
...
Code: [Select]
nano /opt/bootlocal.sh
sudo udevadm control --reload-rules&
...
I guess by that you mean you are backgrounding that command in  bootlocal.sh.
If you want to run that command on startup, place it in  bootsync.sh  before it calls  bootlocal.sh  and do not
background it.

Quote
Quote
... The USB device you plug in must be formatted in order to be mounted.
i don't think so, because with my old script it did work without formatting it,  but i formated it now to test and nothing happens  :-\ ...
An unformatted device will still be detected by  udev , but it can not be mounted. Most USB storage devices come
pre-formatted. If the mount command can not recognize the file system type (fat, ntfs, ext3, etc.) it can not mount it.


Quote
... when i remove the ENV from "/etc/udev/rules.d/98-tc.rules"
Code: [Select]
ENV{ID_FS_TYPE}=="?*" maybe i need to export it as an environment variable ? ...
Why would you remove that? udev sets the  ID_FS_TYPE  environment variable. The 98-tc.rules you attached in
reply #2 is correct.

Quote
... the script do create the log: ...
Good, that means udev is detecting a device and finding the script.

Attached is a file that shows what the result of  udevadm monitor --env  should look like.  The sections
containing  ID_FS_TYPE  are the ones  automount.sh  responds to.

It's also possible you need to install  udev-extra.

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #10 on: December 28, 2021, 08:21:34 AM »
Quote
Why would you remove that? udev sets the  ID_FS_TYPE  environment variable. The 98-tc.rules you attached in
reply #2 is correct.

i removed it just as a test.

Quote
An unformatted device will still be detected by  udev , but it can not be mounted. Most USB storage devices come
pre-formatted. If the mount command can not recognize the file system type (fat, ntfs, ext3, etc.) it can not mount it.

i formatted the USB Storage on Windows as FAT32
the Script still not creating the log and doesn't mount the USB Drive

Quote
... the script do create the log: ...
Good, that means udev is detecting a device and finding the script.
the Log is been created just when i remove ENV{ID_FS_TYPE}=="?*"

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #11 on: December 28, 2021, 08:28:51 AM »
Hi Rabie
... the Log is been created just when i remove ENV{ID_FS_TYPE}=="?*"
Yes, that is by design:
Code: [Select]
# If the device is a disk as opposed to a partition (i.e. sda instead of sda1), an
# extended partition, has no partion table, or is unformatted, then FSTYPE is empty
# and we exit.
[ -z "$FSTYPE" ] && exit
If the variable is not set, we don't have enough information to proceed.

See if installing  udev-extra  helps.

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #12 on: December 28, 2021, 08:45:30 AM »
Quote
If the variable is not set, we don't have enough information to proceed.
i see

Quote
See if installing  udev-extra  helps.

yes that did it  :) :)

Code: [Select]
tail -f /tmp/automount.log
17:36:07.%N sdd1 automount.sh started
17:36:07.%N sdd1 Start Action=add ID_FS_TYPE=vfat
17:36:07.%N sdd1 Arbitration complete.
17:36:09.%N sdd1 Rebuildfstab
17:36:09.%N sdd1 Mount succeeded.
17:36:09.%N sdd1 Refreshed MountTool
17:36:09.%N sdd1 End.
17:37:17.%N sdd1 automount.sh started
17:37:17.%N sdd1 Start Action=remove ID_FS_TYPE=vfat
17:37:17.%N sdd1 Arbitration complete.
17:37:17.%N sdd1 Forcibly unmounted.
17:37:17.%N sdd1 Removed.
17:37:18.%N sdd1 Rebuildfstab.
17:37:18.%N sdd1 End.

added
Code: [Select]
drwxr-sr-x    7 root     staff          140 Dec 28 17:36 ./
drwxr-sr-x   17 root     staff          400 Dec 28 17:33 ../
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda1/
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda2/
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda3/
drwxr-xr-x    4 root     root          4096 Dec  8  2020 sdc1/
drwxrwxrwx    4 root     root         32768 Jan  1  1970 sdd1/

removed
Code: [Select]
drwxr-sr-x    6 root     staff          120 Dec 28 17:37 ./
drwxr-sr-x   17 root     staff          400 Dec 28 17:33 ../
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda1/
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda2/
drwxr-sr-x    2 root     staff           40 Dec 28 17:32 sda3/
drwxr-xr-x    4 root     root          4096 Dec  8  2020 sdc1/

thank you very much

now i have just a little question

is there a way to automaticlly rename the new attached usb ? like /mnt/myusbstick ?
« Last Edit: December 28, 2021, 08:47:42 AM by Rabie »

Offline Rabie

  • Sr. Member
  • ****
  • Posts: 272
Re: Automount USB rules.d Query
« Reply #13 on: December 28, 2021, 09:28:26 AM »
also my device has an SD/SDHC/SDXC slot, but it doesn't seem to be recognized by the script.
i tested it with mnttool maualy to be sure that the sd card works:

before:
Code: [Select]
fdisk -l
Disk /dev/sda: 466 GB, 500107862016 bytes, 976773168 sectors
60801 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sda1 *  0,32,33     6,127,57          2048     104447     102400 50.0M  7 HPFS/NTFS
/dev/sda2    6,127,58    1023,254,63     104448  975694715  975590268  465G  7 HPFS/NTFS
/dev/sda3    1023,254,63 1023,254,63  975695872  976769023    1073152  524M 27 Unknown
Disk /dev/sdc: 3727 MB, 3908042752 bytes, 7632896 sectors
9912 cylinders, 55 heads, 14 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdc1 *  0,1,1       1017,54,14          62    7632895    7632834 3726M 83 Linux



after:

Code: [Select]
fdisk -l
Disk /dev/sda: 466 GB, 500107862016 bytes, 976773168 sectors
60801 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sda1 *  0,32,33     6,127,57          2048     104447     102400 50.0M  7 HPFS/NTFS
/dev/sda2    6,127,58    1023,254,63     104448  975694715  975590268  465G  7 HPFS/NTFS
/dev/sda3    1023,254,63 1023,254,63  975695872  976769023    1073152  524M 27 Unknown
Disk /dev/sdb: 15 GB, 15980298240 bytes, 31211520 sectors
1942 cylinders, 255 heads, 63 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdb1    0,130,3     1023,254,63       8192   31211519   31203328 14.8G  c Win95 FAT32 (LBA)
Disk /dev/sdc: 3727 MB, 3908042752 bytes, 7632896 sectors
9912 cylinders, 55 heads, 14 sectors/track
Units: sectors of 1 * 512 = 512 bytes

Device  Boot StartCHS    EndCHS        StartLBA     EndLBA    Sectors  Size Id Type
/dev/sdc1 *  0,1,1       1017,54,14          62    7632895    7632834 3726M 83 Linux

where sdb is the sd card
is there somthing i can do ?


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Automount USB rules.d Query
« Reply #14 on: December 28, 2021, 11:21:23 AM »
Hi Rabie
also my device has an SD/SDHC/SDXC slot, but it doesn't seem to be recognized by the script. ...
From the comments at the top of the script:
Code: [Select]
# If your CD drive or your card reader devices won't automount, try this:
# echo 2000 | sudo tee /sys/module/block/parameters/events_dfl_poll_msecs
If that solves the problem, add it to  bootlocal.sh.