summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Volf <wolf@wolfsden.cz>2024-01-11 18:35:40 +0100
committerLudovic Courtès <ludo@gnu.org>2024-01-14 23:00:03 +0100
commit086850e5b2b4a1744565fe83624d256524b64a49 (patch)
treec02752272e989134c35dc6dc67735915edc1f25a
parentd082312ef7adfea69c79d30ef947817b39832161 (diff)
bootloader: grub: Add support for loading an additional initrd.
In order to be able to provide decryption keys for the LUKS device, they need to be available in the initial ram disk. However they cannot be stored inside the usual initrd, since it is stored in the store and being a world-readable (as files in the store are) is not a desired property for a initrd containing decryption keys. This commit adds an option to load additional initrd during the boot, one that is not stored inside the store and therefore can contain secrets. Since only grub supports encrypted /boot, only grub is modified to use the extra-initrd. There is no use case for the other bootloaders. * doc/guix.texi (Bootloader Configuration): Describe the new extra-initrd field. * gnu/bootloader.scm (<bootloader-configuration>): Add extra-initrd field. * gnu/bootloader/grub.scm (make-grub-configuration): Use the extra-initrd field. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Change-Id: I995989bb623bb594ccdafbf4a1a6de941bd4189f
-rw-r--r--doc/guix.texi49
-rw-r--r--gnu/bootloader.scm6
-rw-r--r--gnu/bootloader/grub.scm7
3 files changed, 59 insertions, 3 deletions
diff --git a/doc/guix.texi b/doc/guix.texi
index c216d1b4a67..a66005ee9db 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -41070,6 +41070,55 @@ This option in enabled by default. In some cases involving the
41070@code{u-boot} bootloader, where the device tree has already been loaded 41070@code{u-boot} bootloader, where the device tree has already been loaded
41071in RAM, it can be handy to disable the option by setting it to 41071in RAM, it can be handy to disable the option by setting it to
41072@code{#f}. 41072@code{#f}.
41073
41074@item @code{extra-initrd} (default: @code{#f})
41075File name of an additional initrd to load during the boot. It may or
41076may not point to a file in the store, but the main use case is for
41077out-of-store files containing secrets.
41078
41079In order to be able to provide decryption keys for the LUKS device, they
41080need to be available in the initial ram disk. However they cannot be
41081stored inside the usual initrd, since it is stored in the store and
41082being a world-readable (as files in the store are) is not a desired
41083property for a initrd containing decryption keys. You can therefore use
41084this field to instruct GRUB to also load a manually created initrd not
41085stored in the store.
41086
41087For any use case not involving secrets, you should use regular initrd
41088(@pxref{operating-system Reference, @code{initrd}}) instead.
41089
41090Suitable image can be created for example like this:
41091
41092@example
41093echo /key-file.bin | cpio -oH newc >/key-file.cpio
41094chmod 0000 /key-file.cpio
41095@end example
41096
41097After it is created, you can use it in this manner:
41098
41099@lisp
41100;; Operating system with encrypted boot partition
41101(operating-system
41102 ...
41103 (bootloader (bootloader-configuration
41104 (bootloader grub-efi-bootloader)
41105 (targets '("/boot/efi"))
41106 ;; Load the initrd with a key file
41107 (extra-initrd "/key-file.cpio")))
41108 (mapped-devices
41109 (list (mapped-device
41110 (source (uuid "12345678-1234-1234-1234-123456789abc"))
41111 (target "my-root")
41112 (type (luks-device-mapping-with-options
41113 ;; And use it to unlock the root device
41114 #:key-file "/key-file.bin"))))))
41115@end lisp
41116
41117Be careful when using this option, since pointing to a file that is not
41118readable by the grub while booting will cause the boot to fail and
41119require a manual edit of the initrd line in the grub menu.
41120
41121Currently only supported by GRUB.
41073@end table 41122@end table
41074 41123
41075@end deftp 41124@end deftp
diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm
index ba06de76188..f32e90e79dd 100644
--- a/gnu/bootloader.scm
+++ b/gnu/bootloader.scm
@@ -6,6 +6,7 @@
6;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> 6;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
7;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz> 7;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
8;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org> 8;;; Copyright © 2022 Reza Alizadeh Majd <r.majd@pantherx.org>
9;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz>
9;;; 10;;;
10;;; This file is part of GNU Guix. 11;;; This file is part of GNU Guix.
11;;; 12;;;
@@ -77,6 +78,7 @@
77 bootloader-configuration-serial-unit 78 bootloader-configuration-serial-unit
78 bootloader-configuration-serial-speed 79 bootloader-configuration-serial-speed
79 bootloader-configuration-device-tree-support? 80 bootloader-configuration-device-tree-support?
81 bootloader-configuration-extra-initrd
80 82
81 %bootloaders 83 %bootloaders
82 lookup-bootloader-by-name 84 lookup-bootloader-by-name
@@ -279,7 +281,9 @@ instead~%")))
279 (serial-speed bootloader-configuration-serial-speed 281 (serial-speed bootloader-configuration-serial-speed
280 (default #f)) ;integer | #f 282 (default #f)) ;integer | #f
281 (device-tree-support? bootloader-configuration-device-tree-support? 283 (device-tree-support? bootloader-configuration-device-tree-support?
282 (default #t))) ;boolean 284 (default #t)) ;boolean
285 (extra-initrd bootloader-configuration-extra-initrd
286 (default #f))) ;string | #f
283 287
284(define-deprecated (bootloader-configuration-target config) 288(define-deprecated (bootloader-configuration-target config)
285 bootloader-configuration-targets 289 bootloader-configuration-targets
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm
index 5f3fcd7074c..2723eda5f4d 100644
--- a/gnu/bootloader/grub.scm
+++ b/gnu/bootloader/grub.scm
@@ -9,6 +9,7 @@
9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de> 9;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de>
10;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com> 10;;; Copyright © 2022 Karl Hallsby <karl@hallsby.com>
11;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> 11;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
12;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz>
12;;; 13;;;
13;;; This file is part of GNU Guix. 14;;; This file is part of GNU Guix.
14;;; 15;;;
@@ -386,7 +387,8 @@ when booting a root file system on a Btrfs subvolume."
386 store-directory-prefix)) 387 store-directory-prefix))
387 (initrd (normalize-file (menu-entry-initrd entry) 388 (initrd (normalize-file (menu-entry-initrd entry)
388 device-mount-point 389 device-mount-point
389 store-directory-prefix))) 390 store-directory-prefix))
391 (extra-initrd (bootloader-configuration-extra-initrd config)))
390 ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point. 392 ;; Here DEVICE is the store and DEVICE-MOUNT-POINT is its mount point.
391 ;; Use the right file names for LINUX and INITRD in case 393 ;; Use the right file names for LINUX and INITRD in case
392 ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a 394 ;; DEVICE-MOUNT-POINT is not "/", meaning that the store is on a
@@ -397,11 +399,12 @@ when booting a root file system on a Btrfs subvolume."
397 #~(format port "menuentry ~s { 399 #~(format port "menuentry ~s {
398 ~a 400 ~a
399 linux ~a ~a 401 linux ~a ~a
400 initrd ~a 402 initrd ~a ~a
401}~%" 403}~%"
402 #$label 404 #$label
403 #$(grub-root-search device linux) 405 #$(grub-root-search device linux)
404 #$linux (string-join (list #$@arguments)) 406 #$linux (string-join (list #$@arguments))
407 (or #$extra-initrd "")
405 #$initrd))) 408 #$initrd)))
406 (multiboot-kernel 409 (multiboot-kernel
407 (let* ((kernel (menu-entry-multiboot-kernel entry)) 410 (let* ((kernel (menu-entry-multiboot-kernel entry))