Add workaround for mkinitrd failing on CentOS7 19/53019/3
authorThanh Ha <thanh.ha@linuxfoundation.org>
Wed, 8 Mar 2017 16:59:38 +0000 (16:59 +0000)
committerThanh Ha <thanh.ha@linuxfoundation.org>
Thu, 9 Mar 2017 02:20:04 +0000 (21:20 -0500)
Sometimes yum update fails to produce a working grub config as the
kernel install fails to build mkinitrd. This workaround introduces a
loop to reinstall the kernel if grub.conf is missing the initramfs line
which is an indication of the mkinitrd issue. The new function will
cause a packer failure via `exit 1` if the workaround did not work.

Change-Id: Ib498a610fdd6f082575495d1b56a57b5f1802321
Signed-off-by: Thanh Ha <thanh.ha@linuxfoundation.org>
packer/provision/baseline.sh

index 06e0ba75d8bedd3ba42cc967faaf69c38f19c968..7d8e8f25ee304e89daa4f36f17e2cd596744aaf8 100644 (file)
@@ -5,6 +5,26 @@
 # force any errors to cause the script and job to end in failure
 set -xeu -o pipefail
 
+ensure_kernel_install() {
+    # Workaround for mkinitrd failing on occassion.
+    # On CentOS 7 it seems like the kernel install can fail it's mkinitrd
+    # run quietly, so we may not notice the failure. This script retries for a
+    # few times before giving up.
+    initramfs_ver=$(rpm -q kernel | tail -1 | sed "s/kernel-/initramfs-/")
+    for i in $(seq 3); do
+        if grep "$initramfs_ver" /boot/grub/grub.conf; then
+            break
+        fi
+        echo "Kernel initrd missing. Retrying to install kernel..."
+        yum reinstall -y kernel
+    done
+    if ! grep "$initramfs_ver" /boot/grub/grub.conf; then
+        cat /boot/grub/grub.conf
+        echo "ERROR: Failed to install kernel."
+        exit 1
+    fi
+}
+
 rh_systems() {
     # Handle the occurance where SELINUX is actually disabled
     SELINUX=$(grep -E '^SELINUX=(disabled|permissive|enforcing)$' /etc/selinux/config)
@@ -50,12 +70,9 @@ EOF
     echo "---> Updating operating system"
     yum clean all
     yum install -y deltarpm
-
-    # Workaround for kernel panic issue that appears sometimes after kernel update
-    #     https://www.centos.org/forums/viewtopic.php?t=22425
-    yum remove -y kernel
     yum update -y
-    yum install -y kernel
+
+    ensure_kernel_install
 
     # add in components we need or want on systems
     echo "---> Installing base packages"