[node-patches] Change in ovirt-node[ovirt-3.5]: Use efibootmgr and shim.efi instead of grub2-install

fabiand at redhat.com fabiand at redhat.com
Wed Feb 25 09:19:12 UTC 2015


Hello Ryan Barry,

I'd like you to do a code review.  Please visit

    https://gerrit.ovirt.org/38154

to review the following change.

Change subject: Use efibootmgr and shim.efi instead of grub2-install
......................................................................

Use efibootmgr and shim.efi instead of grub2-install

grub2 got broken out into subpackages on 7.1, but it turns out
that we can't SecureBoot without the shim anyway. Use the shim
loader instead of plain grub.

To facilitate this, always use "linuxefi" and "initrdefi" on EFI
systems, since the shim doesn't provide non-efi primitives

Change-Id: I783c140487e44910b01edaf13d0f430b00c29e4a
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1192786
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirtnode/install.py
1 file changed, 51 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/54/38154/1

diff --git a/src/ovirtnode/install.py b/src/ovirtnode/install.py
index 410f397..e1dbea1 100755
--- a/src/ovirtnode/install.py
+++ b/src/ovirtnode/install.py
@@ -233,16 +233,16 @@
 menuentry "%(product)s %(version)s-%(release)s" {
 set root=(hd0,%(partN)d)
 search --no-floppy --label Root --set root
-linux /vmlinuz0 %(root_param)s %(bootparams)s
-initrd /initrd0.img
+%(linux)s /vmlinuz0 %(root_param)s %(bootparams)s
+%(initrd)s /initrd0.img
 }"""
 
         GRUB2_BACKUP_TEMPLATE = """
 menuentry "BACKUP %(oldtitle)s" {
 set root=(hd0,%(partB)d)
 search --no-floppy --label RootBackup --set root
-linux /vmlinuz0 root=live:LABEL=RootBackup %(bootparams)s
-initrd /initrd0.img
+%(linux)s /vmlinuz0 root=live:LABEL=RootBackup %(bootparams)s
+%(initrd)s /initrd0.img
 }    """
         if _functions.is_iscsi_install():
             disk = re.sub("p[1,2,3]$", "", \
@@ -252,33 +252,53 @@
             disk = self.disk
         if _functions.is_efi_boot():
             boot_dir = self.initrd_dest + "/efi"
+            self.grub_dict["linux"] = "linuxefi"
+            self.grub_dict["initrd"] = "initrdefi"
         else:
             boot_dir = self.initrd_dest
-        grub_setup_cmd = ("/sbin/grub2-install " + disk +
-                          " --boot-directory=" + boot_dir +
-                          " --root-directory=" + boot_dir +
-                          " --efi-directory=" + boot_dir +
-                          " --bootloader-id=" + self.efi_dir_name +
-                          " --force")
-        _functions.system("echo '%s' >> /liveos/efi/cmd" % grub_setup_cmd)
-        logger.info(grub_setup_cmd)
-        grub_setup = _functions.subprocess_closefds(grub_setup_cmd, \
-                                         shell=True,
-                                         stdout=subprocess.PIPE,
-                                         stderr=subprocess.STDOUT)
-        grub_results, grub_err = grub_setup.communicate()
-        logger.info(grub_results)
-        if grub_setup.wait() != 0 or "Error" in grub_results:
-            logger.error("grub2-install Failed")
-            return False
+        if not _functions.is_efi_boot():
+            grub_setup_cmd = ("/sbin/grub2-install " + disk +
+                              " --boot-directory=" + boot_dir +
+                              " --root-directory=" + boot_dir +
+                              " --efi-directory=" + boot_dir +
+                              " --bootloader-id=" + self.efi_dir_name +
+                              " --force")
+            _functions.system("echo '%s' >> /liveos/efi/cmd" % grub_setup_cmd)
+            logger.info(grub_setup_cmd)
+            grub_setup = _functions.subprocess_closefds(grub_setup_cmd, \
+                                             shell=True,
+                                             stdout=subprocess.PIPE,
+                                             stderr=subprocess.STDOUT)
+            grub_results, grub_err = grub_setup.communicate()
+            logger.info(grub_results)
+            if grub_setup.wait() != 0 or "Error" in grub_results:
+                logger.error("grub2-install Failed")
+                return False
         else:
-            logger.debug("Generating Grub2 Templates")
-            if _functions.is_efi_boot():
-                if not os.path.exists("/liveos/efi/EFI/%s" \
-                                      % self.efi_dir_name):
-                    os.makedirs("/liveos/efi/EFI/%s" % self.efi_dir_name)
-            grub_conf = open(self.grub_config_file, "w")
-            grub_conf.write(GRUB2_CONFIG_TEMPLATE % self.grub_dict)
+            efi_setup_cmd = (r'efibootmgr -c -L "RHEV-H" -l '
+                             r'"\EFI\redhat\shim.efi" -d %s -p 1' % disk)
+            _functions.system("echo '%s' >> /liveos/efi/cmd" % efi_setup_cmd)
+            logger.info(efi_setup_cmd)
+            efi_setup = _functions.subprocess_closefds(efi_setup_cmd,
+                                                       shell=True,
+                                                       stdout=subprocess.PIPE,
+                                                       stderr=subprocess.STDOUT
+                                                       )
+            efi_results, efi_err = efi_setup.communicate()
+            logger.info(efi_results)
+            if efi_setup.wait() != 0:
+                logger.error("efibootmgr setup failed")
+                return False
+            else:
+                shutil.copy("/boot/efi/EFI/redhat/shim.efi",
+                            "/liveos/efi/EFI/redhat/shim.efi")
+        logger.debug("Generating Grub2 Templates")
+        if _functions.is_efi_boot():
+            if not os.path.exists("/liveos/efi/EFI/%s" \
+                                  % self.efi_dir_name):
+                os.makedirs("/liveos/efi/EFI/%s" % self.efi_dir_name)
+        grub_conf = open(self.grub_config_file, "w")
+        grub_conf.write(GRUB2_CONFIG_TEMPLATE % self.grub_dict)
         if self.oldtitle is not None:
             partB = 0
             if self.partN == 0:
@@ -651,7 +671,9 @@
         "disk": self.disk,
         "grub_dir": self.grub_dir,
         "grub_prefix": self.grub_prefix,
-        "efi_hd": self.efi_hd
+        "efi_hd": self.efi_hd,
+        "linux": "linux",
+        "initrd": "initrd",
     }
         if not _functions.is_firstboot():
             if os.path.ismount("/live"):


-- 
To view, visit https://gerrit.ovirt.org/38154
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I783c140487e44910b01edaf13d0f430b00c29e4a
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: ovirt-3.5
Gerrit-Owner: Fabian Deutsch <fabiand at redhat.com>
Gerrit-Reviewer: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list