From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SIzmDaVAqV6QYgAA0tVLHw (envelope-from ) for ; Wed, 29 Apr 2020 08:53:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id +L+iDq5AqV7AbQAAbx9fmQ (envelope-from ) for ; Wed, 29 Apr 2020 08:54:06 +0000 Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:470:142::17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 71BD994313C for ; Wed, 29 Apr 2020 08:54:04 +0000 (UTC) Received: from localhost ([::1]:41206 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jTiTj-00008Z-8w for larch@yhetil.org; Wed, 29 Apr 2020 04:54:03 -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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: scn0 X-Spam-Score: 4.09 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=gmail.com header.s=20161025 header.b=Y8nAyAWt; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 2001:470:142::17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Scan-Result: default: False [4.09 / 13.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; GENERIC_REPUTATION(0.00)[-0.49332489348297]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2001:470:142::/48:c]; R_DKIM_REJECT(1.00)[gmail.com:s=20161025]; DWL_DNSWL_FAIL(0.00)[2001:470:142::17:server fail]; FREEMAIL_FROM(0.00)[gmail.com]; BROKEN_CONTENT_TYPE(1.50)[]; R_MISSING_CHARSET(2.50)[]; IP_REPUTATION_HAM(0.00)[asn: 22989(0.18), country: US(-0.00), ip: 2001:470:142::17(-0.49)]; DKIM_TRACE(0.00)[gmail.com:-]; RCPT_COUNT_TWO(0.00)[2]; MX_GOOD(-0.50)[cached: eggs.gnu.org]; MAILLIST(-0.20)[mailman]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_LAST(0.00)[]; ASN(0.00)[asn:22989, ipnet:2001:470:142::/48, country:US]; TAGGED_FROM(0.00)[larch=yhetil.org]; ARC_NA(0.00)[]; FROM_NEQ_ENVFROM(0.00)[mothacehe@gmail.com,guix-patches-bounces@gnu.org]; FROM_HAS_DN(0.00)[]; URIBL_BLOCKED(0.00)[gnu.org:url,uefi.org:url]; MID_RHS_MATCH_FROM(0.00)[]; TAGGED_RCPT(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[40955@debbugs.gnu.org]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; DNSWL_BLOCKED(0.00)[2001:470:142::17:from]; FREEMAIL_CC(0.00)[gmail.com]; RCVD_COUNT_SEVEN(0.00)[10]; FORGED_SENDER_MAILLIST(0.00)[]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : SPF not aligned (relaxed),none] X-TUID: QTY+DeWsfH6Y * 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. -- 2.26.0