From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marius Bakke Subject: UEFI support in boot image Date: Mon, 17 Apr 2017 22:41:40 +0200 Message-ID: <8760i2lqbf.fsf@fastmail.com> References: <87wpb7ym78.fsf@gnu.org> <87shlqv4pe.fsf@kirby.i-did-not-set--mail-host-address--so-tickle-me> <87tw65sxvf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36913) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d0DT1-0005Qu-UF for guix-devel@gnu.org; Mon, 17 Apr 2017 16:41:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d0DSy-0000yp-Mq for guix-devel@gnu.org; Mon, 17 Apr 2017 16:41:47 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:44889) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d0DSy-0000y0-B5 for guix-devel@gnu.org; Mon, 17 Apr 2017 16:41:44 -0400 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id B7C3220A12 for ; Mon, 17 Apr 2017 16:41:42 -0400 (EDT) Received: from localhost (unknown [188.113.81.93]) by mail.messagingengine.com (Postfix) with ESMTPA id 4B1357E790 for ; Mon, 17 Apr 2017 16:41:42 -0400 (EDT) In-Reply-To: <87tw65sxvf.fsf@gnu.org> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s writes: > Marius Bakke skribis: > >> Ludovic Court=C3=A8s writes: >> >>> 3. UEFI support documented and possibly improved. >>> >>> We can certainly document the UEFI setup and add the /boot/efi >>> partition in some of the =E2=80=98operating-system=E2=80=99 examp= les. >>> >>> The more difficult part is the installation: do we need to make a >>> second, UEFI-specific, installation image? When I installed >>> GuixSD on UEFI, I booted our installation image as =E2=80=9Clegac= y=E2=80=9D, but >>> then GRUB would default to a legacy install, not a UEFI install: >>> >>> https://lists.gnu.org/archive/html/guix-devel/2016-12/msg00799.= html >>> >>> I=E2=80=99m not sure exactly what needs to be done. Thoughts? >> >> I plan to work on this over the next few days. The most common way is to >> create a "hybrid" disk image that supports both UEFI and BIOS boot. IIRC >> Debian achieves this by using Isolinux to create the EFI payload and >> chainload to Grub. More information next week :-) > > Awesome, thanks for volunteering! Apologies for the late follow-up, but I finally found some time to work on this. I've attached a few patches as a humble beginning, but currently the "format-partition" code in (gnu build vm) needs to learn some filesystem-specific parameters. So, I don't think it will be ready for the upcoming release. I have also done some reading and don't think we can use isolinux as it requires an image in ISO 9660 format. Nor does the syslinux utilities actually support chainloading grub from UEFI as I had hoped. So I think we'll have to offer UEFI as a standalone image, at least to begin with. Unfortunately I also believe it needs to be generated from a UEFI system, but this grub limitation can hopefully be lifted. Anyway, here is the current status (advice on the FIXME appreciated): --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=uefi-boot.patch Content-Transfer-Encoding: quoted-printable From=2025b01f9a219338580b6f7a7449bba8ff90c2176c Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Tue, 11 Apr 2017 10:47:38 +0200 Subject: [PATCH 1/4] vm: Add support for arbitrary partition flags. * gnu/build/vm.scm (): Change BOOTABLE? to FLAGS. (initialize-partition-table): Pass each flag to parted. (initialize-hard-disk): Search for root partition by "boot" flag. * gnu/system/vm.scm (qemu-image): Adjust partitions accordingly. =2D-- gnu/build/vm.scm | 22 ++++++++++++++++------ gnu/system/vm.scm | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 1eb9a4c45..f6a028868 100644 =2D-- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -41,7 +41,7 @@ partition-size partition-file-system partition-label =2D partition-bootable? + partition-flags partition-initializer =20 root-partition-initializer @@ -141,7 +141,7 @@ the #:references-graphs parameter of 'derivation'." (size partition-size) (file-system partition-file-system (default "ext4")) (label partition-label (default #f)) =2D (bootable? partition-bootable? (default #f)) + (flags partition-flags (default '())) (initializer partition-initializer (default (const #t)))) =20 (define (fold2 proc seed1 seed2 lst) ;TODO: factorize @@ -168,9 +168,10 @@ actual /dev name based on DEVICE." (cons* "mkpart" "primary" "ext2" (format #f "~aB" offset) (format #f "~aB" (+ offset (partition-size part))) =2D (if (partition-bootable? part) =2D `("set" ,(number->string index) "boot" "on") =2D '()))) + (apply append (map (lambda (flag) + (cons* "set" (number->string index) flag + "on" '())) + (partition-flags part))))) =20 (define (options partitions offset) (let loop ((partitions partitions) @@ -300,8 +301,17 @@ in PARTITIONS, and using BOOTCFG as its bootloader con= figuration file. =20 Each partition is initialized by calling its 'initializer' procedure, passing it a directory name where it is mounted." + + (define (find-root-partition partitions) + "Return the first partition found with the boot flag set." + ;; FIXME: This probably does not work. What's the best way to do this? + (find (match-lambda + (($ _ _ _ _ flags) + (member "boot" flags))) + partitions)) + (let* ((partitions (initialize-partition-table device partitions)) =2D (root (find partition-bootable? partitions)) + (root (find-root-partition partitions)) (target "/fs")) (unless root (error "no bootable partition specified" partitions)) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 374d8b663..e8a8463d5 100644 =2D-- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -229,7 +229,7 @@ the image." (* 10 (expt 2 20)))) (label #$file-system-label) (file-system #$file-system-type) =2D (bootable? #t) + (flags '("boot")) (initializer initialize))))) (initialize-hard-disk "/dev/vda" #:partitions partitions =2D-=20 2.12.2 From=209db90ea41a94ecbe42bba88de1c2e3ac607d5ea4 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Tue, 11 Apr 2017 10:55:22 +0200 Subject: [PATCH 2/4] vm: Unconditionally add a small ESP partition. * gnu/system/vm.scm (qemu-image): Append 20MB FAT32 partition. =2D-- gnu/system/vm.scm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index e8a8463d5..867802342 100644 =2D-- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -226,11 +226,18 @@ the image." #:system-directory #$os-derivation)) (partitions (list (partition (size #$(- disk-image-size =2D (* 10 (expt 2 20)))) + (* 30 (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 (* 20 (expt 2 20))) + (label "gnu-esp") + (file-system "vfat") + (flags '("esp")))))) (initialize-hard-disk "/dev/vda" #:partitions partitions #:grub.cfg #$grub-configuration) =2D-=20 2.12.2 From=204306bae25d6110ec52b8bbe3ad8b55f2c4c18fca Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Mon, 17 Apr 2017 22:21:28 +0200 Subject: [PATCH 3/4] gnu: dosfstools: Enable compatibility symlinks. * gnu/packages/disk.scm (dosfstools)[arguments]<#:configure-flags>: New parameter. =2D-- gnu/packages/disk.scm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gnu/packages/disk.scm b/gnu/packages/disk.scm index 93895278d..c31107fcf 100644 =2D-- a/gnu/packages/disk.scm +++ b/gnu/packages/disk.scm @@ -196,7 +196,10 @@ to recover data more efficiently by only reading the n= ecessary blocks.") "0wy13i3i4x2bw1hf5m4fd0myh61f9bcrs035fdlf6gyc1jksrcp6")))) (build-system gnu-build-system) (arguments =2D `(#:make-flags (list (string-append "PREFIX=3D" %output) + `(;; The "--enable-compat-symlinks" flag is needed so that "mkfs.vfat" + ;; is created. The guix build code expects this to exist. + #:configure-flags '("--enable-compat-symlinks") + #:make-flags (list (string-append "PREFIX=3D" %output) "CC=3Dgcc"))) (native-inputs `(("xxd" ,vim))) ; for tests =2D-=20 2.12.2 From=20d3e733739edebfd42efd70e7cc6335f3862f1ed5 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Mon, 17 Apr 2017 22:25:43 +0200 Subject: [PATCH 4/4] gnu: vm: Add FAT32 utilities in base image. * gnu/system/vm.scm (qemu-image): Add DOSFSTOOLS to the closure. =2D-- gnu/system/vm.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm index 867802342..0f4e3ef7d 100644 =2D-- a/gnu/system/vm.scm +++ b/gnu/system/vm.scm @@ -201,7 +201,7 @@ the image." (guix build utils)) =20 (let ((inputs =2D '#$(append (list qemu parted grub e2fsprogs) + '#$(append (list qemu parted grub e2fsprogs dosfstools) (map canonical-package (list sed grep coreutils findutils gawk)) (if register-closures? (list guix) '()))) =2D-=20 2.12.2 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAlj1KIQACgkQoqBt8qM6 VPrwIwgAtA/y3OnF8tEYjv0AGXeWARwHwFaCpN0T+Axsgbf8tAAsk4f4IQ1pPCKX vkJFwOiD1tbm9nTPnRzNLRCeQ0EgDiZjKaQSog2QUzZmzRPiwxxe/hZl6GId4l6i 5IGxhLCwlcY1l0qrD+Yqt7bUsCfskKQM32wjvgCeIBOXbTulIjS+lYTwTHh4CTtZ qMn/bjQeaYWclYNo7DxrKG+y+Qzrb6EmoSFGTJ8TcrmPjmM8mj6pKnOoJ4FfuiYa xBTfhP1tAGef69uwO9Kfn855s8LxgD+q1e5NfCRZtSLly0VlwfgHJXOqsI+cC3cw tqisdk39or+i//L5PVbPE2sH7fSnWQ== =NtHT -----END PGP SIGNATURE----- --==-=-=--