From fb08fcc819828d885f6e90f06fc4cd78f46842ac Mon Sep 17 00:00:00 2001 From: Eric Hameleers Date: Tue, 2 Aug 2022 10:15:36 +0200 Subject: liveinit: start ash bash-compatible and save init debug output to file When the value of 'debug' parameter is equal to or greater than '2', the init script enables 'set -x' which results in verbose output of init script execution. When the 'ash' shell is started as '/bin/sh' instead of '/bin/ash', it enables bash-compatible mode. Then the script can use 'BASH_XTRACEFD' to log the verbose script output to a file '/debug_init.log'. This is extremely useful for init debugging. Logging to file is enabled when the value of 'debug' is '4' or higher. When you boot with 'debug=4, you will end up in the rescue shell of the initrd. You can then inspect '/debug_init.log' to diagnose issues with the boot-up, and you can copy that logfile for instance to /mnt/overlay/root/ if you want to preserve it. After typing 'exit', the live init will hand-over to the Slackware OS initialization and after logging in you can copy the logfile to a network location if you want. --- liveinit.tpl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/liveinit.tpl b/liveinit.tpl index a5a7e9c..d00650d 100644 --- a/liveinit.tpl +++ b/liveinit.tpl @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/sh # # Copyright 2004 Slackware Linux, Inc., Concord, CA, USA # Copyright 2007, 2008, 2009, 2010, 2012 Patrick J. Volkerding, Sebeka, MN, USA @@ -305,7 +305,17 @@ for ARG in $(cat /proc/cmdline); do done # Verbose boot script execution: -[ $DEBUG -ge 2 ] && set -x +if [ $DEBUG -ge 2 ]; then + if [ $DEBUG -ge 4 ]; then + # We save (verbose) shell output to local file; + # These busybox compile options make it possible: + # CONFIG_SH_IS_ASH=y + # CONFIG_ASH_BASH_COMPAT=y + exec 5> debug_init.log + export BASH_XTRACEFD="5" + fi + set -x +fi debugit () { if [ $DEBUG -eq 0 -o $DEBUG -gt 3 ]; then -- cgit v1.2.3