LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 08-17-2021, 01:43 PM   #1
JayByrd
Member
 
Registered: Aug 2021
Location: Seattle, WA
Distribution: Slackware
Posts: 300

Rep: Reputation: 309Reputation: 309Reputation: 309Reputation: 309
Hiccup/oversight in mkinitrd


Recently, while building up another BOINC crunching rig, I discovered something peculiar in the Slackware boot process.

This system is an old laptop with a faulty internal harddrive, so I installed Slackware to a USB pen drive. When I would try to boot the new install, it would drop me to an emergency shell, saying the root device didn't exist. Checking the logs, I soon realized that init was trying to mount the root file system before the root device had been enumerated. Easy enough fix: I just added "-w 2" to my mkinitrd command line.

However, this got me curious, so I delved into the mkinitrd script itself and found this:

Code:
# If $WAIT is not set, assume we need only one second
# to have all devices done
# (unless we find that value is already set in the initrd-tree):
if [ -z "$WAIT" -a -z "$(cat $SOURCE_TREE/wait-for-root)" ]; then
  WAIT=1
  # ARM devices need even more time:
  case "$( uname -m )" in
    arm*) WAIT=4;;
  esac
fi
if [ ! -z "$WAIT" ]; then
  echo $WAIT > $SOURCE_TREE/wait-for-root
fi
Unfortunately, this test for ARM-ness never gets run. When extracting the skeleton initrd-tree, rootdev and rootfs are empty files (0 bytes,) but wait-for-root contains a "1". Thus, testing "-z $SOURCE_TREE/wait-for-root" always fails, so the body of that block is never entered.

The only way I can see for the ARM-test to actually run would be to run mkinitrd once to extract the skeleton initrd-tree, manually empty/null the wait-for-root file, and then run mkinitrd again without the "-c" option. (Also note that the second if-statement applies only if "-w" is specified on the command line. Otherwise, $WAIT is always empty.)

Simple solution: make wait-for-root an empty file in the skeleton tree, like rootfs, etc. Then the test for ARM-ness will actually run.

However, this does make it so that the second if-block above will always override the wait-for-root value, even in the case where there is a preexisting initrd-tree with a non-empty wait-for-root. So, in addition to making wait-for-root a null file in the skeleton tree, I suggest the following change to the above mkinitrd code:

Code:
if [ -z "$WAIT" ]; then
  PRESET_WAIT="$(cat $SOURCE_TREE/wait-for-root)"
  if [ -n "$PRESET_WAIT" ]; then
    WAIT="$PRESET_WAIT"
  else
    case "$( uname -m )" in
      arm*) WAIT=4;;
         *) WAIT=1;;
    esac
  fi
fi

if [ ! -z "$WAIT" ]; then
  echo $WAIT > $SOURCE_TREE/wait-for-root
fi
This change preserves the intended order of priority:
1st priority: "-w" on the command line
2nd priority: preexisting value in wait-for-root
3rd priority: default to 1 or 4

(I suppose at this point you could also drop that final if-statement before the echo, because now $WAIT should never be empty by this point in the script.)

(note: this diagnosis applies at least to 14.1, 14.2, and the last time I checked it in current a few weeks ago...)

Last edited by JayByrd; 08-17-2021 at 02:58 PM. Reason: fix intermediate code, and second thoughts about final "if."
 
Old 08-17-2021, 01:56 PM   #2
JayByrd
Member
 
Registered: Aug 2021
Location: Seattle, WA
Distribution: Slackware
Posts: 300

Original Poster
Rep: Reputation: 309Reputation: 309Reputation: 309Reputation: 309
While the above solution does work, I'd like to go out on a limb and suggest another solution, one that would obviate the need for any "uname -m" testing at all. (My apologies to Pat and team if this is old hat and/or goes against KISS.)

In addition to nulling out the wait-for-root file, I changed the "sleep $WAIT" line in the init script to a sleep one-second-at-a-time countdown. Thus, the suggestion offered above for the mkinitrd script became:
Code:
# NOTE: modified by Jay to make a default of 5 seconds,
# unless specified on the command line or previously set
# in the "wait-for-root" file.
PRESET_WAIT="$(cat $SOURCE_TREE/wait-for-root)"
if [ -z "$WAIT" -a -n "$PRESET_WAIT" ]; then
  WAIT="$PRESET_WAIT"
else
  WAIT="${WAIT:-5}"
fi
And I replaced "sleep $WAIT" in the initrd-tree/init script with a small countdown loop:
Code:
COUNTER="$WAIT"
while [ ! -b $ROOTDEV -a $COUNTER -gt 0 ] ; do
  sleep 1
  COUNTER=$((COUNTER - 1))
done
unset COUNTER
This way, the init script will wait as long as necessary (up to the time-out value) and would resume booting within one second of rootdev becoming available.

Again, apologies if this has been discussed before and/or countdown timers are frowned upon. Moreover, I realize that this may be much ado about nothing. A dozen Slackware installs, and the wait-for-root value of "1" always sufficed, until I installed to a USB--and subsequently realized that I needed only two seconds instead of four. But that's what I like about this solution: it behaves the same regardless of boot-media type, arch, etc.

(This modification has the effect of changing the definition of "-w". Instead of specifying a set wait time, "-w" sets a maximum time to wait for the root device to become ready.)

Last edited by JayByrd; 08-17-2021 at 01:59 PM.
 
5 members found this post helpful.
Old 08-18-2021, 12:15 AM   #3
JayByrd
Member
 
Registered: Aug 2021
Location: Seattle, WA
Distribution: Slackware
Posts: 300

Original Poster
Rep: Reputation: 309Reputation: 309Reputation: 309Reputation: 309
Looking back over my first post, it seems I may have been over-thinking the second part. I see now that just making wait-for-root null in the skeleton initrd-tree alone should be sufficient. No changes to the mkinitrd script required... D'OH!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Secure IoT Through Oversight, Open Source and Open Standards LXer Syndicated Linux News 0 12-08-2016 11:12 PM
exim4 is in Cygwin 32 but not Cygwin 64 - is it an oversight or otherwise? fairch720 Linux - Software 0 08-27-2013 12:45 AM
Setup question, possible oversight in setup routine vdemuth Slackware 5 08-04-2010 01:47 PM
sudo mkinitrd -o /boot/initrd.img-2.6.32.9 2.6.32.9 sudo: mkinitrd: command not foun vishwas181 Linux - Newbie 1 02-27-2010 01:16 AM
iptables.. Bit of guidance/oversight with my SNAT and DNAT stuff please? GrapefruiTgirl Linux - Security 15 04-02-2009 01:31 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 10:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration