Tiny Core Linux
Tiny Core Base => TCB Q&A Forum => Topic started by: SvOlli on March 28, 2010, 01:10:18 PM
-
A small question:
Could the "waitusb=" boot parameter be extended to that "waitusb=UUID=..." or "waitusb=LABEL=..." waits for the specific label to come up? That would be great for those "rescue-usb-sticks", since the some machines start up usb faster than others.
Greetings,
SvOlli
-
Well, as you probably know, polling = bad. If you have an idea how to do this properly, please share :)
-
Current waitusb is really a misnomer, as it just represents seconds to sleep. No polling. That is why some must use other than the recommended starting point of 5 in waitusb=5.
-
I meant the first way that came to mind, checking blkid every once in a while.
-
I meant the first way that came to mind, checking blkid every once in a while.
That was I was thinking about. Instead of a "sleep $waitusb" use a "while ! blkid ...; do sleep 1; done"
I'll hack up a prototype / suggestion in the next couple of hours.
Greetings,
SvOlli
-
Well, here's my suggestion:
in /etc/init.d/tc-config, I replaced
[ -n "$WAITUSB" ] && sleep $WAITUSB
with
[ -n "$WAITUSB" ] && (
case $WAITUSB in
*:*) dev=${WAITUSB#*:}
timeout=${WAITUSB%:*}
while [ $timeout -gt 0 ]; do
echo -en "\rwaiting for usb ... $timeout "
timeout=$(expr $timeout - 1)
sleep 1
blkid | tr -d \" | grep -q $dev && timeout=0
done ;;
*) sleep "$WAITUSB" ;;
esac
)
and now with the option WAITUSB=30:LABEL=TinyCore now boots in far less than 30 seconds.
Greetings,
SvOlli
-
Pretty nice. One thing though, it allows partial matches - for example two labels, "linux" and "linux2" would both be matched by LABEL=linux.
How about using the same method as in tc-functions (blkid -lt $dev) and checking if the output is not empty?
-
Pretty nice. One thing though, it allows partial matches - for example two labels, "linux" and "linux2" would both be matched by LABEL=linux.
Yeah, you're right, I missed that one... Thanks for noticing.
How about using the same method as in tc-functions (blkid -lt $dev) and checking if the output is not empty?
But that could be done better. If no match was found, blkid returns 2; on success 0, so you can run it like this:[ -n "$WAITUSB" ] && (
case $WAITUSB in
*:*) dev=${WAITUSB#*:}
timeout=${WAITUSB%:*}
while [ $timeout -gt 0 ]; do
echo -en "\rwaiting for usb ... $timeout "
timeout=$(expr $timeout - 1)
sleep 1
blkid -lt $dev && timeout=0
done ;;
*) sleep "$WAITUSB" ;;
esac
)
This code is untested, though.
-
Now that I think of it, I'd suggest builtin arithmetic instead of a call:
timeout=$(($timeout-1))
-
timeout=$(($timeout-1))
Ah, that's how it works. I tried timeout=$[$timeout-1] without success. That seems to be a bash extension.
-
The one second delay between probing for the disc still felt too slow to me, so I did a slight change as well:
[ -n "$WAITUSB" ] && (
case $WAITUSB in
*:*) dev=${WAITUSB#*:}
timeout=$((${WAITUSB%:*} * 4))
while [ $timeout -gt 0 ]; do
echo -en "\rwaiting for usb ... $(($timeout / 4)) "
timeout=$(($timeout - 1))
sleep 0.25
blkid | tr -d \" | grep -q $dev && timeout=0
done
;;
*) sleep "$WAITUSB" ;;
esac
)
Now I'm checking four times a second, this feels like an instant continue after the kernel log message that a new disc was found.
-
That reverted back to the previous blkid test?
-
Whoops, got wrong codebase for the "1/4 second"-change. I meant of cause:
[ -n "$WAITUSB" ] && (
case $WAITUSB in
*:*) dev=${WAITUSB#*:}
timeout=$((${WAITUSB%:*} * 4))
while [ $timeout -gt 0 ]; do
echo -en "\rwaiting for usb ... $(($timeout / 4)) "
timeout=$(($timeout - 1))
sleep 0.25
blkid -lt $dev && timeout=0
done
;;
*) sleep "$WAITUSB" ;;
esac
)
Thanks for reminding me...
-
Looks good. Adding to the base for v2.11.