WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: feature request for the "waitusb=" parameter  (Read 5891 times)

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
feature request for the "waitusb=" parameter
« on: March 28, 2010, 04: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

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11043
Re: feature request for the "waitusb=" parameter
« Reply #1 on: March 28, 2010, 05:41:47 PM »
Well, as you probably know, polling = bad. If you have an idea how to do this properly, please share :)
The only barriers that can stop you are the ones you create yourself.

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: feature request for the "waitusb=" parameter
« Reply #2 on: March 29, 2010, 01:06:06 AM »
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.
10+ Years Contributing to Linux Open Source Projects.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11043
Re: feature request for the "waitusb=" parameter
« Reply #3 on: March 29, 2010, 04:44:56 AM »
I meant the first way that came to mind, checking blkid every once in a while.
The only barriers that can stop you are the ones you create yourself.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #4 on: March 29, 2010, 01:40:08 PM »
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

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #5 on: March 29, 2010, 03:59:25 PM »
Well, here's my suggestion:

in /etc/init.d/tc-config, I replaced
Code: [Select]
[ -n "$WAITUSB" ] && sleep $WAITUSBwith
Code: [Select]
[ -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

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11043
Re: feature request for the "waitusb=" parameter
« Reply #6 on: March 29, 2010, 06:03:33 PM »
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?
The only barriers that can stop you are the ones you create yourself.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #7 on: March 29, 2010, 06:18:06 PM »
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.

Quote
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:
Code: [Select]
[ -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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11043
Re: feature request for the "waitusb=" parameter
« Reply #8 on: March 29, 2010, 06:22:02 PM »
Now that I think of it, I'd suggest builtin arithmetic instead of a call:

timeout=$(($timeout-1))
The only barriers that can stop you are the ones you create yourself.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #9 on: March 29, 2010, 06:31:07 PM »
timeout=$(($timeout-1))
Ah, that's how it works. I tried timeout=$[$timeout-1] without success. That seems to be a bash extension.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #10 on: April 01, 2010, 02:13:07 PM »
The one second delay between probing for the disc still felt too slow to me, so I did a slight change as well:

Code: [Select]
[ -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.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11043
Re: feature request for the "waitusb=" parameter
« Reply #11 on: April 01, 2010, 03:43:09 PM »
That reverted back to the previous blkid test?
The only barriers that can stop you are the ones you create yourself.

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: feature request for the "waitusb=" parameter
« Reply #12 on: April 01, 2010, 03:52:41 PM »
Whoops, got wrong codebase for the "1/4 second"-change.  I meant of cause:
Code: [Select]
[ -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...

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: feature request for the "waitusb=" parameter
« Reply #13 on: April 02, 2010, 12:23:18 AM »
Looks good. Adding to the base for v2.11.
10+ Years Contributing to Linux Open Source Projects.