From 8f3d547516a9d1dc091e5bfdff89573439be47c1 Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Thu, 14 Jan 2021 21:07:23 +0100 Subject: [PATCH] Support grub compat setting for Ubuntu Ubuntu and Debian differ in the set of supported arguments for grub-install. Allow the users to ignore the difference and select their preferencein the yaml configuration file. Fixes: https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/1786699 Fixes: https://gitlab.com/larswirzenius/vmdb2/-/issues/36 Fixes: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=951766 Signed-off-by: Zygmunt Krynicki --- vmdb/plugins/grub.mdwn | 3 +++ vmdb/plugins/grub_plugin.py | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/vmdb/plugins/grub.mdwn b/vmdb/plugins/grub.mdwn index 645caf0..8360668 100644 --- a/vmdb/plugins/grub.mdwn +++ b/vmdb/plugins/grub.mdwn @@ -30,6 +30,9 @@ Step keys: * `timeout` — OPTIONAL; set the grub menu timeout, in seconds. Defaults to 0 seconds. +* `compat` — OPTIONAL; defaults to `debian`, accepts value `debian` + or `ubuntu` and controls specific arguments passed to `grub-install`. + Example (in the .vmdb file): - grub: bios diff --git a/vmdb/plugins/grub_plugin.py b/vmdb/plugins/grub_plugin.py index b081098..5a13936 100644 --- a/vmdb/plugins/grub_plugin.py +++ b/vmdb/plugins/grub_plugin.py @@ -93,6 +93,7 @@ class GrubStepRunner(vmdb.StepRunnerInterface): "image-dev": "", "quiet": False, "timeout": 0, + "compat": "", } def run(self, values, settings, state): @@ -177,19 +178,23 @@ class GrubStepRunner(vmdb.StepRunnerInterface): self.add_grub_serial_console(chroot) vmdb.runcmd_chroot(chroot, ["grub-mkconfig", "-o", "/boot/grub/grub.cfg"]) - vmdb.runcmd_chroot( - chroot, - [ - "grub-install", - "--target=" + grub_target, - "--no-nvram", - "--force-extra-removable", + args = [ + "grub-install", + "--target=" + grub_target, + "--no-nvram" + ] + compat = values["compat"] or "debian" + if compat == "debian": + args.append("--force-extra-removable") + elif compat == "ubuntu": + args.append("--no-extra-removable") + args.extend([ "--no-floppy", "--modules=part_msdos part_gpt", "--grub-mkdevicemap=/boot/grub/device.map", image_dev, - ], - ) + ]) + vmdb.runcmd_chroot(chroot, args) # self.unmount(state) -- 2.25.1