ebba664
From 6ecc08eb02fc2f9e67c8a75eebab9b2d824d63e6 Mon Sep 17 00:00:00 2001
ebba664
From: "Brian C. Lane" <bcl@redhat.com>
ebba664
Date: Wed, 6 Mar 2019 09:54:38 -0800
ebba664
Subject: [PATCH 5/6] Recreate the BLS entries when using liveimg
ebba664
ebba664
If the source image (eg. tar) had no /boot mountpoint the BLS entry will
ebba664
not work on an installed system with /boot as a separate partition. So
ebba664
this patch does a few things to correct this:
ebba664
ebba664
 * Always make a new machine-id at the end of install
ebba664
 * Fix the tar --exclude lines to actually exclude the paths
ebba664
 * Remove any existing BLS entries from /boot/loader/entries/
ebba664
ebba664
The machine-id creation has to be done before calling grub2-set-default,
ebba664
grub2-mkconfig, or kernel-install so doing it in post_install is too late.
ebba664
---
ebba664
 pyanaconda/payload/livepayload.py | 37 ++++++++++++++++++++-----------
ebba664
 1 file changed, 24 insertions(+), 13 deletions(-)
ebba664
ebba664
diff --git a/pyanaconda/payload/livepayload.py b/pyanaconda/payload/livepayload.py
ebba664
index f8f473c61..993cae4b1 100644
ebba664
--- a/pyanaconda/payload/livepayload.py
ebba664
+++ b/pyanaconda/payload/livepayload.py
ebba664
@@ -170,7 +170,13 @@ class LiveImagePayload(Payload):
ebba664
 
ebba664
     def _create_rescue_image(self):
ebba664
         """Create the rescue initrd images for each installed kernel. """
ebba664
-        # Live needs to create the rescue image before bootloader is written
ebba664
+        # Always make sure the new system has a new machine-id, it won't boot without it
ebba664
+        # (and nor will some of the subsequent commands like grub2-mkconfig and kernel-install)
ebba664
+        log.info("Generating machine ID")
ebba664
+        if os.path.exists(util.getSysroot() + "/etc/machine-id"):
ebba664
+            os.unlink(util.getSysroot() + "/etc/machine-id")
ebba664
+        util.execInSysroot("systemd-machine-id-setup", [])
ebba664
+
ebba664
         if os.path.exists(util.getSysroot() + "/usr/sbin/new-kernel-pkg"):
ebba664
             use_nkp = True
ebba664
         else:
ebba664
@@ -198,18 +204,22 @@ class LiveImagePayload(Payload):
ebba664
 
ebba664
         super().post_install()
ebba664
 
ebba664
-        # Make sure the new system has a machine-id, it won't boot without it
ebba664
-        # (and nor will some of the subsequent commands)
ebba664
-        if not os.path.exists(util.getSysroot() + "/etc/machine-id"):
ebba664
-            log.info("Generating machine ID")
ebba664
-            util.execInSysroot("systemd-machine-id-setup", [])
ebba664
+        # Not using BLS configuration, skip it
ebba664
+        if os.path.exists(util.getSysroot() + "/usr/sbin/new-kernel-pkg"):
ebba664
+            return
ebba664
+
ebba664
+        # Remove any existing BLS entries, they will not match the new system's
ebba664
+        # machine-id or /boot mountpoint.
ebba664
+        for file in glob.glob(util.getSysroot() + "/boot/loader/entries/*.conf"):
ebba664
+            log.info("Removing old BLS entry: %s", file)
ebba664
+            os.unlink(file)
ebba664
 
ebba664
+        # Create new BLS entries for this system
ebba664
         for kernel in self.kernel_version_list:
ebba664
-            if not os.path.exists(util.getSysroot() + "/usr/sbin/new-kernel-pkg"):
ebba664
-                log.info("Regenerating BLS info for %s", kernel)
ebba664
-                util.execInSysroot("kernel-install", ["add",
ebba664
-                                                      kernel,
ebba664
-                                                      "/lib/modules/{0}/vmlinuz".format(kernel)])
ebba664
+            log.info("Regenerating BLS info for %s", kernel)
ebba664
+            util.execInSysroot("kernel-install", ["add",
ebba664
+                                                  kernel,
ebba664
+                                                  "/lib/modules/{0}/vmlinuz".format(kernel)])
ebba664
 
ebba664
     @property
ebba664
     def space_required(self):
ebba664
@@ -504,8 +514,9 @@ class LiveImageKSPayload(LiveImagePayload):
ebba664
         # preserve: ACL's, xattrs, and SELinux context
ebba664
         args = ["--selinux", "--acls", "--xattrs", "--xattrs-include", "*",
ebba664
                 "--exclude", "/dev/", "--exclude", "/proc/",
ebba664
-                "--exclude", "/sys/", "--exclude", "/run/", "--exclude", "/boot/*rescue*",
ebba664
-                "--exclude", "/etc/machine-id", "-xaf", self.image_path, "-C", util.getSysroot()]
ebba664
+                "--exclude", "/sys/", "--exclude", "/run/", "--exclude", "boot/*rescue*",
ebba664
+                "--exclude", "boot/loader", "--exclude", "boot/efi/loader",
ebba664
+                "--exclude", "etc/machine-id", "-xaf", self.image_path, "-C", util.getSysroot()]
ebba664
         try:
ebba664
             rc = util.execWithRedirect(cmd, args)
ebba664
         except (OSError, RuntimeError) as e:
ebba664
-- 
ebba664
2.21.0
ebba664