Patchwork [6/6] gnu: Add grub-efi.

login
register
mail settings
Submitter Marius Bakke
Date Dec. 16, 2016, 5:33 p.m.
Message ID <87y3zfrd7j.fsf@kirby.i-did-not-set--mail-host-address--so-tickle-me>
Download mbox | patch
Permalink /patch/18519/
State New
Headers show

Comments

Marius Bakke - Dec. 16, 2016, 5:33 p.m.
Ludovic Courtès <ludo@gnu.org> writes:

> Hi Marius,
>
> Marius Bakke <mbakke@fastmail.com> skribis:
>
>> Ludovic Courtès <ludo@gnu.org> writes:
>>
>>>>>> From 940c03c7dcddec019e27f6eb1470aeab4db57799 Mon Sep 17 00:00:00 2001
>>>>>> From: Marius Bakke <mbakke@fastmail.com>
>>>>>> Date: Thu, 20 Oct 2016 17:26:52 +0100
>>>>>> Subject: [PATCH] gnu: Add grub-efi.
>>>>>>
>>>>>> * gnu/packages/grub.scm (grub-efi): New variable.
>>>>>
>>>>> [...]
>>>>>
>>>>>> +    (name "grub-efi")
>>>>>> +    (synopsis (string-append (package-synopsis grub) " (UEFI version)"))
>>>>>
>>>>> Please use a literal string for ‘synopsis’; use of ‘string-append’ like
>>>>> this prevents i18n.
>>>>>
>>>>>> +     `(#:tests? #f ; FIXME: 40 failures, 24 skipped, 17 passed.
>>>>>
>>>>> It would be good to investigate, especially if the tests pass in the
>>>>> ‘grub’ package.
>>>>>
>>>>> Also, what’s the rationale for making ‘grub-efi’ separate instead of
>>>>> incorporating the changes in ‘grub’ proper?  Are there issues around the
>>>>> portability of ‘efibootmgr’, or an increased closure size?
>>>>
>>>> This is a good point. The only difference with "--with-platform=efi" is
>>>> that another directory is created in place of the i386-pc directory. It
>>>> is perfectly possible to build multiple platforms and copying the
>>>> platform-specific stuff to $out/lib -- grub will pick the correct
>>>> platform at runtime. This is what the Gentoo ebuild does.
>>>
>>> Are you saying that a GRUB compiled with UEFI support will no longer
>>> work out-of-the-box on non-UEFI machines, unless platform-specific stuff
>>> is moved like you suggest?
>>
>> Ha, no, it was just a long-winded and intoxicated way of saying what you
>> proposed should work fine. :)
>
> It turns out I have an immediate need ;-), so I pushed this as commit
> 3eee16130d858ae96510ec1c7d38d31290de2699.  Let me know if that doesn’t
> seem right!

I think you need to compile with '--with-platform=efi' as well. Check
/gnu/store/...grub-.../lib/grub. I still use a custom 'grub-efi'
expression (attached, needs adaption to 3eee16). Otherwise grub won't
have the required install files, even if it could detect the platform.

Relatedly, I think the way to build a 'multi-grub' is to have one
expression for each supported grub platform, and then consolidate
out/lib/grub from each.

> Now there are things I didn’t quite get.  Apparently you’re supposed to
> have a /boot/efi as a vfat partition, and ‘grub-install’ is supposed to
> detect it and install the EFI stuff, or so I thought (info "(grub)
> Installing GRUB using grub-install").
>
> However, ‘grub-install’ still seems to be installing for “i386-pc”
> instead of EFI.
>
> What am I missing?

IIRC grub-install will detect and install for the running mode (pc, efi,
etc). So in a classic chicken-and-egg situation, you need to be booted
with UEFI mode for grub to select the correct installation platform!

I worked around this by installing grub from a UEFI live CD, copy and
adapt the grub.cfg from an existing (BIOS) GuixSD installation, then
coerce the GuixSD system to use EFI from that point..
Ludovic Courtès - Dec. 18, 2016, 10:54 a.m.
Hello Marius!

Marius Bakke <mbakke@fastmail.com> skribis:

> Ludovic Courtès <ludo@gnu.org> writes:

[...]

>> It turns out I have an immediate need ;-), so I pushed this as commit
>> 3eee16130d858ae96510ec1c7d38d31290de2699.  Let me know if that doesn’t
>> seem right!
>
> I think you need to compile with '--with-platform=efi' as well.

Bah, silly me.

> Check /gnu/store/...grub-.../lib/grub. I still use a custom 'grub-efi'
> expression (attached, needs adaption to 3eee16). Otherwise grub won't
> have the required install files, even if it could detect the platform.
>
> Relatedly, I think the way to build a 'multi-grub' is to have one
> expression for each supported grub platform, and then consolidate
> out/lib/grub from each.

So in essence, GRUB itself supports only one platform at a time?

>> Now there are things I didn’t quite get.  Apparently you’re supposed to
>> have a /boot/efi as a vfat partition, and ‘grub-install’ is supposed to
>> detect it and install the EFI stuff, or so I thought (info "(grub)
>> Installing GRUB using grub-install").
>>
>> However, ‘grub-install’ still seems to be installing for “i386-pc”
>> instead of EFI.
>>
>> What am I missing?
>
> IIRC grub-install will detect and install for the running mode (pc, efi,
> etc). So in a classic chicken-and-egg situation, you need to be booted
> with UEFI mode for grub to select the correct installation platform!

My understanding is that it would install for UEFI if it fines
/boot/efi or if --efi-directory is passed.

BTW, as far as I’m concerned, most of the other patches are ready:

  https://lists.gnu.org/archive/html/guix-devel/2016-11/msg00303.html
  https://lists.gnu.org/archive/html/guix-devel/2016-11/msg00304.html

Could you push them?

The remaining issue is how to run fsck for vfat.

Currently I still have a preference for something like what I suggested
at:

  https://lists.gnu.org/archive/html/guix-devel/2016-12/msg00095.html

Thoughts?

Thanks!

Ludo’.
Marius Bakke - Dec. 18, 2016, 2:36 p.m.
Ludovic Courtès <ludo@gnu.org> writes:

>> Relatedly, I think the way to build a 'multi-grub' is to have one
>> expression for each supported grub platform, and then consolidate
>> out/lib/grub from each.
>
> So in essence, GRUB itself supports only one platform at a time?

AFAICT yes. Gentoo works around this by running the build for each
user-specified platform and combining the outputs. Most other distros
just carry separate grub-pc and grub-efi packages.

>>> Now there are things I didn’t quite get.  Apparently you’re supposed to
>>> have a /boot/efi as a vfat partition, and ‘grub-install’ is supposed to
>>> detect it and install the EFI stuff, or so I thought (info "(grub)
>>> Installing GRUB using grub-install").
>>>
>>> However, ‘grub-install’ still seems to be installing for “i386-pc”
>>> instead of EFI.
>>>
>>> What am I missing?
>>
>> IIRC grub-install will detect and install for the running mode (pc, efi,
>> etc). So in a classic chicken-and-egg situation, you need to be booted
>> with UEFI mode for grub to select the correct installation platform!
>
> My understanding is that it would install for UEFI if it fines
> /boot/efi or if --efi-directory is passed.

I'm not so sure, but it's been a while since I played around with this.
At least building the 'gnu/system/install.scm' image works fine when
passing --efi-directory (see the bottom two patches from
https://lists.gnu.org/archive/html/guix-devel/2016-12/txtchTym4QVKr.txt ),
and I think it would choose i386-pc even if x86_64-efi was available
since the VM boots in BIOS mode.

Tangentially, I'm not aware of any way to build a "hybrid" ISO image
using only grub. I've started work on packaging syslinux/isolinux which
is what Debian uses for their hybrid UEFI/BIOS install image.

> BTW, as far as I’m concerned, most of the other patches are ready:
>
>   https://lists.gnu.org/archive/html/guix-devel/2016-11/msg00303.html
>   https://lists.gnu.org/archive/html/guix-devel/2016-11/msg00304.html
>
> Could you push them?

Done.

> The remaining issue is how to run fsck for vfat.
>
> Currently I still have a preference for something like what I suggested
> at:
>
>   https://lists.gnu.org/archive/html/guix-devel/2016-12/msg00095.html
>
> Thoughts?

This approach looks better than the one I started working on. It's not
clear to me how to pass the device to these procedures, or how
'check-file-system' will know which checker to use. We should try to
have this in place before 0.13 :-)

Patch

From 1ca87a51f55f0b05f89eed707c1485b94f3d7d16 Mon Sep 17 00:00:00 2001
From: Marius Bakke <mbakke@fastmail.com>
Date: Thu, 20 Oct 2016 17:26:52 +0100
Subject: [PATCH] gnu: Add grub-efi.

* gnu/packages/grub.scm (grub-efi): New variable.
---
 gnu/packages/grub.scm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/gnu/packages/grub.scm b/gnu/packages/grub.scm
index ef7395e95..1cb835695 100644
--- a/gnu/packages/grub.scm
+++ b/gnu/packages/grub.scm
@@ -164,3 +164,26 @@  on the same computer; upon booting the computer, the user is presented with a
 menu to select one of the installed operating systems.")
     (license gpl3+)
     (properties '((cpe-name . "grub2")))))
+
+(define-public grub-efi
+  (package
+    (inherit grub)
+    (name "grub-efi")
+    (synopsis (string-append (package-synopsis grub) " (UEFI version)"))
+    (inputs
+     `(("efibootmgr" ,efibootmgr)
+       ,@(package-inputs grub)))
+    (arguments
+     `(#:tests? #f ; FIXME: 40 failures, 24 skipped, 17 passed.
+       ,@(substitute-keyword-arguments (package-arguments grub)
+           ((#:configure-flags flags) `(cons* "--with-platform=efi"
+                                              ,flags))
+           ((#:phases phases)
+            `(modify-phases ,phases
+               (add-after 'patch-stuff 'use-absolute-efibootmgr-path
+                 (lambda* (#:key inputs #:allow-other-keys)
+                   (substitute* "grub-core/osdep/unix/platform.c"
+                     (("efibootmgr")
+                      (string-append (assoc-ref inputs "efibootmgr")
+                                     "/sbin/efibootmgr")))
+                   #t)))))))))
-- 
2.11.0