Tiny Core Linux
Tiny Core Base => Corepure64 => Topic started by: pek on September 16, 2021, 08:33:12 PM
-
Hi All,
I need another help again today :)
My aim:
1. To auto mount a USB drive with specific label name after X started.
2. run a script from from the USB.
What I did:
1. create a script to mount the USB /home/tc/mountUSB.sh
sudo mkdir /tmp/theUSB
sudo mount -L theLABEL /tmp/theUSB
sh /tmp/theUSB/theSCRIPT.sh
2. create a file to load it in /home/tc/.X.d/loadit
exec /home/tc/mountUSB.sh &
The problem:
**After boots up to X, the USB was not mounted.
But the /tmp/theUSB directory was successfully created.
**If I manually type exec "/home/tc/mountUSB.sh" in aterm, everything works perfectly and the script within the USB was launched successfully.
Can anyone help me on this please?
Thank you.
-
Hi pek
Try it like this:
#!/bin/sh
sudo mkdir /tmp/theUSB
drive="`/sbin/blkid -lt LABEL=theLABEL -o device`"
sudo mount "$drive" /tmp/theUSB
/tmp/theUSB/theSCRIPT.sh
Make /home/tc/.X.d/loadit look like this:
/home/tc/mountUSB.sh &
-
Hi Rich, thanks for your suggestion.
However it behaves exactly the same like the original.
**After boots up to X, the USB was not mounted.
But the /tmp/theUSB directory was successfully created.
**when I type exec ./.X.d/loadit in aterm, everything works perfectly and the script within the USB was launched successfully.
-
Hi pek
Try adding a sync command after the mkdir line.
Also, make sure your script is executable:
chmod 775 /home/tc/mountUSB.sh
-
Remove the exec, it may block anything after it from running.
-
Hi pek
Try adding a sync command after the mkdir line.
Also, make sure your script is executable:
chmod 775 /home/tc/mountUSB.sh
Hi Rich,
still the same.
This is what i did
sudo mkdir /tmp/theUSB
drive="`/sbin/blkid -lt LABEL=theLABEL -o device`"
sudo mount "$drive" /tmp/theUSB
sudo sync -f /tmp/theUSB/theSCRIPT.sh
/tmp/theUSB/theSCRIPT.sh
I'm not sure if that the correct sync command and position.
I think it should be invoked after mount instead of mkdir.
But no joy...
-
Remove the exec, it may block anything after it from running.
Hi curaga,
yes I did as Rich pointed out above.. But still same result.
-
Hi pek
... I'm not sure if that the correct sync command and position. ...
No, like this:
sudo mkdir /tmp/theUSB
sync
drive="`/sbin/blkid -lt LABEL=theLABEL -o device`"
sudo mount "$drive" /tmp/theUSB
/tmp/theUSB/theSCRIPT.sh
-
Hi pek
If the sync command does not help, change the first line of /home/tc/mountUSB.sh to this:
#!/bin/sh -x
And add these 2 lines immediately after the first line:
exec 1>/home/tc/debug.txt
exec 2>&1
Restart your machine and attach the the /home/tc/debug.txt file to your next post.
-
Hi Rich, it still failed.
Here's the debug.txt
+ sudo mkdir /tmp/theUSB
+ sync
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=
+ sudo mount '' /tmp/theUSB
mount: /tmp/theUSB: wrong fs type, bad option, bad superblock on , missing codepage or helper program, or other error.
+ /tmp/theUSB/xyz/theSCRIPT.sh
cd: line 4: can't cd to /tmp/theUSB/xyz: No such file or directory
when I change the mount command into my original one, the debug gives
+ sudo mount -L theLABEL /tmp/theUSB
mount: /tmp/theUSB: can't find LABEL="theLABEL".
-
Hi pek
It's not finding the drive. Is the drives label actually theLABEL ?
If you run this command manually does it find the device:
/sbin/blkid -lt LABEL=theLABEL -o device
-
Hi pek
It's not finding the drive. Is the drives label actually theLABEL ?
If you run this command manually does it find the device:
/sbin/blkid -lt LABEL=theLABEL -o device
yes, it returned
/dev/sdb1
And the fact that everything runs properly when invoked "./.X.d/loadit" means all is named correctly.
I edited my reply before this.. i tried mount -L command and gives similar result.
-
Could be timing then? Your device's label is not yet known at that time?
-
Could be timing then? Your device's label is not yet known at that time?
Possibly.. but i tried "sleep 9".. still nothing
-
Hi pek
Change this:
drive="`/sbin/blkid -lt LABEL=theLABEL -o device`"
To this:
drive=""
while [ -z "$drive" ]
do
drive="`/sbin/blkid -lt LABEL=theLABEL -o device`"
s l e e p 1
done
Remove the extra spaces in the sleep command.
-
Good news.. It works this time..!! ;D
Thank you Rich and curaga.
It took about 2 or 3 seconds to get mounted as can be seen in below debug.txt
+ sudo mkdir /tmp/theUSB
+ sync
+ drive=
+ '[' -z '' ']'
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=
+ sleep 1
+ '[' -z '' ']'
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=
+ sleep 1
+ '[' -z '' ']'
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=
+ sleep 1
+ '[' -z '' ']'
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=
+ sleep 1
+ '[' -z '' ']'
++ /sbin/blkid -lt LABEL=theLABEL -o device
+ drive=/dev/sdb1
+ sleep 1
+ '[' -z /dev/sdb1 ']'
+ sudo mount /dev/sdb1 /tmp/theUSB
However when I did "sleep 9" without the loop as above, it did not recognized.
Probably the USB drive needs to be probed a few times. Thus the loop "wakes" it up only in few seconds.
I'm not sure how how this works... But it does.
Thank you again guys...!! :)
-
Sorry.. my bad.
Actually "sleep 9" is also working.
I put it at the wrong line... That's why it did not work.
sudo mkdir /tmp/theUSB
sudo mount -L theLABEL /tmp/theUSB
s l e e p 9
the correct one is
sudo mkdir /tmp/theUSB
s l e e p 9
sudo mount -L theLABEL /tmp/theUSB
even so.. I prefer Rich's loop code. That way I don't need to guess how long the "sleep" should be.
All good.. Mistery solved.
Sorry for the hassles guys..
And best of all, I learn more new tricks... Thank you!! ;D ;D
-
Hi pek
... I prefer Rich's loop code. That way I don't need to guess how long the "sleep" should be. ...
It's also faster since it waits only until the label becomes visible.
The sleep command also can handle decimal numbers.
If you want to reduce the wait time a little more, try sleep 0.25
-
The sleep command also can handle decimal numbers.
If you want to reduce the wait time a little more, try sleep 0.25
Oh.. that's good to know. Thank you.