From patchwork Wed Apr 29 08:47:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Othacehe X-Patchwork-Id: 21745 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id E062027BBE4; Wed, 29 Apr 2020 09:54:05 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,T_DKIM_INVALID, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) by mira.cbaines.net (Postfix) with ESMTP id 6A70F27BBE1 for ; Wed, 29 Apr 2020 09:54:05 +0100 (BST) Received: from localhost ([::1]:41206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTiTl-00008Z-0O for patchwork@mira.cbaines.net; Wed, 29 Apr 2020 04:54:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57082) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTiQI-00072y-JJ for guix-patches@gnu.org; Wed, 29 Apr 2020 04:53:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jTiOt-0002vR-Iq for guix-patches@gnu.org; Wed, 29 Apr 2020 04:50:30 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:59081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jTiOt-0002tq-46 for guix-patches@gnu.org; Wed, 29 Apr 2020 04:49:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jTiOt-0005DV-23 for guix-patches@gnu.org; Wed, 29 Apr 2020 04:49:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#40955] [PATCH 3/5] build: bootloader: Add install-efi procedure. Resent-From: Mathieu Othacehe Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 29 Apr 2020 08:49:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 40955 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 40955@debbugs.gnu.org Cc: Mathieu Othacehe Received: via spool by 40955-submit@debbugs.gnu.org id=B40955.158815009719959 (code B ref 40955); Wed, 29 Apr 2020 08:49:03 +0000 Received: (at 40955) by debbugs.gnu.org; 29 Apr 2020 08:48:17 +0000 Received: from localhost ([127.0.0.1]:42388 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTiO8-0005Bl-Iy for submit@debbugs.gnu.org; Wed, 29 Apr 2020 04:48:17 -0400 Received: from mail-wm1-f50.google.com ([209.85.128.50]:56280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jTiO2-0005B3-D8 for 40955@debbugs.gnu.org; Wed, 29 Apr 2020 04:48:10 -0400 Received: by mail-wm1-f50.google.com with SMTP id e26so1065446wmk.5 for <40955@debbugs.gnu.org>; Wed, 29 Apr 2020 01:48:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/jGuAwU24E9GEwu4XlrPjIZFzkZZfvlHV2ClD/llzQ0=; b=Y8nAyAWtqlAcrhmrhrHCeCN/wFtGsQH//aW9LcMPTfiKIANMpkhtY61YpxGoafIp5X z/V8CHf0l9zmYPBH8yMzVryXdvMBPvB24cDJZVT3P5zfoWE58GKTH6+4WJl0daQ2fapZ XhiVzOZ5w6oAKNEnzwMpCBi5kcGRzEWk7tmaMk9aSK4TWqqIbh/H2iBGGRZoZquBh1gk nV4GXFQC7aBVwCqDz8cWU/n3RNEgZ8E/0cUIshcx+HAxeNfdXG5DKB6CwPfnDIR1ehRc UTB/XfWi4x+DSzP8DWabpnWyUXJgMBJJxdaVxzwJ5EuLGJC+aUOauPWAOqtFpllyN6Pu YbAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/jGuAwU24E9GEwu4XlrPjIZFzkZZfvlHV2ClD/llzQ0=; b=cShD9Sb21Mp5hDuO+8jX09JNfBhmVz7vNZqvCDIUW9NzrykI0pB1Ol6zbZA55Sh1iZ rhli+WZElGE2fX+yfz7k6ovxjug04xJnWvDGQfNZftEWlZLEFgF2v6coHn974AkaO9d7 uouGx9xMr3+xC3etK59QMBGw8gVN66+zCItDHJY+aNGJCT/ImD93QNN2trK8EMy+Hlle vVCXMPqNc+Bv7dF+r2onXurl10Rpr8rxq9EAcyvUxlw2+AlZjtDYuh7nZUCvNo2w6Wgm AsY/FveI30Z1VI/vV7LJjBpTmKOvToWasVB9/ZxfJqWtgwWhWmbJV/O5hw2sfpXiYOda E+cg== X-Gm-Message-State: AGi0PuaoonjX8BMu23+2f+lphQpbymGQNO7eJnXH0TdWA1AWZt7tHKa3 WAWK/DE2NPhA3gouredTxIX+GLc/ X-Google-Smtp-Source: APiQypLyMIUl2vkjNUJDpomVeZud6OCHE1bxmwTGN0mkRGe6wIhQiyh6H3GGp6CAXSfVa27fkLlNcw== X-Received: by 2002:a1c:f418:: with SMTP id z24mr1986096wma.122.1588150084381; Wed, 29 Apr 2020 01:48:04 -0700 (PDT) Received: from meru.fronius.com ([2a01:cb18:832e:5f00:e9fd:9d65:b691:fcb3]) by smtp.gmail.com with ESMTPSA id x132sm6812621wmg.33.2020.04.29.01.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 01:48:03 -0700 (PDT) From: Mathieu Othacehe Date: Wed, 29 Apr 2020 10:47:54 +0200 Message-Id: <20200429084756.25072-3-m.othacehe@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200429084756.25072-1-m.othacehe@gmail.com> References: <20200429084756.25072-1-m.othacehe@gmail.com> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Received-From: 209.51.188.43 X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/build/bootloader.scm (install-efi-loader): New exported procedure. This is based on install-efi from (gnu build vm) module. * gnu/build/vm.scm (initialize-hard-disk): Adapt to use install-efi-loader. --- gnu/build/bootloader.scm | 55 +++++++++++++++++++++++++++++++++++++++- gnu/build/vm.scm | 19 +++----------- 2 files changed, 57 insertions(+), 17 deletions(-) diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm index 9570d6dd18..e15e7c0828 100644 --- a/gnu/build/bootloader.scm +++ b/gnu/build/bootloader.scm @@ -18,8 +18,12 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu build bootloader) + #:use-module (guix build utils) + #:use-module (guix utils) #:use-module (ice-9 binary-ports) - #:export (write-file-on-device)) + #:use-module (ice-9 format) + #:export (write-file-on-device + install-efi-loader)) ;;; @@ -36,3 +40,52 @@ (seek output offset SEEK_SET) (put-bytevector output bv)) #:binary #t))))) + + +;;; +;;; EFI bootloader. +;;; + +(define (install-efi grub grub-config esp) + "Write a self-contained GRUB EFI loader to the mounted ESP using GRUB-CONFIG." + (let* ((system %host-type) + ;; Hard code the output location to a well-known path recognized by + ;; compliant firmware. See "3.5.1.1 Removable Media Boot Behaviour": + ;; http://www.uefi.org/sites/default/files/resources/UEFI%20Spec%202_6.pdf + (grub-mkstandalone (string-append grub "/bin/grub-mkstandalone")) + (efi-directory (string-append esp "/EFI/BOOT")) + ;; Map grub target names to boot file names. + (efi-targets (cond ((string-prefix? "x86_64" system) + '("x86_64-efi" . "BOOTX64.EFI")) + ((string-prefix? "i686" system) + '("i386-efi" . "BOOTIA32.EFI")) + ((string-prefix? "armhf" system) + '("arm-efi" . "BOOTARM.EFI")) + ((string-prefix? "aarch64" system) + '("arm64-efi" . "BOOTAA64.EFI"))))) + ;; grub-mkstandalone requires a TMPDIR to prepare the firmware image. + (setenv "TMPDIR" esp) + + (mkdir-p efi-directory) + (invoke grub-mkstandalone "-O" (car efi-targets) + "-o" (string-append efi-directory "/" + (cdr efi-targets)) + ;; Graft the configuration file onto the image. + (string-append "boot/grub/grub.cfg=" grub-config)))) + +(define (install-efi-loader grub-efi esp) + ;; Create a tiny configuration file telling the embedded grub + ;; where to load the real thing. + ;; XXX This is quite fragile, and can prevent the image from booting + ;; when there's more than one volume with this label present. + ;; Reproducible almost-UUIDs could reduce the risk (not eliminate it). + (let ((grub-config "grub.cfg")) + (call-with-output-file grub-config + (lambda (port) + (format port + "insmod part_msdos~@ + search --set=root --label Guix_image~@ + configfile /boot/grub/grub.cfg~%") + (fsync port))) + (install-efi grub-efi grub-config esp) + (delete-file grub-config))) diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 9caa110463..bc6071daa9 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -27,6 +27,7 @@ #:use-module (guix build store-copy) #:use-module (guix build syscalls) #:use-module (guix store database) + #:use-module (gnu build bootloader) #:use-module (gnu build linux-boot) #:use-module (gnu build install) #:use-module (gnu system uuid) @@ -610,30 +611,16 @@ passing it a directory name where it is mounted." (when esp ;; Mount the ESP somewhere and install GRUB UEFI image. - (let ((mount-point (string-append target "/boot/efi")) - (grub-config (string-append target "/tmp/grub-standalone.cfg"))) + (let ((mount-point (string-append target "/boot/efi"))) (display "mounting EFI system partition...\n") (mkdir-p mount-point) (mount (partition-device esp) mount-point (partition-file-system esp)) - ;; Create a tiny configuration file telling the embedded grub - ;; where to load the real thing. - ;; XXX This is quite fragile, and can prevent the image from booting - ;; when there's more than one volume with this label present. - ;; Reproducible almost-UUIDs could reduce the risk (not eliminate it). - (call-with-output-file grub-config - (lambda (port) - (format port - "insmod part_msdos~@ - search --set=root --label Guix_image~@ - configfile /boot/grub/grub.cfg~%"))) - (display "creating EFI firmware image...") - (install-efi grub-efi mount-point grub-config) + (install-efi-loader grub-efi mount-point) (display "done.\n") - (delete-file grub-config) (umount mount-point))) ;; Register BOOTCFG as a GC root.