From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32822) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d7Rh0-00062a-Oi for guix-patches@gnu.org; Sun, 07 May 2017 15:18:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d7Rgw-0004zh-4c for guix-patches@gnu.org; Sun, 07 May 2017 15:18:06 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:34310) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d7Rgv-0004zI-V5 for guix-patches@gnu.org; Sun, 07 May 2017 15:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d7Rgv-0000nn-Pf for guix-patches@gnu.org; Sun, 07 May 2017 15:18:01 -0400 Subject: bug#26815: [PATCH 3/3] vm: Support EFI boot in base image. Resent-Message-ID: From: Marius Bakke In-Reply-To: <20170507171814.555ec8b3@scratchpost.org> References: <20170507143647.21036-1-mbakke@fastmail.com> <20170507143647.21036-3-mbakke@fastmail.com> <20170507171814.555ec8b3@scratchpost.org> Date: Sun, 07 May 2017 21:17:49 +0200 Message-ID: <87r300xyqq.fsf@fastmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Danny Milosavljevic Cc: 26815@debbugs.gnu.org --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain Danny Milosavljevic writes: > Hi Marius, > >> + (system* "grub-mkstandalone" "-O" "x86_64-efi" "-o" >> + (string-append efi-directory "/EFI/BOOT/BOOTX64.EFI") >> + ;; Embed the contents of grubdisk.cfg. >> + (string-append "boot/grub/grub.cfg=" target >> + "/tmp/grubdisk.cfg")) > > Check return value of system* ? I rewrote most of this to be (hopefully) more understandable. Also, some rudimentary steps towards other platforms, native testing required. V2 attached. --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-vm-Support-EFI-boot-in-base-image.patch Content-Transfer-Encoding: quoted-printable From=20e94c9071c53db28c3e73998654b185c36a210df6 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Sun, 7 May 2017 15:31:30 +0200 Subject: [PATCH] vm: Support EFI boot in base image. * gnu/system/vm.scm (qemu-image): Add GRUB-EFI to inputs. Append 40MB EFI System Partition. * gnu/build/vm.scm (initialize-hard-disk): Generate grub EFI blob when ESP = is present. =2D-- gnu/build/vm.scm | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++= +++- gnu/system/vm.scm | 14 ++++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 206696ef6..8b4a44579 100644 =2D-- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -27,6 +27,7 @@ #:use-module (gnu build linux-boot) #:use-module (gnu build install) #:use-module (guix records) + #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (ice-9 regex) #:use-module (srfi srfi-1) @@ -334,9 +335,16 @@ passing it a directory name where it is mounted." "Return the first partition found with the boot flag set." (member 'boot (partition-flags partitions))) =20 + (define (partition-esp? partitions) + "Return the first EFI System Partition." + (member 'esp (partition-flags partitions))) + (let* ((partitions (initialize-partition-table device partitions)) (root (find partition-bootable? partitions)) =2D (target "/fs")) + (esp (find partition-esp? partitions)) + (target "/fs") + ;; Grub expects to find an EFI System Partition here. + (efi-directory (string-append target "/boot/efi"))) (unless root (error "no bootable partition specified" partitions)) =20 @@ -346,6 +354,55 @@ passing it a directory name where it is mounted." (mkdir-p target) (mount (partition-device root) target (partition-file-system root)) (install-boot-config bootcfg bootcfg-location target) + + ;; If we have an ESP partition, generate a self-contained grub EFI + ;; image and write it to a well-known location. + (when esp + (let* ((system %host-type) + (efi-payload-directory (string-append efi-directory "/EFI/BOO= T")) + (efi-payload-file-name (if (any (cute string-prefix? <> syste= m) + '("i686" "armhf")) + "BOOTX32.EFI" ;hail mary + "BOOTX64.EFI")) ;fairly suppor= ted + (efi-payload-format (cond + ((string-prefix? "x86_64" system) + "x86_64-efi") + ((string-prefix? "i686" system) + "i386-efi") + ((string-prefix? "armhf" system) + "arm-efi") + ((string-prefix? "aarch64" system) + "arm64-efi"))) + (grub-tmp (string-append target "/tmp")) + (grub.cfg (string-append grub-tmp "/grub.cfg"))) + (display "mounting EFI system partition...\n") + (mkdir-p efi-directory) + (mount (partition-device esp) efi-directory + (partition-file-system esp)) + (mkdir-p efi-payload-directory) + + ;; Grub needs a tmpdir to prepare the image. + (setenv "TMPDIR" grub-tmp) + ;; We also need a tiny configuration file telling the EFI blob whe= re + ;; to find the real thing. + (with-output-to-file grub.cfg + (lambda _ + (format #t + "insmod part_msdos~@ + search --set=3Droot --label gnu-disk-image~@ + configfile /boot/grub/grub.cfg~%"))) + (display "creating grub firmware image...\n") + (unless (zero? (system* "grub-mkstandalone" "-O" efi-payload-format + "-o" (string-append efi-payload-directory = "/" + efi-payload-file-name) + ;; Graft the contents of our configuration= file + ;; into the image. See grub-mkstandalone(= 1). + (string-append "boot/grub/grub.cfg=3D" gru= b.cfg))) + (error "failed to create grub EFI image")) + + (delete-file grub.cfg) + (umount efi-directory))) + (when bootloader-installer (bootloader-installer bootloader device target)) =20 diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 099e3fac3..04ccc3650 100644 =2D-- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -3,6 +3,7 @@ ;;; Copyright =C2=A9 2016 Christopher Allan Webber ;;; Copyright =C2=A9 2016 Leo Famulari ;;; Copyright =C2=A9 2017 Mathieu Othacehe +;;; Copyright =C2=A9 2017 Marius Bakke ;;; ;;; This file is part of GNU Guix. ;;; @@ -202,7 +203,7 @@ the image." (guix build utils)) =20 (let ((inputs =2D '#$(append (list qemu parted e2fsprogs dosfstools) + '#$(append (list qemu parted e2fsprogs dosfstools grub-efi) (map canonical-package (list sed grep coreutils findutils gawk)) (if register-closures? (list guix) '()))) @@ -227,11 +228,18 @@ the image." #:system-directory #$os.drv)) (partitions (list (partition (size #$(- disk-image-size =2D (* 10 (expt 2 20)))) + (* 50 (expt 2 20)))) (label #$file-system-label) (file-system #$file-system-type) (flags '(boot)) =2D (initializer initialize))))) + (initializer initialize)) + (partition + ;; Append a small FAT32 partition for + ;; use with UEFI bootloaders. + (size (* 40 (expt 2 20))) + (label "gnu-esp") + (file-system "vfat") + (flags '(esp)))))) (initialize-hard-disk "/dev/vda" #:partitions partitions #:bootloader =2D-=20 2.12.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAlkPct0ACgkQoqBt8qM6 VPq60QgAhWPFxpI/bI38befXrrz3ytCKAr+aoVdARRiUqS5wXeG1jczWb+oLk29m MgqpbX42kPEpRDhYQrY+Vzogdou2PLdI+HQhSUR2/6QODwSo3XRLFkhoMf+JYjwH bAuxw9hNjgioD9f1vLAZ9+egSFzB0xr0At+BvBz99Lve97FMjJdWblLUZnCjGTXQ 3LFt9Na8ZKKjcQdF10t2enYiqsNHRERHsIWHBnF7AjWSPQT6j42RNnHKD8GDXOuC zTtaw3SFj9AQZ1qAU9/JOoVvF6fQ3kftaBolIt84j9aI6qYq2Sr7bnjgDR8p7yxO 5iOOSel6KYAWkA+ZhLKMw+bStrOKng== =aF6s -----END PGP SIGNATURE----- --==-=-=--