Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

efibootmgr is not called on the OEM expandable image #2140

Open
ignatenkobrain opened this issue May 15, 2022 · 3 comments
Open

efibootmgr is not called on the OEM expandable image #2140

ignatenkobrain opened this issue May 15, 2022 · 3 comments

Comments

@ignatenkobrain
Copy link
Collaborator

Problem description

I'm trying to build expandable image for our physical servers and apart from many other issues I have, this one looks like a missing feature.

Expected behaviour

When firmware=uefi, I would expect that some part of kiwi installation would call to efibootmgr to actually install the boot entry, sadly this does not happen =(

Steps to reproduce the behaviour

Build CentOS Stream 9 image with kiwi, with firmware=uefi and try to install it on a physical hardware.

OS and Software information

  • KIWI version: 9.24.34
  • Operating system: CentOS Stream 9 (Fedora 36 on build host)
  • OBS version: N/A
@ignatenkobrain
Copy link
Collaborator Author

@ignatenkobrain
Copy link
Collaborator Author

I think we should be able to check if efibootmgr is present in the image and from some dump dracut module we can call efibootmgr right away, it should not be a big deal.

@ignatenkobrain
Copy link
Collaborator Author

FTR this is how the helper script I use to run on the first boot:

#!/usr/bin/python3

import argparse
import json
import re
import shlex
import subprocess

LABEL = "CentOS Linux"


def remove(apply=False):
    r = subprocess.run(["efibootmgr"], check=True, capture_output=True, text=True)
    for l in r.stdout.splitlines():
        slot, label = l.split(None, 1)
        if label == LABEL:
            slot_id = re.match(r"^Boot([0-9a-fA-F]{4})", slot).group(1)
            cmd = ["efibootmgr", "-b", slot_id, "-B"]
            if apply:
                subprocess.run(
                    cmd,
                    check=True,
                    stdout=subprocess.DEVNULL,
                )
            else:
                print(shlex.join(cmd))


def add(apply=False):
    r = subprocess.run(
        ["lsblk", "-J", "-p", "-s"], check=True, capture_output=True, text=True
    )
    for bd in json.loads(r.stdout)["blockdevices"]:
        if "/boot/efi" in bd["mountpoints"]:
            disk = bd["children"][0]["name"]
            part_num = re.search(r"(\d+)$", bd["name"]).group(1)
            break
    else:
        raise Exception("Can't find /boot/efi mountpoint")

    cmd = [
        "efibootmgr",
        "-c",
        "-L",
        LABEL,
        "-d",
        disk,
        "-p",
        part_num,
        "-l",
        "\\EFI\\centos\\shimx64.efi",
    ]
    if apply:
        subprocess.run(
            cmd,
            check=True,
            stdout=subprocess.DEVNULL,
        )
    else:
        print(shlex.join(cmd))


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--apply", action="store_true")
    args = parser.parse_args()
    remove(args.apply)
    add(args.apply)


if __name__ == "__main__":
    main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants