From 11275c212b3f2b8c936f07e7938dd81b2908faac Mon Sep 17 00:00:00 2001
From: Yolanda Robla <yroblamo@redhat.com>
Date: Wed, 8 Mar 2017 14:39:55 +0100
Subject: [PATCH] Send custom parameters in bootloader to GRUB_CMDLINE

Depending on the types of deployment (security, nfv...) some extra
kernel flags are needed on the images. This change exposes the
DIB_BOOTLOADER_DEFAULT_CMDLINE parameter, defaulting to the
existing 'nofb nomodeset vga=normal', that will allow to modify
these boot params.

Change-Id: I67d191fa5ca44a57f776cb9739a02dd71212969c
Closes-Bug: #1668890
---
 diskimage_builder/elements/bootloader/README.rst            | 4 ++++
 .../bootloader/environment.d/10-bootloader-default-cmdline  | 1 +
 .../elements/bootloader/finalise.d/50-bootloader            | 6 +++---
 3 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline

diff --git a/diskimage_builder/elements/bootloader/README.rst b/diskimage_builder/elements/bootloader/README.rst
index 86f759143..4baf6eaec 100644
--- a/diskimage_builder/elements/bootloader/README.rst
+++ b/diskimage_builder/elements/bootloader/README.rst
@@ -12,3 +12,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.
+
+* ``DIB_BOOTLOADER_DEFAULT_CMD_LINE`` sets the CMDLINE parameters that
+  are appended to the grub.cfg configuration. It defaults to
+  'nofb nomodeset vga=normal'
diff --git a/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline b/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline
new file mode 100644
index 000000000..902494b43
--- /dev/null
+++ b/diskimage_builder/elements/bootloader/environment.d/10-bootloader-default-cmdline
@@ -0,0 +1 @@
+export DIB_BOOTLOADER_DEFAULT_CMDLINE=${DIB_BOOTLOADER_DEFAULT_CMDLINE:-"nofb nomodeset vga=normal"}
diff --git a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader
index d1f540923..a23086603 100755
--- a/diskimage_builder/elements/bootloader/finalise.d/50-bootloader
+++ b/diskimage_builder/elements/bootloader/finalise.d/50-bootloader
@@ -144,14 +144,14 @@ function install_grub2 {
     DISTRO_NAME=${DISTRO_NAME:-}
     case $DISTRO_NAME in
         'ubuntu'|'debian')
-            sed -i -e 's/\(^GRUB_CMDLINE_LINUX.*\)"$/\1 nofb nomodeset vga=normal"/' /etc/default/grub
+            sed -i -e "s/\(^GRUB_CMDLINE_LINUX.*\)\"$/\1 ${DIB_BOOTLOADER_DEFAULT_CMDLINE}\"/" /etc/default/grub
             GRUB_MKCONFIG=update-grub
         ;;
         'fedora'|'centos7'|'centos')
-            echo 'GRUB_CMDLINE_LINUX="nofb nomodeset vga=normal"' >>/etc/default/grub
+            echo "GRUB_CMDLINE_LINUX=\"${DIB_BOOTLOADER_DEFAULT_CMDLINE}\"" >>/etc/default/grub
         ;;
         'opensuse')
-            sed -i -e 's/\(^GRUB_CMDLINE_LINUX.*\)"$/\1 nofb nomodeset vga=normal"/' /etc/default/grub
+            sed -i -e "s/\(^GRUB_CMDLINE_LINUX.*\)\"$/\1 ${DIB_BOOTLOADER_DEFAULT_CMDLINE}\"/" /etc/default/grub
         ;;
     esac