File support-grub2efi.patch of Package cobbler.10419

Index: cobbler-2.6.6/cobbler/pxegen.py
===================================================================
--- cobbler-2.6.6.orig/cobbler/pxegen.py
+++ cobbler-2.6.6/cobbler/pxegen.py
@@ -130,8 +130,13 @@ class PXEGen:
                 require_match=False, api=self.api, cache=False, logger=self.logger)
 
         # Copy grub EFI bootloaders if possible:
-        utils.copyfile_pattern('/var/lib/cobbler/loaders/grub*.efi', grub_dst,
-                require_match=False, api=self.api, cache=False, logger=self.logger)
+        try:
+            # *.efi copies also shim*.efi and MokManager.efi
+            utils.copyfile_pattern('/usr/lib64/efi/*.efi', grub_dst,
+                    require_match=False, api=self.api, cache=False, logger=self.logger)
+        except:
+            utils.copyfile_pattern('/var/lib/cobbler/loaders/grub*.efi', grub_dst,
+                    require_match=False, api=self.api, cache=False, logger=self.logger)
 
         pxegrub_imported = False
         if os.path.isdir(os.path.join(self.bootloc, 'boot')):
@@ -147,6 +152,12 @@ class PXEGen:
         grub2_ppc_src = '/var/lib/cobbler/loaders/grub2-ieee1275'
         if os.path.exists(grub2_ppc_src):
             shutil.copytree(grub2_ppc_src, grub2_ppc_dst)
