lib.sh: rm Ubuntu boot entry on EFI systems 33/46433/1
authorAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Thu, 24 Aug 2017 02:09:59 +0000 (04:09 +0200)
committerAlexandru Avadanii <Alexandru.Avadanii@enea.com>
Mon, 30 Oct 2017 17:16:10 +0000 (17:16 +0000)
On EFI-enabled systems, grub-install from grub-efi-* package
installs a boot entry named "ubuntu".

MaaS relies on IPMI to set boot order to PXE first; however
on systems with buggy firmware or without full IPMI support,
that fails, leading to booting Ubuntu from hard disk instead.

Work around this by clearing any previous Ubuntu boot entry
from board flash, before starting a new baremetal deploy.

NOTE: This only runs against nodes that are online from a
previous deploy.

Closes: ARMBAND-47

Change-Id: I1c4ece09e42845ce2a1b7119ec69e46e5ca12376
Signed-off-by: Alexandru Avadanii <Alexandru.Avadanii@enea.com>
(cherry picked from commit 4e2c736cce578d1073dab0e0960b524b1dcc663a)

mcp/scripts/lib.sh

index b4d45dd..6b7193b 100644 (file)
@@ -35,6 +35,15 @@ function get_base_image {
   wget -P "${image_dir}" -N "${base_image}"
 }
 
+function cleanup_uefi {
+  # Clean up Ubuntu boot entry if cfg01, kvm nodes online from previous deploy
+  # shellcheck disable=SC2086
+  ssh ${SSH_OPTS} "${SSH_SALT}" "sudo salt -C 'kvm* or cmp*' cmd.run \
+    \"which efibootmgr > /dev/null 2>&1 && \
+    efibootmgr | grep -oP '(?<=Boot)[0-9]+(?=.*ubuntu)' | \
+    xargs -I{} efibootmgr --delete-bootnum --bootnum {}\"" || true
+}
+
 function cleanup_vms {
   # clean up existing nodes
   for node in $(virsh list --name | grep -P '\w{3}\d{2}'); do
@@ -52,6 +61,7 @@ function prepare_vms {
   local image_dir=$1; shift
   local vnodes=("$@")
 
+  cleanup_uefi
   cleanup_vms
   get_base_image "${base_image}" "${image_dir}"
   # shellcheck disable=SC2016