nixos/stage-1: Added boot.initrd.logCommands

authored by Roger Qiu and committed by Eelco Dolstra 142f65e0 8b3d057c

+36 -2
+26
nixos/modules/system/boot/stage-1-init.sh
··· 71 71 mkdir -p /run 72 72 mount -t tmpfs -o "mode=0755,size=@runSize@" tmpfs /run 73 73 74 + # Optionally log the script output to /dev/kmsg or /run/log/stage-1-init.log 75 + if test -n "@logCommands@"; then 76 + mkdir -p /tmp 77 + mkfifo /tmp/stage-1-init.log.fifo 78 + logOutFd=8 && logErrFd=9 79 + eval "exec $logOutFd>&1 $logErrFd>&2" 80 + if test -w /dev/kmsg; then 81 + tee -i < /tmp/stage-1-init.log.fifo /proc/self/fd/"$logOutFd" | while read line; do 82 + if test -n "$line"; then 83 + echo "stage-1-init: $line" > /dev/kmsg 84 + fi 85 + done & 86 + else 87 + mkdir -p /run/log 88 + tee -i < /tmp/stage-1-init.log.fifo /run/log/stage-1-init.log & 89 + fi 90 + exec > /tmp/stage-1-init.log.fifo 2>&1 91 + fi 74 92 75 93 # Process the kernel command line. 76 94 export stage2Init=/init ··· 414 432 415 433 # Stop udevd. 416 434 udevadm control --exit 435 + 436 + # Reset the logging file descriptors. 437 + # Do this just before pkill, which will kill the tee process. 438 + if test -n "@logCommands@" 439 + then 440 + exec 1>&$logOutFd 2>&$logErrFd 441 + eval "exec $logOutFd>&- $logErrFd>&-" 442 + fi 417 443 418 444 # Kill any remaining processes, just to be sure we're not taking any 419 445 # with us into stage 2. But keep storage daemons like unionfs-fuse.
+10 -2
nixos/modules/system/boot/stage-1.nix
··· 200 200 201 201 inherit (config.boot) resumeDevice devSize runSize; 202 202 203 - inherit (config.boot.initrd) checkJournalingFS 204 - preLVMCommands preDeviceCommands postDeviceCommands postMountCommands kernelModules; 203 + inherit (config.boot.initrd) checkJournalingFS 204 + logCommands preLVMCommands preDeviceCommands postDeviceCommands postMountCommands kernelModules; 205 205 206 206 resumeDevices = map (sd: if sd ? device then sd.device else "/dev/disk/by-label/${sd.label}") 207 207 (filter (sd: (sd ? label || hasPrefix "/dev/" sd.device) && !sd.randomEncryption) config.swapDevices); ··· 266 266 Specify here the device where the file resides. 267 267 You should also use <varname>boot.kernelParams</varname> to specify 268 268 <literal><replaceable>resume_offset</replaceable></literal>. 269 + ''; 270 + }; 271 + 272 + boot.initrd.logCommands = mkOption { 273 + default = false; 274 + type = types.bool; 275 + description = '' 276 + 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. 269 277 ''; 270 278 }; 271 279