From deae4eff7b837a51699a10e499c3dc7311fd3ef1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 23 Feb 2016 11:53:37 +0100 Subject: [PATCH] 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). --- nixos/modules/system/boot/stage-1-init.sh | 34 +++++++++++------------ nixos/modules/system/boot/stage-1.nix | 12 ++------ nixos/modules/system/boot/stage-2-init.sh | 30 +++++++++----------- nixos/modules/system/boot/stage-2.nix | 10 +------ 4 files changed, 33 insertions(+), 53 deletions(-) diff --git a/nixos/modules/system/boot/stage-1-init.sh b/nixos/modules/system/boot/stage-1-init.sh index 94cecdf1fd7..7a4c93e8a0f 100644 --- a/nixos/modules/system/boot/stage-1-init.sh +++ b/nixos/modules/system/boot/stage-1-init.sh @@ -71,24 +71,24 @@ mount -t devtmpfs -o "size=@devSize@" devtmpfs /dev 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 diff --git a/nixos/modules/system/boot/stage-1.nix b/nixos/modules/system/boot/stage-1.nix index 45652b355c8..f31620df1d8 100644 --- a/nixos/modules/system/boot/stage-1.nix +++ b/nixos/modules/system/boot/stage-1.nix @@ -200,8 +200,8 @@ let 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); @@ -269,14 +269,6 @@ in ''; }; - boot.initrd.logCommands = mkOption { - default = false; - type = types.bool; - description = '' - Whether to replicate command output of stage-1 booting to /dev/kmsg or /run/log/stage-1-init.log if /dev/kmsg is not writable. - ''; - }; - boot.initrd.prepend = mkOption { default = [ ]; type = types.listOf types.str; diff --git a/nixos/modules/system/boot/stage-2-init.sh b/nixos/modules/system/boot/stage-2-init.sh index 17b24e1678b..9b34d24bdbc 100644 --- a/nixos/modules/system/boot/stage-2-init.sh +++ b/nixos/modules/system/boot/stage-2-init.sh @@ -157,18 +157,16 @@ mount -t tmpfs -o "mode=0755" tmpfs /var/setuid-wrappers # 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 @@ -199,11 +197,9 @@ ln -sfn /run/booted-system /nix/var/nix/gcroots/booted-system @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. diff --git a/nixos/modules/system/boot/stage-2.nix b/nixos/modules/system/boot/stage-2.nix index 32281e63af2..c0ef4e02d1f 100644 --- a/nixos/modules/system/boot/stage-2.nix +++ b/nixos/modules/system/boot/stage-2.nix @@ -17,7 +17,7 @@ let 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; @@ -40,14 +40,6 @@ in boot = { - logCommands = mkOption { - default = false; - type = types.bool; - description = '' - Whether to replicate command output of stage-1 booting to /dev/kmsg or /run/log/stage-2-init.log if /dev/kmsg is not writable. - ''; - }; - postBootCommands = mkOption { default = ""; example = "rm -f /var/log/messages";