Make stage-1/2 logging unconditional, and drop log level to "debug"

Using "debug" level prevents spamming the console with messages twice
(once directly and once via kmsg).

Changed files
+33 -53
nixos
+17 -17
nixos/modules/system/boot/stage-1-init.sh
···
mkdir -p /run
mount -t tmpfs -o "mode=0755,size=@runSize@" tmpfs /run
-
# Optionally log the script output to /dev/kmsg or /run/log/stage-1-init.log
-
if test -n "@logCommands@"; then
-
mkdir -p /tmp
-
mkfifo /tmp/stage-1-init.log.fifo
-
logOutFd=8 && logErrFd=9
-
eval "exec $logOutFd>&1 $logErrFd>&2"
-
if test -w /dev/kmsg; then
-
tee -i < /tmp/stage-1-init.log.fifo /proc/self/fd/"$logOutFd" | while read line; do
-
if test -n "$line"; then
-
echo "stage-1-init: $line" > /dev/kmsg
-
fi
-
done &
-
else
-
mkdir -p /run/log
-
tee -i < /tmp/stage-1-init.log.fifo /run/log/stage-1-init.log &
-
fi
-
exec > /tmp/stage-1-init.log.fifo 2>&1
+
+
# Optionally log the script output to /dev/kmsg or /run/log/stage-1-init.log.
+
mkdir -p /tmp
+
mkfifo /tmp/stage-1-init.log.fifo
+
logOutFd=8 && logErrFd=9
+
eval "exec $logOutFd>&1 $logErrFd>&2"
+
if test -w /dev/kmsg; then
+
tee -i < /tmp/stage-1-init.log.fifo /proc/self/fd/"$logOutFd" | while read line; do
+
if test -n "$line"; then
+
echo "<7>stage-1-init: $line" > /dev/kmsg
+
fi
+
done &
+
else
+
mkdir -p /run/log
+
tee -i < /tmp/stage-1-init.log.fifo /run/log/stage-1-init.log &
fi
+
exec > /tmp/stage-1-init.log.fifo 2>&1
+
# Process the kernel command line.
export stage2Init=/init
+2 -10
nixos/modules/system/boot/stage-1.nix
···
inherit (config.boot) resumeDevice devSize runSize;
-
inherit (config.boot.initrd) checkJournalingFS
-
logCommands preLVMCommands preDeviceCommands postDeviceCommands postMountCommands kernelModules;
+
inherit (config.boot.initrd) checkJournalingFS
+
preLVMCommands preDeviceCommands postDeviceCommands postMountCommands kernelModules;
resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}")
(filter (sd: (sd ? label || hasPrefix "/dev/" sd.device) && !sd.randomEncryption) config.swapDevices);
···
Specify here the device where the file resides.
You should also use <varname>boot.kernelParams</varname> to specify
<literal><replaceable>resume_offset</replaceable></literal>.
-
'';
-
};
-
-
boot.initrd.logCommands = mkOption {
-
default = false;
-
type = types.bool;
-
description = ''
-
Whether to replicate command output of stage-1 booting to <filename>/dev/kmsg</filename> or <filename>/run/log/stage-1-init.log</filename> if <filename>/dev/kmsg</filename> is not writable.
'';
};
+13 -17
nixos/modules/system/boot/stage-2-init.sh
···
# Optionally log the script output to /dev/kmsg or /run/log/stage-2-init.log.
# Only at this point are all the necessary prerequisites ready for these commands.
-
if test -n "@logCommands@"; then
-
exec {logOutFd}>&1 {logErrFd}>&2
-
if test -w /dev/kmsg; then
-
exec > >(tee -i /proc/self/fd/"$logOutFd" | while read line; do
-
if test -n "$line"; then
-
echo "stage-2-init: $line" > /dev/kmsg
-
fi
-
done) 2>&1
-
else
-
mkdir -p /run/log
-
exec > >(tee -i /run/log/stage-2-init.log) 2>&1
-
fi
+
exec {logOutFd}>&1 {logErrFd}>&2
+
if test -w /dev/kmsg; then
+
exec > >(tee -i /proc/self/fd/"$logOutFd" | while read line; do
+
if test -n "$line"; then
+
echo "<7>stage-2-init: $line" > /dev/kmsg
+
fi
+
done) 2>&1
+
else
+
mkdir -p /run/log
+
exec > >(tee -i /run/log/stage-2-init.log) 2>&1
fi
···
@shell@ @postBootCommands@
-
# Reset the logging file descriptors
-
if test -n "@logCommands@"; then
-
exec 1>&$logOutFd 2>&$logErrFd
-
exec {logOutFd}>&- {logErrFd}>&-
-
fi
+
# Reset the logging file descriptors.
+
exec 1>&$logOutFd 2>&$logErrFd
+
exec {logOutFd}>&- {logErrFd}>&-
# Start systemd.
+1 -9
nixos/modules/system/boot/stage-2.nix
···
src = ./stage-2-init.sh;
shellDebug = "${pkgs.bashInteractive}/bin/bash";
isExecutable = true;
-
inherit (config.boot) logCommands devShmSize runSize;
+
inherit (config.boot) devShmSize runSize;
inherit (config.nix) readOnlyStore;
inherit (config.networking) useHostResolvConf;
ttyGid = config.ids.gids.tty;
···
options = {
boot = {
-
-
logCommands = mkOption {
-
default = false;
-
type = types.bool;
-
description = ''
-
Whether to replicate command output of stage-1 booting to <filename>/dev/kmsg</filename> or <filename>/run/log/stage-2-init.log</filename> if <filename>/dev/kmsg</filename> is not writable.
-
'';
-
};
postBootCommands = mkOption {
default = "";