From be4ff60d9c022ebf1d010da8fd06f187dc40c3d9 Mon Sep 17 00:00:00 2001 From: afazekas Date: Thu, 1 Aug 2024 11:22:50 +0200 Subject: [PATCH] Not duplicate grub defaults The GRUB_TIMEOUT was duplicated in the /etc/grub/defaults. Changing the DIB_GRUB_TIMEOUT default to the base image typical default. Note: Hold shift if you want to interact with the grub menu. Change-Id: If4d5ae467706b98d89f9dd6714ef06a5933ccfb3 --- .../elements/bootloader/README.rst | 2 +- .../bootloader/finalise.d/50-bootloader | 27 ++++++++++++++----- .../notes/grub-timeout1-a3e48ac5da970499.yaml | 7 +++++ 3 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 releasenotes/notes/grub-timeout1-a3e48ac5da970499.yaml diff --git a/diskimage_builder/elements/bootloader/README.rst b/diskimage_builder/elements/bootloader/README.rst index e52cee4b1..1f1714681 100644 --- a/diskimage_builder/elements/bootloader/README.rst +++ b/diskimage_builder/elements/bootloader/README.rst @@ -8,7 +8,7 @@ Arguments ========= * ``DIB_GRUB_TIMEOUT`` sets the ``grub`` menu timeout. It defaults to - 5 seconds. Set this to 0 (no timeout) for fast boot times. + 1 seconds. Set this to 0 (no timeout) for fast boot times. * ``DIB_GRUB_TIMEOUT_STYLE`` sets the visibility of the ``grub`` menu. It defaults to ``hidden`` (or ``countdown`` as an alias). Set this to diff --git a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader index 6cfa2fcff..6ce9d9eb9 100755 --- a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader +++ b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader @@ -87,6 +87,19 @@ if [[ -L $GRUBENV ]]; then rm -f $GRUBENV fi +function append_or_replace { + local file=$1 + local key=$2 + local value=$3 + + if grep -q "^$key=" "$file"; then + sed -i "s/^$key=.*/$key=$value/" "$file" + else + echo $key=$value >>"$file" + fi +} + + # NOTE(TheJulia): Explicitly strip out embedded console settings # in the source's grub defaults. This prevents re-introduction later. # Intentionally matching 'console=ttyS0,115200n8 console=tty0' @@ -97,16 +110,16 @@ if [[ -f /etc/default/grub ]]; then sed -i 's/\> /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 +append_or_replace /etc/default/grub GRUB_DEVICE "LABEL=${DIB_ROOT_LABEL}" +append_or_replace /etc/default/grub GRUB_DISABLE_LINUX_UUID true +append_or_replace /etc/default/grub GRUB_TIMEOUT "${DIB_GRUB_TIMEOUT:-1}" +append_or_replace /etc/default/grub GRUB_TIMEOUT_STYLE "${DIB_GRUB_TIMEOUT_STYLE:-hidden}" if [[ "True" == "${DIB_BOOTLOADER_USE_SERIAL_CONSOLE:-True}" ]]; then - echo 'GRUB_TERMINAL="serial console"' >>/etc/default/grub + append_or_replace /etc/default/grub GRUB_TERMINAL \""serial console"\" else - echo 'GRUB_TERMINAL="console"' >>/etc/default/grub + append_or_replace /etc/default/grub GRUB_TERMINAL \"console\" fi -echo 'GRUB_GFXPAYLOAD_LINUX=auto' >>/etc/default/grub +append_or_replace /etc/default/grub GRUB_GFXPAYLOAD_LINUX auto # NOTE(TheJulia): We need to remove any boot entry from the /etc/default/grub # file that may already exist, such as what was added by fips being setup on diff --git a/releasenotes/notes/grub-timeout1-a3e48ac5da970499.yaml b/releasenotes/notes/grub-timeout1-a3e48ac5da970499.yaml new file mode 100644 index 000000000..84cef3e01 --- /dev/null +++ b/releasenotes/notes/grub-timeout1-a3e48ac5da970499.yaml @@ -0,0 +1,7 @@ +--- +upgrade: + - | + DIB_GRUB_TIMEOUT defaulting to 1 second, + GRUB_TIMEOUT was duplicated in the /etc/defaults/grub the original + intension of DIB_GRUB_TIMEOUT default was to match the typical image + default which is one 1 second instead of 5 second today.