From 69187bae3fa85cbb5de9ed61f11de4fb7a3095be Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Thu, 20 Jun 2024 14:06:43 -0700 Subject: [PATCH] Provide an ability to disable serial console injection By default, we attempt to inject a serial console, which may, or may not be needed, for example, Centos Stream 9 cloud images already configure a console setting, and repeating it just might be undesirable and cause workload performance degredation if the kernel or an application has to report anything to a console. This change generally results in original console entries being preserved, which might actually be a bug and get fixed in a latter patch. Generally, users of dib *should* likely be specific what they want to do with their console setting, and without setting the new DIB_BOOTLOADER_USE_SERIAL_CONSOLE paramter to false, the default will be adhered to, and any pre-existing serial console entries will *not* be de-duplicated from the base image. That too is *likely* a bug, but a harder one to fix. Change-Id: Icdfb5ed021b1a91e2de3c9a22bb2ff7fe9882bcd --- .../elements/bootloader/README.rst | 3 ++ .../10-bootloader-default-cmdline | 1 + .../bootloader/finalise.d/50-bootloader | 33 ++++++++++++------- ...sable-serial-console-d6aaa42ef3031d86.yaml | 6 ++++ 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 releasenotes/notes/bootloader-disable-serial-console-d6aaa42ef3031d86.yaml diff --git a/diskimage_builder/elements/bootloader/README.rst b/diskimage_builder/elements/bootloader/README.rst index fe479260d..e52cee4b1 100644 --- a/diskimage_builder/elements/bootloader/README.rst +++ b/diskimage_builder/elements/bootloader/README.rst @@ -19,6 +19,9 @@ Arguments to the ``GRUB_CMDLINE_LINUX_DEFAULT`` values in ``grub.cfg`` configuration. It defaults to ``nofb nomodeset gfxpayload=text``. +* ``DIB_BOOTLOADER_USE_SERIAL_CONSOLE`` allows usage of a serial console + to be disabled in the resulting image by setting to a value of ``False``. + * ``DIB_BOOTLOADER_SERIAL_CONSOLE`` sets the serial device to be used as a console. It defaults to ``hvc0`` for PowerPC, ``ttyAMA0,115200`` for ARM64, otherwise ``ttyS0,115200``. diff --git a/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline b/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline index b2201fc5c..c0f7e779b 100644 --- a/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline +++ b/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline @@ -8,3 +8,4 @@ else export DIB_BOOTLOADER_VIRTUAL_TERMINAL=${DIB_BOOTLOADER_VIRTUAL_TERMINAL} fi export DIB_NO_TIMER_CHECK=${DIB_NO_TIMER_CHECK:-"True"} +export DIB_BOOTLOADER_USE_SERIAL_CONSOLE=${DIB_BOOTLOADER_USE_SERIAL_CONSOLE:-"True"} diff --git a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader index cfedd9b3e..b9a53801d 100755 --- a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader +++ b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader @@ -91,7 +91,11 @@ echo "GRUB_DEVICE=LABEL=${DIB_ROOT_LABEL}" >> /etc/default/grub echo 'GRUB_DISABLE_LINUX_UUID=true' >> /etc/default/grub echo "GRUB_TIMEOUT=${DIB_GRUB_TIMEOUT:-5}" >>/etc/default/grub echo "GRUB_TIMEOUT_STYLE=${DIB_GRUB_TIMEOUT_STYLE:-hidden}" >>/etc/default/grub -echo 'GRUB_TERMINAL="serial console"' >>/etc/default/grub +if [[ "True" == "${DIB_BOOTLOADER_USE_SERIAL_CONSOLE:-True}" ]]; then + echo 'GRUB_TERMINAL="serial console"' >>/etc/default/grub +else + echo 'GRUB_TERMINAL="console"' >>/etc/default/grub +fi echo 'GRUB_GFXPAYLOAD_LINUX=auto' >>/etc/default/grub # NOTE(TheJulia): We need to remove any boot entry from the /etc/default/grub @@ -139,16 +143,19 @@ if [[ -x /bin/fips-mode-setup ]]; then fi - -if [[ -n "${DIB_BOOTLOADER_SERIAL_CONSOLE}" ]]; then - SERIAL_CONSOLE="console=${DIB_BOOTLOADER_SERIAL_CONSOLE}" -elif [[ "powerpc ppc64 ppc64le" =~ "$ARCH" ]]; then - # Serial console on Power is hvc0 - SERIAL_CONSOLE="console=hvc0" -elif [[ "arm64" =~ "$ARCH" ]]; then - SERIAL_CONSOLE="console=ttyAMA0,115200" +if [[ "True" == "${DIB_BOOTLOADER_USE_SERIAL_CONSOLE:-True}" ]]; then + if [[ -n "${DIB_BOOTLOADER_SERIAL_CONSOLE}" ]]; then + SERIAL_CONSOLE="console=${DIB_BOOTLOADER_SERIAL_CONSOLE}" + elif [[ "powerpc ppc64 ppc64le" =~ "$ARCH" ]]; then + # Serial console on Power is hvc0 + SERIAL_CONSOLE="console=hvc0" + elif [[ "arm64" =~ "$ARCH" ]]; then + SERIAL_CONSOLE="console=ttyAMA0,115200" + else + SERIAL_CONSOLE="console=ttyS0,115200" + fi else - SERIAL_CONSOLE="console=ttyS0,115200" + SERIAL_CONSOLE="" fi if [[ -n "${DIB_BOOTLOADER_VIRTUAL_TERMINAL}" ]]; then @@ -165,7 +172,11 @@ fi GRUB_CMDLINE_LINUX_DEFAULT="${VIRTUAL_TERMINAL} ${SERIAL_CONSOLE} ${NO_TIMER_CHECK}" echo "GRUB_CMDLINE_LINUX_DEFAULT=\"${GRUB_CMDLINE_LINUX_DEFAULT} ${DIB_BOOTLOADER_DEFAULT_CMDLINE}${BOOT_FS}${BOOT_FIPS}\"" >>/etc/default/grub -echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >>/etc/default/grub + + +if [[ "True" == "${DIB_BOOTLOADER_USE_SERIAL_CONSOLE:-True}" ]]; then + echo 'GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"' >>/etc/default/grub +fi # os-prober leaks /dev/sda into config file in dual-boot host # Disable grub-os-prober to avoid the issue while running diff --git a/releasenotes/notes/bootloader-disable-serial-console-d6aaa42ef3031d86.yaml b/releasenotes/notes/bootloader-disable-serial-console-d6aaa42ef3031d86.yaml new file mode 100644 index 000000000..2d4d14fd4 --- /dev/null +++ b/releasenotes/notes/bootloader-disable-serial-console-d6aaa42ef3031d86.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Adds the ability to disable serial console logging from being setup in + the ``bootloader`` element by setting the + ``DIB_BOOTLOADER_USE_SERIAL_CONSOLE`` environment variable to ``False``.