[elbe-devel] [PATCH] Add support for hybrid images (UEFI+Bios)

John Ogness john.ogness at linutronix.de
Mon Mar 26 17:09:16 CEST 2018


On 2018-03-26, Martin Kaistra <martin.kaistra at linutronix.de> wrote:
> This patch adds the possibility to create images which
> can boot from UEFI as well as Bios.
>
> How to use:
> You need to add the packages grub-efi-amd64-bin and grub-pc
> and a small (1MiB should be enough) partition with <biosgrub> in
> addition to a standard UEFI image.
>
> Signed-off-by: Martin Kaistra <martin.kaistra at linutronix.de>
> ---
>  elbepack/elbeproject.py |  6 +++++-
>  elbepack/hdimg.py       | 15 +++++++++++++++
>  2 files changed, 20 insertions(+), 1 deletion(-)
>
> diff --git a/elbepack/elbeproject.py b/elbepack/elbeproject.py
> index 047020bc..1cb22ef5 100644
> --- a/elbepack/elbeproject.py
> +++ b/elbepack/elbeproject.py
> @@ -466,7 +466,11 @@ class ElbeProject (object):
>          # jessie and wheezy grubs are 2.0 but differ in behaviour
>          #
>          # We might also want support for legacy grub
> -        if self.get_rpcaptcache().is_installed('grub-pc'):
> +        if (self.get_rpcaptcache().is_installed('grub-pc') and
> +                self.get_rpcaptcache().is_installed('grub-efi-amd64-bin')):
> +            grub_version = 202
> +            grub_fw_type = "hybrid"
> +        elif self.get_rpcaptcache().is_installed('grub-pc'):
>              if self.codename == "wheezy":
>                  grub_version = 199
>              else:
> diff --git a/elbepack/hdimg.py b/elbepack/hdimg.py
> index f505208c..a84c0a5d 100644
> --- a/elbepack/hdimg.py
> +++ b/elbepack/hdimg.py
> @@ -190,6 +190,7 @@ class grubinstaller_base(object):
>          self.outf = outf
>          self.root = None
>          self.boot = None
> +        self.fw_type = None

Perhaps fw_type should be an argument of __init__() with a default value
of None? Then we would not need the set_fw_type() method and its call in
do_image_hd().

>      def set_boot_entry(self, entry):
>          print("setting boot entry")
> @@ -289,6 +290,9 @@ class grubinstaller202(grubinstaller_base):
>  
>  class grubinstaller202efi(grubinstaller_base):
>  
> +    def set_fw_type(self, fw_type):
> +        self.fw_type = fw_type
> +
>      def install(self, target):
>          if not self.root:
>              return
> @@ -340,6 +344,13 @@ class grubinstaller202efi(grubinstaller_base):
>                  "--removable --no-floppy /dev/poop0" %
>                  (imagemnt))
>  
> +            # when we are in hybrid mode, install grub also into MBR
> +            if self.fw_type == "hybrid":
> +                self.outf.do(
> +                    "chroot %s grub-install --target=i386-pc "
> +                    "--no-floppy /dev/poop0" %
> +                    (imagemnt))
> +
>          finally:
>              os.unlink(os.path.join(imagemnt, "boot/grub/device.map"))
>              self.outf.do(
> @@ -589,6 +600,10 @@ def do_image_hd(outf, hd, fslabel, target, grub_version, grub_fw_type):
>          grub = grubinstaller199(outf)
>      elif grub_version == 202 and grub_fw_type == "efi":
>          grub = grubinstaller202efi(outf)
> +        grub.set_fw_type("efi")
> +    elif grub_version == 202 and grub_fw_type == "hybrid":
> +        grub = grubinstaller202efi(outf)
> +        grub.set_fw_type("hybrid")
>      elif grub_version == 202:
>          grub = grubinstaller202(outf)
>      else:

John Ogness



More information about the elbe-devel mailing list