+        # copy modules
+        for gdir in ['x86_64-efi', 'i386-pc']:
+            fullgdir = os.path.join('/usr/lib/grub2/', gdir)
+            fulldest = os.path.join(grub_dst, gdir)
+            if os.path.exists(fullgdir):
+                shutil.copytree(fullgdir, fulldest)
 
     def copy_images(self):
         """
@@ -297,12 +308,14 @@ class PXEGen:
 
             # for tftp only ...
             grub_path = None
+            grub2_path = None
             if working_arch in [ "i386", "x86", "x86_64", "arm", "standard"]:
                 # pxelinux wants a file named $name under pxelinux.cfg
                 f2 = os.path.join(self.bootloc, "pxelinux.cfg", f1)
 
                 # Only generating grub menus for these arch's:
                 grub_path = os.path.join(self.bootloc, "grub", f1.upper())
+                grub2_path = os.path.join(self.bootloc, "grub", "grub.cfg-{}".format(f1.upper()))
 
             elif working_arch == "ia64":
                 # elilo expects files to be named "$name.conf" in the root
@@ -330,8 +343,11 @@ class PXEGen:
                 if not image_based:
                     self.write_pxe_file(f2, system, profile, distro, working_arch, metadata=pxe_metadata)
                     if grub_path:
-                        self.write_pxe_file(grub_path, system, profile, distro, 
+                        self.write_pxe_file(grub_path, system, profile, distro,
                                 working_arch, format="grub")
+                    if grub2_path:
+                        self.write_pxe_file(grub2_path, system, profile, distro,
+                                working_arch, format="grub2")
                 else:
                     self.write_pxe_file(f2, system, None, None, working_arch, image=profile, metadata=pxe_metadata)
             else:
@@ -428,13 +444,11 @@ class PXEGen:
             if grub_contents is not None:
                 grub_menu_items = grub_menu_items + grub_contents + "\n"
 
-            # We add grub2 menu entries for SLE12+ ppc distros
-            if distro.arch.startswith("ppc") and distro.os_version.startswith("sles12"):
-                grub2_contents = self.write_pxe_file(filename=None, system=None,
-                        profile=profile, distro=distro,
-                        arch=distro.arch, include_header=False, format="grub2")
-                if grub2_contents is not None:
-                    grub2_menu_items = grub2_menu_items + grub2_contents + "\n"
+            grub2_contents = self.write_pxe_file(filename=None, system=None,
+                    profile=profile, distro=distro,
+                    arch=distro.arch, include_header=False, format="grub2")
+            if grub2_contents is not None:
+                grub2_menu_items = grub2_menu_items + grub2_contents + "\n"
 
             # For SLE11 we uses yaboot
             elif distro.arch.startswith("ppc"):
@@ -528,6 +542,14 @@ class PXEGen:
         self.templar.render(template_data, metadata, outfile, None)
         template_src.close()
 
+        # Write the grub2 menu:
+        metadata = { "grub2_menu_items" : menu_items['grub2'] }
+        outfile = os.path.join(self.bootloc, "grub", "grub.cfg")
+        template_src = open(os.path.join(self.settings.pxe_template_dir, "grub2efidefault.template"))
+        template_data = template_src.read()
+        self.templar.render(template_data, metadata, outfile, None)
+        template_src.close()
+
         # Write the grub2 ppc64le menu:
         metadata = { "grub2_menu_items" : menu_items['grub2'] }
         outfile = os.path.join(self.bootloc, "boot/ppc64le/grub2-ieee1275", "grub.cfg")
@@ -682,7 +704,14 @@ class PXEGen:
                     if os.path.exists(local):
                         template = local
             elif format == "grub2":
+                if arch.startswith("ppc"):
                     template = os.path.join(self.settings.pxe_template_dir,"grub2system_ppc.template")
+                elif system.netboot_enabled:
+                    template = os.path.join(self.settings.pxe_template_dir,"grub2efisystem.template")
+                else:
+                    local = os.path.join(self.settings.pxe_template_dir, "grub2efilocal.template")
+                    if os.path.exists(local):
+                        template = local
             elif format == "yaboot":
                     template = os.path.join(self.settings.pxe_template_dir,"pxesystem_ppc.template")
             else: # pxe
@@ -744,6 +773,8 @@ class PXEGen:
                 template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_arm.template")
             elif format == "grub":
                 template = os.path.join(self.settings.pxe_template_dir,"grubprofile.template")
+            elif format == "grub2":
+                template = os.path.join(self.settings.pxe_template_dir,"grub2efiprofile.template")
             elif distro and distro.os_version.startswith("esxi"):
                 # ESXi uses a very different pxe method, see comment above in the system section
                 template = os.path.join(self.settings.pxe_template_dir,"pxeprofile_esxi.template")
Index: cobbler-2.6.6/templates/pxe/grub2efidefault.template
===================================================================
--- /dev/null
+++ cobbler-2.6.6/templates/pxe/grub2efidefault.template
@@ -0,0 +1,41 @@
+with_gfx=0
+
+gfxmode=auto
+lang=en
+
+insmod gettext
+insmod tr
+
+color_normal=light-gray/black
+color_highlight=white/light-gray
+
+tr -s m1 ':' '-' $net_default_mac
+tr -s macstring -U $m1
+
+if [ -s "$prefix/grub.cfg-01-$macstring" ]; then
+  source "$prefix/grub.cfg-01-$macstring"
+else
+
+timeout=80
+
+menuentry "Boot from Hard Disk" --class opensuse --class gnu-linux --class gnu --class os {
+  if search --no-floppy --file /efi/boot/fallback.efi --set ; then
+    if [ -f /efi/opensuse/shim.efi ] ; then
+      chainloader /efi/opensuse/grub.efi
+    elif [ -f /efi/sles/shim.efi ] ; then
+      chainloader /efi/sles/grub.efi
+    elif [ -f /EFI/redhat/grub.efi ]; then
+      chainloader /EFI/redhat/grub.efi
+    elif [ -f /EFI/redhat/grubx64.efi ]; then
+      chainloader /EFI/redhat/grubx64.efi
+    elif [ -f /EFI/centos/grub.efi ]; then
+      chainloader /EFI/centos/grub.efi
+    elif [ -f /EFI/centos/grubx64.efi ]; then
+      chainloader /EFI/centos/grubx64.efi
+    fi
+  fi
+}
+
+$grub2_menu_items
+
+fi
Index: cobbler-2.6.6/templates/pxe/grub2efilocal.template
===================================================================
--- /dev/null
+++ cobbler-2.6.6/templates/pxe/grub2efilocal.template
@@ -0,0 +1,26 @@
+with_gfx=0
+
+gfxmode=auto
+lang=en
+
+timeout=1
+default=1
+
+menuentry "Boot from Hard Disk" --class opensuse --class gnu-linux --class gnu --class os {
+  if search --no-floppy --file /efi/boot/fallback.efi --set ; then
+    if [ -f /efi/opensuse/shim.efi ] ; then
+      chainloader /efi/opensuse/grub.efi
+    elif [ -f /efi/sles/shim.efi ] ; then
+      chainloader /efi/sles/grub.efi
+    elif [ -f /EFI/redhat/grub.efi ]; then
+      chainloader /EFI/redhat/grub.efi
+    elif [ -f /EFI/redhat/grubx64.efi ]; then
+      chainloader /EFI/redhat/grubx64.efi
+    elif [ -f /EFI/centos/grub.efi ]; then
+      chainloader /EFI/centos/grub.efi
+    elif [ -f /EFI/centos/grubx64.efi ]; then
+      chainloader /EFI/centos/grubx64.efi
+    fi
+  fi
+}
+
Index: cobbler-2.6.6/templates/pxe/grub2efiprofile.template
===================================================================
--- /dev/null
+++ cobbler-2.6.6/templates/pxe/grub2efiprofile.template
@@ -0,0 +1,6 @@
+menuentry '$profile_name' --class opensuse --class gnu-linux --class gnu --class os {
+  echo 'Loading kernel ...'
+  linuxefi $kernel_path $kernel_options
+  echo 'Loading initial ramdisk ...'
+  initrdefi $initrd_path
+}
Index: cobbler-2.6.6/templates/pxe/grub2efisystem.template
===================================================================
--- /dev/null
+++ cobbler-2.6.6/templates/pxe/grub2efisystem.template
@@ -0,0 +1,14 @@
+with_gfx=0
+
+gfxmode=auto
+lang=en
+
+timeout=1
+default=1
+
+menuentry 'linux' --class opensuse --class gnu-linux --class gnu --class os {
+  echo 'Loading kernel ...'
+  linuxefi $kernel_path $kernel_options
+  echo 'Loading initial ramdisk ...'
+  initrdefi $initrd_path
+}
openSUSE Build Service is sponsored by