Repository: cobbler/cobbler

Issue:
issues with EL7 + UEFI + Cobbler
Greetings,

I'm having a heck of a time with UEFI and would appreciate some help. I reached out on the [mailing list](https://groups.google.com/forum/#!forum/cobbler-users), but it is just crickets over there and there is no history to sort through.

I finally discovered the problem that I mentioned on the mailing list, I just don't know how to fix it. All my hosts are Scientific Linux 7.5.

Here's the short of it. If I use the cobbler loaders (even a forced upgrade), everything goes horribly wrong.

From the SL7.5 disk I copied BOOTX64.EFI -> /var/lib/cobbler/loaders/grub-el7-bootx64.efi and grubx64.efi -> /var/lib/cobbler/loaders/grubx64.efi (my hacky way to have cobbler sync those files too). I updated my dhcpd.template file to load grub-el7-bootx64.efi.

Now suddenly, I no longer have weird TFTP issues! Hooray!! But I can't get it to load the kickstart to provision! Ugh.

Well lets look. For some reason some of my hosts have files that look like this:
```
$ cat /var/lib/tftpboot/grub/01-3C-FD-FE-B2-5A-A3 
default=0
timeout=0
splashimage=(nd)/splash.xpm.gz
title local
	quit
```

Well, that is EFI...but nothing tells it to kickstart anything at all.

Other files look like this:
```$ cat /var/lib/tftpboot/grub/01-3C-FD-FE-B2-5C-A7 
default=0
timeout=0

title testhost02
    root (nd)
    kernel /images/SL-7.5-x86_64/vmlinuz  ksdevice=link lang=en_US kssendmac text  ks=http://192.168.1.3/cblr/svc/op/ks/system/testhost02
    initrd /images/SL-7.5-x86_64/initrd.img
```
Better. At least that is a grub menu...too bad that it is the WRONG one. 

So I wrote a nastly little script that basically figured out which host each of the Mac address are in cobbler and dumps out a GRUB2 file instead. Also, notice the new name AND LOWERCASE (ugh, that bit me hard...).
```
$ cat /var/lib/tftpboot/grub/grub.cfg-01-3c-fd-fe-b5-9a-a4
set default="1"

function load_video {
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod all_video
}

load_video
set gfxpayload=keep
insmod gzio
insmod part_gpt
insmod ext2

set timeout=3
### END /etc/grub.d/00_header ###

search --no-floppy --set=root -l 'Scientific-7.5-x86_64'

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Install Scientific 7.5' --class fedora --class gnu-linux --class gnu --class os {
	linuxefi /images/SL-7.5-x86_64/vmlinuz ksdevice=link lang=en_US kssendmac text  ks=http://192.168.1.3/cblr/svc/op/ks/system/testhost01
	initrdefi /images/SL-7.5-x86_64/initrd.img
}
```
HOORAY! <Insert heavenly rejoicing music here!>

My nodes now boot UEFI with cobbler!! After much dancing and rejoicing, I would really like to figure out how I can get cobbler to write out a correct GRUB2 menu instead of whatever it is  that it's doing now (since it isn't doing any one thing consistently with the nodes I have right now).

Can someone please help? Have I hit a bug with cobbler or am I just doing something wrong? I can't find anything in the docs that relates to EUFI or configuring GRUB2.

Thanks!


Discussion:
I need grub2 UEFI support too.
Qemu with tianocore ovmf PXE failed to boot with grub legacy, but worked with grub2.
FYI, the likely issue with grub2 is around the presentation of boot_loaders as defined in: `config/cobbler/distro_signatures.json`

Apparently only "ppc64" can use grub2 (which is absolutely not the case).  This may provide a starting point.
I will start looking at Grub2 support.

CentOS 7 and UEFI doesn't require Grub2 - But I have issues with HP Gen10 servers in UEFI-mode that has issues with the normal grub-x86_64.uefi loader.
DHCP config looks like:
```
        if option arch = 00:07 {
            # UEFI Client
	    filename = "grub/grub-x86_64.efi";
	} else {
            # BIOS Client
            filename "pxelinux.0";
        }
```
So either pxelinux or Grub (v1?) is loaded depending on Bios/Legacy or UEFI mode is configured.
I was running into this problem today too with my new HPE Gen 10 servers.  I finally found out the issue was cobbler get-loaders is not pulling down the latest UEFI loaders from cobbler.io.  get-loaders is actually pulling down F15 "grub-x86_64.efi" instead of F17.  If you pull down F17 it works just fine. 

md5sum compares:
f24175db5ffb572764c8cb545418bfd3:  grub-x86_64.efi-f17
3484decda055ec4660637ca12500faf7:  grub-x86_64.efi-f15/get-loaders

That said, I think work on a grub2 implementation is still the way to go ... especially with RHEL 8 around the corner.

I hope this helps someone.



actually, the efi loader is synced with the latest EL6 release version. (or
it should be)

