[elbe-devel] [PATCH v2 2/4] Add support for UEFI boot with grub
Torben Hohn
torben.hohn at linutronix.de
Thu Mar 29 10:10:25 CEST 2018
On Wed, Mar 28, 2018 at 02:16:54PM +0200, Martin Kaistra wrote:
> If the package grub-efi-amd64 is installed and <grub-install/> is
> used in the xml, try to install grub on the boot partition
> to the default fallback location \EFI\boot\bootx64.efi
>
> Use grub_fw_type to differentiate between "bios" and "efi", so we can
> pass that to the grub installer function.
>
> This is currently specific to amd64, but it shouldn't be too difficult
> to expand it to other target platforms which support uefi.
>
> Signed-off-by: Martin Kaistra <martin.kaistra at linutronix.de>
Reviewed-by: Torben Hohn <torben.hohn at linutronix.de>
> ---
> elbepack/efilesystem.py | 5 +++--
> elbepack/elbeproject.py | 8 +++++++-
> elbepack/hdimg.py | 37 +++++++++++++++++++++++++++++--------
> 3 files changed, 39 insertions(+), 11 deletions(-)
>
> diff --git a/elbepack/efilesystem.py b/elbepack/efilesystem.py
> index e1bab181..a2781b5f 100644
> --- a/elbepack/efilesystem.py
> +++ b/elbepack/efilesystem.py
> @@ -309,7 +309,7 @@ class TargetFs(ChRootFilesystem):
> f.write(fstab.get_str())
> f.close()
>
> - def part_target(self, targetdir, grub_version):
> + def part_target(self, targetdir, grub_version, grub_fw_type):
>
> # create target images and copy the rfs into them
> self.images = do_hdimg(
> @@ -317,7 +317,8 @@ class TargetFs(ChRootFilesystem):
> self.xml,
> targetdir,
> self,
> - grub_version)
> + grub_version,
> + grub_fw_type)
>
> if self.xml.has("target/package/tar"):
> targz_name = self.xml.text("target/package/tar/name")
> diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
> index be2b25f5..047020bc 100644
> --- a/elbepack/elbeproject.py
> +++ b/elbepack/elbeproject.py
> @@ -471,15 +471,21 @@ class ElbeProject (object):
> grub_version = 199
> else:
> grub_version = 202
> + grub_fw_type = "bios"
> + elif self.get_rpcaptcache().is_installed('grub-efi-amd64'):
> + grub_version = 202
> + grub_fw_type = "efi"
> elif self.get_rpcaptcache().is_installed('grub-legacy'):
> self.log.printo("package grub-legacy is installed, "
> "this is obsolete, skipping grub")
> grub_version = 0
> + grub_fw_type = ""
> else:
> self.log.printo("package grub-pc is not installed, skipping grub")
> # version 0 == skip_grub
> grub_version = 0
> - self.targetfs.part_target(self.builddir, grub_version)
> + grub_fw_type = ""
> + self.targetfs.part_target(self.builddir, grub_version, grub_fw_type)
>
> # Build cdrom images
> self.repo_images = []
> diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
> index e1dc2aae..ddc3138c 100644
> --- a/elbepack/hdimg.py
> +++ b/elbepack/hdimg.py
> @@ -186,10 +186,11 @@ def size_to_int(size):
>
>
> class grubinstaller_base(object):
> - def __init__(self, outf):
> + def __init__(self, outf, fw_type="bios"):
> self.outf = outf
> self.root = None
> self.boot = None
> + self.fw_type = fw_type
>
> def set_boot_entry(self, entry):
> print("setting boot entry")
> @@ -249,9 +250,15 @@ class grubinstaller202(grubinstaller_base):
> self.outf.do("chroot %s update-initramfs -u -k all" % imagemnt)
> self.outf.do("chroot %s update-grub2" % imagemnt)
>
> - self.outf.do(
> - "chroot %s grub-install --no-floppy /dev/poop0" %
> - (imagemnt))
> + if self.fw_type == "efi":
> + self.outf.do(
> + "chroot %s grub-install --target=x86_64-efi --removable "
> + "--efi-directory=/boot --no-floppy /dev/poop0" %
> + (imagemnt))
> + else:
> + self.outf.do(
> + "chroot %s grub-install --no-floppy /dev/poop0" %
> + (imagemnt))
>
> finally:
> os.unlink(os.path.join(imagemnt, "boot/grub/device.map"))
> @@ -480,7 +487,7 @@ def create_logical_partitions(
> current_sector += lpart.getLength()
>
>
> -def do_image_hd(outf, hd, fslabel, target, grub_version):
> +def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type):
>
> sector_size = 512
> s = size_to_int(hd.text("size"))
> @@ -500,6 +507,8 @@ def do_image_hd(outf, hd, fslabel, target, grub_version):
>
> if grub_version == 199:
> grub = grubinstaller199(outf)
> + elif grub_version == 202 and grub_fw_type == "efi":
> + grub = grubinstaller202(outf, "efi")
> elif grub_version == 202:
> grub = grubinstaller202(outf)
> else:
> @@ -574,7 +583,7 @@ def add_binary_blob(outf, hd, target):
> bs))
>
>
> -def do_hdimg(outf, xml, target, rfs, grub_version):
> +def do_hdimg(outf, xml, target, rfs, grub_version, grub_fw_type):
> # list of created files
> img_files = []
>
> @@ -623,11 +632,23 @@ def do_hdimg(outf, xml, target, rfs, grub_version):
> # Now iterate over all images and create filesystems and partitions
> for i in xml.tgt.node("images"):
> if i.tag == "msdoshd":
> - img = do_image_hd(outf, i, fslabel, target, grub_version)
> + img = do_image_hd(
> + outf,
> + i,
> + fslabel,
> + target,
> + grub_version,
> + grub_fw_type)
> img_files.append(img)
>
> if i.tag == "gpthd":
> - img = do_image_hd(outf, i, fslabel, target, grub_version)
> + img = do_image_hd(
> + outf,
> + i,
> + fslabel,
> + target,
> + grub_version,
> + grub_fw_type)
> img_files.append(img)
>
> if i.tag == "mtd":
> --
> 2.11.0
>
>
> _______________________________________________
> elbe-devel mailing list
> elbe-devel at linutronix.de
> https://lists.linutronix.de/mailman/listinfo/elbe-devel
--
Mit freundlichen Grüßen
Torben Hohn
Linutronix GmbH
Standort: Bremen
Phone: +49 7556 25 999 18; Fax.: +49 7556 25 999 99
Firmensitz / Registered Office: D-88690 Uhldingen, Bahnhofstr. 3
Registergericht / Local District Court: Amtsgericht Freiburg i. Br.; HRB
Nr. / Trade register no.: 700 806
Geschäftsführer / Managing Directors: Heinz Egger, Thomas Gleixner
Eine Bitte von uns: Sollten Sie diese E-Mail irrtümlich erhalten haben,
benachrichtigen Sie uns in diesem Falle bitte sobald wie es Ihnen
möglich ist, durch Antwort-Mail. Vielen Dank!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.linutronix.de/pipermail/elbe-devel/attachments/20180329/44848709/attachment-0001.sig>
More information about the elbe-devel
mailing list