diff options
| author | Mathieu Othacehe <m.othacehe@gmail.com> | 2020-04-28 16:17:59 +0200 |
|---|---|---|
| committer | Mathieu Othacehe <m.othacehe@gmail.com> | 2020-05-05 16:08:33 +0200 |
| commit | f8fd1157174fd523d36dcfa756c965a54c30d5ae (patch) | |
| tree | b0522095d41e3a1441ede268de37ea7d55ad8944 /gnu | |
| parent | 892bbea750e5733979ee0423cbdfcea222b07925 (diff) | |
build: bootloader: Add install-efi procedure.
* gnu/build/bootloader.scm (install-efi): New procedure copied from (gnu build vm).
(install-efi-loader): New exported procedure, wrapping install-efi.
* gnu/build/vm.scm (initialize-hard-disk): Adapt to use install-efi-loader.
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/build/bootloader.scm | 56 | ||||
| -rw-r--r-- | gnu/build/vm.scm | 19 |
2 files changed, 58 insertions, 17 deletions
diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm index 9570d6dd18d..498022f6db4 100644 --- a/gnu/build/bootloader.scm +++ b/gnu/build/bootloader.scm | |||
| @@ -18,8 +18,12 @@ | |||
| 18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | 18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 19 | 19 | ||
| 20 | (define-module (gnu build bootloader) | 20 | (define-module (gnu build bootloader) |
| 21 | #:use-module (guix build utils) | ||
| 22 | #:use-module (guix utils) | ||
| 21 | #:use-module (ice-9 binary-ports) | 23 | #:use-module (ice-9 binary-ports) |
| 22 | #:export (write-file-on-device)) | 24 | #:use-module (ice-9 format) |
| 25 | #:export (write-file-on-device | ||
| 26 | install-efi-loader)) | ||
| 23 | 27 | ||
| 24 | 28 | ||
| 25 | ;;; | 29 | ;;; |
| @@ -36,3 +40,53 @@ | |||
| 36 | (seek output offset SEEK_SET) | 40 | (seek output offset SEEK_SET) |
| 37 | (put-bytevector output bv)) | 41 | (put-bytevector output bv)) |
| 38 | #:binary #t))))) | 42 | #:binary #t))))) |
| 43 | |||
| 44 | |||
| 45 | ;;; | ||
| 46 | ;;; EFI bootloader. | ||
| 47 | ;;; | ||
| 48 | |||
| 49 | (define (install-efi grub grub-config esp) | ||
| 50 | "Write a self-contained GRUB EFI loader to the mounted ESP using GRUB-CONFIG." | ||
| 51 | (let* ((system %host-type) | ||
| 52 | ;; Hard code the output location to a well-known path recognized by | ||
| 53 | ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour": | ||
| 54 | ;; http://www.uefi.org/sites/default/files/resources/UEFI%20Spec%202_6.pdf | ||
| 55 | (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone")) | ||
| 56 | (efi-directory (string-append esp "/EFI/BOOT")) | ||
| 57 | ;; Map grub target names to boot file names. | ||
| 58 | (efi-targets (cond ((string-prefix? "x86_64" system) | ||
| 59 | '("x86_64-efi" . "BOOTX64.EFI")) | ||
| 60 | ((string-prefix? "i686" system) | ||
| 61 | '("i386-efi" . "BOOTIA32.EFI")) | ||
| 62 | ((string-prefix? "armhf" system) | ||
| 63 | '("arm-efi" . "BOOTARM.EFI")) | ||
| 64 | ((string-prefix? "aarch64" system) | ||
| 65 | '("arm64-efi" . "BOOTAA64.EFI"))))) | ||
| 66 | ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image. | ||
| 67 | (setenv "TMPDIR" esp) | ||
| 68 | |||
| 69 | (mkdir-p efi-directory) | ||
| 70 | (invoke grub-mkstandalone "-O" (car efi-targets) | ||
| 71 | "-o" (string-append efi-directory "/" | ||
| 72 | (cdr efi-targets)) | ||
| 73 | ;; Graft the configuration file onto the image. | ||
| 74 | (string-append "boot/grub/grub.cfg=" grub-config)))) | ||
| 75 | |||
| 76 | (define (install-efi-loader grub-efi esp) | ||
| 77 | "Install in ESP directory the given GRUB-EFI bootloader. Configure it to | ||
| 78 | load the Grub bootloader located in the 'Guix_image' root partition." | ||
| 79 | (let ((grub-config "grub.cfg")) | ||
| 80 | (call-with-output-file grub-config | ||
| 81 | (lambda (port) | ||
| 82 | ;; Create a tiny configuration file telling the embedded grub where to | ||
| 83 | ;; load the real thing. XXX This is quite fragile, and can prevent | ||
| 84 | ;; the image from booting when there's more than one volume with this | ||
| 85 | ;; label present. Reproducible almost-UUIDs could reduce the risk | ||
| 86 | ;; (not eliminate it). | ||
| 87 | (format port | ||
| 88 | "insmod part_msdos~@ | ||
| 89 | search --set=root --label Guix_image~@ | ||
| 90 | configfile /boot/grub/grub.cfg~%"))) | ||
| 91 | (install-efi grub-efi grub-config esp) | ||
| 92 | (delete-file grub-config))) | ||
diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 9caa110463b..bc6071daa9e 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #:use-module (guix build store-copy) | 27 | #:use-module (guix build store-copy) |
| 28 | #:use-module (guix build syscalls) | 28 | #:use-module (guix build syscalls) |
| 29 | #:use-module (guix store database) | 29 | #:use-module (guix store database) |
| 30 | #:use-module (gnu build bootloader) | ||
| 30 | #:use-module (gnu build linux-boot) | 31 | #:use-module (gnu build linux-boot) |
| 31 | #:use-module (gnu build install) | 32 | #:use-module (gnu build install) |
| 32 | #:use-module (gnu system uuid) | 33 | #:use-module (gnu system uuid) |
| @@ -610,30 +611,16 @@ passing it a directory name where it is mounted." | |||
| 610 | 611 | ||
| 611 | (when esp | 612 | (when esp |
| 612 | ;; Mount the ESP somewhere and install GRUB UEFI image. | 613 | ;; Mount the ESP somewhere and install GRUB UEFI image. |
| 613 | (let ((mount-point (string-append target "/boot/efi")) | 614 | (let ((mount-point (string-append target "/boot/efi"))) |
| 614 | (grub-config (string-append target "/tmp/grub-standalone.cfg"))) | ||
| 615 | (display "mounting EFI system partition...\n") | 615 | (display "mounting EFI system partition...\n") |
| 616 | (mkdir-p mount-point) | 616 | (mkdir-p mount-point) |
| 617 | (mount (partition-device esp) mount-point | 617 | (mount (partition-device esp) mount-point |
| 618 | (partition-file-system esp)) | 618 | (partition-file-system esp)) |
| 619 | 619 | ||
| 620 | ;; Create a tiny configuration file telling the embedded grub | ||
| 621 | ;; where to load the real thing. | ||
| 622 | ;; XXX This is quite fragile, and can prevent the image from booting | ||
| 623 | ;; when there's more than one volume with this label present. | ||
| 624 | ;; Reproducible almost-UUIDs could reduce the risk (not eliminate it). | ||
| 625 | (call-with-output-file grub-config | ||
| 626 | (lambda (port) | ||
| 627 | (format port | ||
| 628 | "insmod part_msdos~@ | ||
| 629 | search --set=root --label Guix_image~@ | ||
| 630 | configfile /boot/grub/grub.cfg~%"))) | ||
| 631 | |||
| 632 | (display "creating EFI firmware image...") | 620 | (display "creating EFI firmware image...") |
| 633 | (install-efi grub-efi mount-point grub-config) | 621 | (install-efi-loader grub-efi mount-point) |
| 634 | (display "done.\n") | 622 | (display "done.\n") |
| 635 | 623 | ||
| 636 | (delete-file grub-config) | ||
| 637 | (umount mount-point))) | 624 | (umount mount-point))) |
| 638 | 625 | ||
| 639 | ;; Register BOOTCFG as a GC root. | 626 | ;; Register BOOTCFG as a GC root. |