On Wed, Jan 9, 2019 at 1:31 AM negregg <notifications@github.com> wrote:

> I was running into this problem today too with my new HPE Gen 10 servers.
> I finally found out the issue was cobbler get-loaders is not pulling down
> the latest UEFI loaders from cobbler.io. get-loaders is actually pulling
> down F15 "grub-x86_64.efi" instead of F17. If you pull down F17 it works
> just fine.
>
> md5sum compares:
> f24175db5ffb572764c8cb545418bfd3: grub-x86_64.efi-f17
> 3484decda055ec4660637ca12500faf7: grub-x86_64.efi-f15/get-loaders
>
> That said, I think work on a grub2 implementation is still the way to go
> ... especially with RHEL 8 around the corner.
>
> I hope this helps someone.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/cobbler/cobbler/issues/1904#issuecomment-452513929>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAwQopModE8YToyZcs5qcYdmWo43ZCeIks5vBThegaJpZM4UbpHJ>
> .
>

Hi,

I have a working Grub2 implementation which basically replaces Grub legacy for extended UEFI support.

If this match everybody needs, I can make a PR. Let me know.

Cheers!
Please do so, please target master and note that master is a bit broken
right now due to the python3 porting effort.
Many thanks in advance!!!

On Sun, Jan 13, 2019 at 1:30 PM MRinalducci <notifications@github.com>
wrote:

> Hi,
>
> I have a working Grub2 implementation which basically replaces Grub legacy
> for extended UEFI support.
>
> If this match everybody needs, I can make a PR. Let me know.
>
> Cheers!
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub
> <https://github.com/cobbler/cobbler/issues/1904#issuecomment-453825803>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAwQogWJwOfvtwnXUAMcxZaqgY-uzBO3ks5vCyb1gaJpZM4UbpHJ>
> .
>

Ok great!
I’ll do it in the next few days/weeks, when I have a working master.

Resolving patch:
diff --git a/cobbler/tftpgen.py b/cobbler/tftpgen.py
--- a/cobbler/tftpgen.py
+++ b/cobbler/tftpgen.py
@@ -253,7 +253,7 @@ def write_all_system_files(self, system, menu_items):
                 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())
+                grub_path = os.path.join(self.bootloc, "grub", f1.lower())
 
             elif working_arch.startswith("ppc"):
                 # Determine filename for system-specific bootloader config
@@ -404,10 +404,10 @@ def make_actual_pxe_menu(self):
         self.templar.render(template_data, metadata, outfile, None)
         template_src.close()
 
-        # Write the grub menu:
+        # Write the grub2 menu:
         metadata = {"grub_menu_items": menu_items['grub']}
-        outfile = os.path.join(self.bootloc, "grub", "efidefault")
-        template_src = open(os.path.join(self.settings.boot_loader_conf_template_dir, "efidefault.template"))
+        outfile = os.path.join(self.bootloc, "grub", "grub.cfg")
+        template_src = open(os.path.join(self.settings.boot_loader_conf_template_dir, "grub.cfg.template"))
         template_data = template_src.read()
         self.templar.render(template_data, metadata, outfile, None)
         template_src.close()
@@ -504,9 +504,9 @@ def write_pxe_file(self, filename, system, profile, distro, arch,
         if system:
             if format == "grub":
                 if system.netboot_enabled:
-                    template = os.path.join(self.settings.boot_loader_conf_template_dir, "grubsystem.template")
+                    template = os.path.join(self.settings.boot_loader_conf_template_dir, "grub2system.template")
                 else:
-                    local = os.path.join(self.settings.boot_loader_conf_template_dir, "grublocal.template")
+                    local = os.path.join(self.settings.boot_loader_conf_template_dir, "grub2local.template")
                     if os.path.exists(local):
                         template = local
             else:   # pxe
@@ -561,7 +561,7 @@ def write_pxe_file(self, filename, system, profile, distro, arch,
             if arch.startswith("arm"):
                 template = os.path.join(self.settings.boot_loader_conf_template_dir, "pxeprofile_arm.template")
             elif format == "grub":
-                template = os.path.join(self.settings.boot_loader_conf_template_dir, "grubprofile.template")
+                template = os.path.join(self.settings.boot_loader_conf_template_dir, "grub2profile.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.boot_loader_conf_template_dir, "pxeprofile_esxi.template")
diff --git a/cobbler/utils.py b/cobbler/utils.py
--- a/cobbler/utils.py
+++ b/cobbler/utils.py
@@ -210,7 +210,7 @@ def get_config_filename(sys, interface):
     mac = sys.get_mac_address(interface)
     ip = sys.get_ip_address(interface)
     if mac is not None and mac != "":
-        return "01-" + "-".join(mac.split(":")).lower()
+        return "grub.cfg-01-" + "-".join(mac.split(":")).lower()
     elif ip is not None and ip != "":
         return get_host_ip(ip)
     else:


Test patch: