Subject: Re: bug#30311: efi-less grub install fails

From: Marius Bakke <[email-masked]>
Date: Tue, 20 Feb 2018 04:46:22 +0100

Marius Bakke <[email-masked]> writes:

> Mark H Weaver <[email-masked]> writes:
>
>> Hi Ricardo,
>>
>> Ricardo Wurmus <[email-masked]> writes:
>>> Okay, I’ve added “--target=i386-pc” to the list of arguments.
>>
>> This change breaks my mips64el-linux GuixSD system, which is supported
>> by GRUB, but where "--target=i386-pc" is obviously not appropriate.  On
>> my system I need a different 'target' setting.
>
> Maybe we can make it conditional on EFI for now.  Ricardo, are you able
> to test the attached patch?  I suspect we might get problems on POWER
> and some ARM systems down the road, but it should at least fix this
> immediate issue.
>
> Note: I haven't tested this patch myself.

Bah, here is a fixed version that actually works (for the normal case).

From 968ccb27e40ce683ec469f3ac7973827a7e8ddf5 Mon Sep 17 00:00:00 2001
From: Marius Bakke <[email-masked]>
Date: Tue, 20 Feb 2018 04:02:23 +0100
Subject: [PATCH] gnu: Pass "--target" to EFI-less GRUB only when EFI variables
 are present.

Fixes <https://bugs.gnu.org/30311>.

* gnu/bootloader/grub.scm (install-grub): Make "--target" argument
conditional on the presence of "/sys/firmware/efi".
---
 gnu/bootloader/grub.scm | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 3b01125c7..17ded5f6d 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -386,9 +386,15 @@ submenu \"GNU system, old configurations...\" {~%")
         ;; root partition.
         (setenv "GRUB_ENABLE_CRYPTODISK" "y")
 
-        (unless (zero? (system* grub "--no-floppy" "--target=i386-pc"
-                                "--boot-directory" install-dir
-                                device))
+        (unless (zero? (apply system* grub
+                              (list "--no-floppy"
+                                    "--boot-directory" install-dir
+                                    ;; Explicitly pass target if the non-EFI
+                                    ;; GRUB is requested on an EFI system.
+                                    ;; See <https://bugs.gnu.org/30311>.
+                                    #$@(if (file-exists? "/sys/firmware/efi")
+                                           '("--target=i386-pc"))
+                                    device)))
           (error "failed to install GRUB (BIOS)")))))
 
 (define install-grub-efi
-- 
2.16.2