Skip to content

Commit

Permalink
Lower kernel log level to 4 before exiting initramfs
Browse files Browse the repository at this point in the history
Closes: coreos/fedora-coreos-tracker#1244

A lot going on for this simple service.  See the tracker issue above
for more info, but briefly:

Anaconda has historically injected `quiet` into the kernel command
line in many cases, and this suppresses *both* kernel and systemd
output.  On computers in general, but particularly many bare metal
servers, the serial console can be slow.  This can cause reliability
issues.

However for servers, we usually *do* want to see informational
output when they boot.  For example, today the kernel "mitigations"
information for hardware vulnerabilities is output.

This change is a compromise; we boot up at the kernel's default
verbosity level (which for Fedora and derivatives is the upstream 7),
but switch to 4 before exiting the initramfs.  At that point, we've
gotten most of the boot time output, and our initramfs is not
extremely performance sensitive right now.
  • Loading branch information
cgwalters committed Jul 13, 2022
1 parent 55c8d7c commit 1cd8115
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=CoreOS: Quiet printk after initramfs setup
Documentation=https://github.com/coreos/fedora-coreos-tracker/issues/1244
ConditionPathExists=/etc/initrd-release
After=initrd.target

[Service]
Type=oneshot
RemainAfterExit=yes
# Change the kernel to default to warning level
ExecStart=/bin/sh -c 'echo 4 > /proc/sys/kernel/printk'
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://issues.redhat.com/browse/RFE-2977 and
# https://github.com/coreos/fedora-coreos-tracker/issues/1244
# Basically, the current Fedora kernel log level is "7" which is quite
# high. We could change the kernel, and it's tempting to do so but
# there's some nontrivial potential fallout from that.
# As a compromise, we keep the default log level for the initramfs,
# but quiet it before switching to the real root. This will ensure
# we'll get most useful logging of bootup configuration.

check() {
return 0
}

install_unit() {
unit="$1"; shift
target="$1"; shift
inst_simple "$moddir/$unit" "$systemdsystemunitdir/$unit"
# note we `|| exit 1` here so we error out if e.g. the units are missing
# see https://github.com/coreos/fedora-coreos-config/issues/799
systemctl -q --root="$initdir" add-requires "$target" "$unit" || exit 1
}

install() {
install_unit coreos-printk-quiet.service initrd.target
}
16 changes: 16 additions & 0 deletions tests/kola/logging/printk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
# kola: { "exclusive": false }

# Verify fix for https://github.com/coreos/fedora-coreos-tracker/issues/1244

set -xeuo pipefail

. $KOLA_EXT_DATA/commonlib.sh

printk=$(cat /proc/sys/kernel/printk)

if ! [[ "$printk" =~ ^4 ]]; then
fatal "printk: expected console log level 4, found ${printk}"
fi

ok "Found expected printk value "

0 comments on commit 1cd8115

Please sign in to comment.