diff mbox series

[bug#41560,2/8] bootloader: grub: Do not run grub-install when creating a disk-image.

Message ID 20200527072420.26140-2-othacehe@gnu.org
State Accepted
Headers show
Series image: Add MBR based boot support. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Mathieu Othacehe May 27, 2020, 7:24 a.m. UTC
* gnu/bootloader/grub.scm (install-grub): When creating a disk-image,
grub-install will fail because it lacks root permissions. In that case, do not
run grub-install and only copy Grub modules to the /boot directory.
---
 gnu/bootloader/grub.scm | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

Comments

Ludovic Courtès May 28, 2020, 9:40 p.m. UTC | #1
Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> * gnu/bootloader/grub.scm (install-grub): When creating a disk-image,
> grub-install will fail because it lacks root permissions. In that case, do not
> run grub-install and only copy Grub modules to the /boot directory.

[...]

> +        ;; Install GRUB on DEVICE which is mounted at MOUNT-POINT. If device
                                                                         ^
DEVICE

> +        ;; is #f we are creating a disk-image.

Maybe:

  … is #f, then populate the disk image rooted at MOUNT-POINT.
diff mbox series

Patch

diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 74dc00480f..29bec92196 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -423,18 +423,24 @@  fi~%"))))
 
 (define install-grub
   #~(lambda (bootloader device mount-point)
-      ;; Install GRUB on DEVICE which is mounted at MOUNT-POINT.
       (let ((grub (string-append bootloader "/sbin/grub-install"))
             (install-dir (string-append mount-point "/boot")))
-        ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
-        ;; root partition.
-        (setenv "GRUB_ENABLE_CRYPTODISK" "y")
-
-        ;; Hide potentially confusing messages from the user, such as
-        ;; "Installing for i386-pc platform."
-        (invoke/quiet grub "--no-floppy" "--target=i386-pc"
-                      "--boot-directory" install-dir
-                      device))))
+        ;; Install GRUB on DEVICE which is mounted at MOUNT-POINT. If device
+        ;; is #f we are creating a disk-image.
+        (if device
+            (begin
+              ;; Tell 'grub-install' that there might be a LUKS-encrypted
+              ;; /boot or root partition.
+              (setenv "GRUB_ENABLE_CRYPTODISK" "y")
+
+              ;; Hide potentially confusing messages from the user, such as
+              ;; "Installing for i386-pc platform."
+              (invoke/quiet grub "--no-floppy" "--target=i386-pc"
+                            "--boot-directory" install-dir
+                            device))
+            ;; When creating a disk-image, only install Grub modules.
+            (copy-recursively (string-append bootloader "/lib/")
+                              install-dir)))))
 
 (define install-grub-disk-image
   #~(lambda (bootloader root-index image)