diff options
author | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-10-19 12:51:57 -0400 |
---|---|---|
committer | Maxim Cournoyer <maxim.cournoyer@gmail.com> | 2020-10-19 13:11:40 -0400 |
commit | 5e2140511c1ad9ccd731438b74d61b62111da1e6 (patch) | |
tree | a4ff748ad26e121b88469b5d921001ef1382be8f /gnu/bootloader | |
parent | 9e3a5ee417ea7fe9721be8804ff047e80c4f22ed (diff) | |
parent | 353bdae32f72b720c7ddd706576ccc40e2b43f95 (diff) | |
download | guix-5e2140511c1ad9ccd731438b74d61b62111da1e6.tar.gz guix-5e2140511c1ad9ccd731438b74d61b62111da1e6.zip |
Merge branch 'staging'
Conflicts:
gnu/packages/admin.scm
gnu/packages/commencement.scm
gnu/packages/gdb.scm
gnu/packages/llvm.scm
gnu/packages/package-management.scm
gnu/packages/tls.scm
Diffstat (limited to 'gnu/bootloader')
-rw-r--r-- | gnu/bootloader/grub.scm | 132 | ||||
-rw-r--r-- | gnu/bootloader/u-boot.scm | 69 |
2 files changed, 163 insertions, 38 deletions
diff --git a/gnu/bootloader/grub.scm b/gnu/bootloader/grub.scm index f69bf8ed4d..611580a350 100644 --- a/gnu/bootloader/grub.scm +++ b/gnu/bootloader/grub.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2017 Leo Famulari <leo@famulari.name> ;;; Copyright © 2017, 2020 Mathieu Othacehe <m.othacehe@gmail.com> ;;; Copyright © 2019, 2020 Jan (janneke) Nieuwenhuizen <janneke@gnu.org> +;;; Copyright © 2019 Miguel Ángel Arruga Vivas <rosen644835@gmail.com> ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> ;;; Copyright © 2020 Stefan <stefan-guix@vodafonemail.de> ;;; @@ -23,14 +24,17 @@ ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. (define-module (gnu bootloader grub) + #:use-module (guix build union) #:use-module (guix records) - #:use-module ((guix utils) #:select (%current-system)) + #:use-module (guix store) + #:use-module (guix utils) #:use-module (guix gexp) #:use-module (gnu artwork) #:use-module (gnu bootloader) #:use-module (gnu system uuid) #:use-module (gnu system file-systems) #:use-module (gnu system keyboard) + #:use-module (gnu system locale) #:use-module (gnu packages bootloaders) #:autoload (gnu packages gtk) (guile-cairo guile-rsvg) #:autoload (gnu packages xorg) (xkeyboard-config) @@ -46,8 +50,11 @@ grub-theme-color-highlight grub-theme-gfxmode + install-grub-efi-netboot + grub-bootloader grub-efi-bootloader + grub-efi-netboot-bootloader grub-mkrescue-bootloader grub-minimal-bootloader @@ -297,9 +304,11 @@ code." (file-system-label->string label))) ((? (lambda (device) (and (string? device) (string-contains device ":/"))) nfs-uri) - ;; This assumes that if your root file system is on NFS, then - ;; you also want to load your grub extra files, kernel and initrd - ;; from there. + ;; If the device is an NFS share, then we assume that the expected + ;; file on that device (e.g. the GRUB background image or the kernel) + ;; has to be loaded over the network. Otherwise we would need an + ;; additional device information for some local disk to look for that + ;; file, which we do not have. ;; ;; We explicitly set "root=(tftp)" here even though if grub.cfg ;; had been loaded via TFTP, Grub would have set "root=(tftp)" @@ -327,6 +336,7 @@ code." (define* (grub-configuration-file config entries #:key + (locale #f) (system (%current-system)) (old-entries '()) store-directory-prefix) @@ -391,6 +401,20 @@ menuentry ~s { #:store-directory-prefix store-directory-prefix #:port #~port))) + (define locale-config + #~(let ((locale #$(and locale + (locale-definition-source + (locale-name->definition locale))))) + (when locale + (format port "\ +# Localization configuration. +if search --file --set boot_partition /grub/grub.cfg; then + set locale_dir=(${boot_partition})/grub/locale +else + set locale_dir=/boot/grub/locale +fi +set lang=~a~%" locale)))) + (define keyboard-layout-config (let* ((layout (bootloader-configuration-keyboard-layout config)) (grub (bootloader-package @@ -415,6 +439,7 @@ keymap ~a~%" #$keymap)))) # will be lost upon reconfiguration. ") #$(sugar) + #$locale-config #$keyboard-layout-config (format port " set default=~a @@ -528,6 +553,99 @@ fi~%")))) "--bootloader-id=Guix" "--efi-directory" target-esp)))) +(define (install-grub-efi-netboot subdir) + "Define a grub-efi-netboot bootloader installer for installation in SUBDIR, +which is usually efi/Guix or efi/boot." + (let* ((system (string-split (nix-system->gnu-triplet + (or (%current-target-system) + (%current-system))) + #\-)) + (arch (first system)) + (boot-efi-link (match system + ;; These are the supportend systems and the names + ;; defined by the UEFI standard for removable media. + (("i686" _ ...) "/bootia32.efi") + (("x86_64" _ ...) "/bootx64.efi") + (("arm" _ ...) "/bootarm.efi") + (("aarch64" _ ...) "/bootaa64.efi") + (("riscv" _ ...) "/bootriscv32.efi") + (("riscv64" _ ...) "/bootriscv64.efi") + ;; Other systems are not supported, although defined. + ;; (("riscv128" _ ...) "/bootriscv128.efi") + ;; (("ia64" _ ...) "/bootia64.efi") + ((_ ...) #f))) + (core-efi (string-append + ;; This is the arch dependent file name of GRUB, e.g. + ;; i368-efi/core.efi or arm64-efi/core.efi. + (match arch + ("i686" "i386") + ("aarch64" "arm64") + ("riscv" "riscv32") + (_ arch)) + "-efi/core.efi"))) + (with-imported-modules + '((guix build union)) + #~(lambda (bootloader target mount-point) + "Install the BOOTLOADER, which must be the package grub, as e.g. +bootx64.efi or bootaa64.efi into SUBDIR, which is usually efi/Guix or efi/boot, +below the directory TARGET for the system whose root is mounted at MOUNT-POINT. + +MOUNT-POINT is the last argument in 'guix system init /etc/config.scm mnt/point' +or '/' for other 'guix system' commands. + +TARGET is the target argument given to the bootloader-configuration in + +(operating-system + (bootloader (bootloader-configuration + (target \"/boot\") + …)) + …) + +TARGET is required to be an absolute directory name, usually mounted via NFS, +and finally needs to be provided by a TFTP server as the TFTP root directory. + +GRUB will load tftp://server/SUBDIR/grub.cfg and this file will instruct it to +load more files from the store like tftp://server/gnu/store/…-linux…/Image. + +To make this possible two symlinks will be created. The first symlink points +relatively form MOUNT-POINT/TARGET/SUBDIR/grub.cfg to +MOUNT-POINT/boot/grub/grub.cfg, and the second symlink points relatively from +MOUNT-POINT/TARGET/%store-prefix to MOUNT-POINT/%store-prefix. + +It is important to note that these symlinks need to be relativ, as the absolute +paths on the TFTP server side are unknown. + +It is also important to note that both symlinks will point outside the TFTP root +directory and that the TARGET/%store-prefix symlink makes the whole store +accessible via TFTP. Possibly the TFTP server must be configured +to allow accesses outside its TFTP root directory. This may need to be +considered for security aspects." + (use-modules ((guix build union) #:select (symlink-relative))) + (let* ((net-dir (string-append mount-point target "/")) + (sub-dir (string-append net-dir #$subdir "/")) + (store (string-append mount-point (%store-prefix))) + (store-link (string-append net-dir (%store-prefix))) + (grub-cfg (string-append mount-point "/boot/grub/grub.cfg")) + (grub-cfg-link (string-append sub-dir (basename grub-cfg))) + (boot-efi-link (string-append sub-dir #$boot-efi-link))) + ;; Prepare the symlink to the store. + (mkdir-p (dirname store-link)) + (false-if-exception (delete-file store-link)) + (symlink-relative store store-link) + ;; Prepare the symlink to the grub.cfg, which points into the store. + (mkdir-p (dirname grub-cfg-link)) + (false-if-exception (delete-file grub-cfg-link)) + (symlink-relative grub-cfg grub-cfg-link) + ;; Install GRUB, which refers to the grub.cfg, with support for + ;; encrypted partitions, + (setenv "GRUB_ENABLE_CRYPTODISK" "y") + (invoke/quiet (string-append bootloader "/bin/grub-mknetdir") + (string-append "--net-directory=" net-dir) + (string-append "--subdir=" #$subdir)) + ;; Prepare the bootloader symlink, which points to core.efi of GRUB. + (false-if-exception (delete-file boot-efi-link)) + (symlink #$core-efi boot-efi-link)))))) + ;;; @@ -560,6 +678,12 @@ fi~%")))) (name 'grub-efi) (package grub-efi))) +(define grub-efi-netboot-bootloader + (bootloader + (inherit grub-efi-bootloader) + (name 'grub-efi-netboot-bootloader) + (installer (install-grub-efi-netboot "efi/Guix")))) + (define grub-mkrescue-bootloader (bootloader (inherit grub-efi-bootloader) diff --git a/gnu/bootloader/u-boot.scm b/gnu/bootloader/u-boot.scm index 1da9d04eb2..c57d4964c8 100644 --- a/gnu/bootloader/u-boot.scm +++ b/gnu/bootloader/u-boot.scm @@ -45,7 +45,7 @@ u-boot-wandboard-bootloader)) (define install-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (if bootloader (error "Failed to install U-Boot")))) @@ -56,74 +56,74 @@ ;; the MLO and is expected at 0x60000. Write both first stage ("MLO") and ;; second stage ("u-boot.img") images, read in BOOTLOADER directory, to the ;; specified DEVICE. - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((mlo (string-append bootloader "/libexec/MLO")) (u-boot (string-append bootloader "/libexec/u-boot.img"))) (write-file-on-device mlo (* 256 512) - device (* 256 512)) + image (* 256 512)) (write-file-on-device u-boot (* 1024 512) - device (* 768 512))))) + image (* 768 512))))) (define install-allwinner-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((u-boot (string-append bootloader "/libexec/u-boot-sunxi-with-spl.bin"))) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 8 1024))))) + image (* 8 1024))))) (define install-allwinner64-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((spl (string-append bootloader "/libexec/spl/sunxi-spl.bin")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device spl (stat:size (stat spl)) - device (* 8 1024)) + image (* 8 1024)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 40 1024))))) + image (* 40 1024))))) (define install-imx-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((spl (string-append bootloader "/libexec/SPL")) (u-boot (string-append bootloader "/libexec/u-boot.img"))) (write-file-on-device spl (stat:size (stat spl)) - device (* 1 1024)) + image (* 1 1024)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 69 1024))))) + image (* 69 1024))))) (define install-puma-rk3399-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((spl (string-append bootloader "/libexec/u-boot-spl.rksd")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device spl (stat:size (stat spl)) - device (* 64 512)) + image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 512 512))))) + image (* 512 512))))) (define install-firefly-rk3399-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((idb (string-append bootloader "/libexec/idbloader.img")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device idb (stat:size (stat idb)) - device (* 64 512)) + image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 16384 512))))) + image (* 16384 512))))) (define install-rock64-rk3328-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((idb (string-append bootloader "/libexec/idbloader.img")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device idb (stat:size (stat idb)) - device (* 64 512)) + image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 16384 512))))) + image (* 16384 512))))) (define install-rockpro64-rk3399-u-boot - #~(lambda (bootloader device mount-point) + #~(lambda (bootloader root-index image) (let ((idb (string-append bootloader "/libexec/idbloader.img")) (u-boot (string-append bootloader "/libexec/u-boot.itb"))) (write-file-on-device idb (stat:size (stat idb)) - device (* 64 512)) + image (* 64 512)) (write-file-on-device u-boot (stat:size (stat u-boot)) - device (* 16384 512))))) + image (* 16384 512))))) (define install-pinebook-pro-rk3399-u-boot install-rockpro64-rk3399-u-boot) @@ -138,28 +138,29 @@ (inherit extlinux-bootloader) (name 'u-boot) (package #f) - (installer install-u-boot))) + (installer #f) + (disk-image-installer install-u-boot))) (define u-boot-beaglebone-black-bootloader (bootloader (inherit u-boot-bootloader) (package u-boot-am335x-boneblack) - (installer install-beaglebone-black-u-boot))) + (disk-image-installer install-beaglebone-black-u-boot))) (define u-boot-allwinner-bootloader (bootloader (inherit u-boot-bootloader) - (installer install-allwinner-u-boot))) + (disk-image-installer install-allwinner-u-boot))) (define u-boot-allwinner64-bootloader (bootloader (inherit u-boot-bootloader) - (installer install-allwinner64-u-boot))) + (disk-image-installer install-allwinner64-u-boot))) (define u-boot-imx-bootloader (bootloader (inherit u-boot-bootloader) - (installer install-imx-u-boot))) + (disk-image-installer install-imx-u-boot))) (define u-boot-nintendo-nes-classic-edition-bootloader (bootloader @@ -196,7 +197,7 @@ (bootloader (inherit u-boot-bootloader) (package u-boot-firefly-rk3399) - (installer install-firefly-rk3399-u-boot))) + (disk-image-installer install-firefly-rk3399-u-boot))) (define u-boot-mx6cuboxi-bootloader (bootloader @@ -232,25 +233,25 @@ (bootloader (inherit u-boot-bootloader) (package u-boot-puma-rk3399) - (installer install-puma-rk3399-u-boot))) + (disk-image-installer install-puma-rk3399-u-boot))) (define u-boot-rock64-rk3328-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-rock64-rk3328) - (installer install-rock64-rk3328-u-boot))) + (disk-image-installer install-rock64-rk3328-u-boot))) (define u-boot-rockpro64-rk3399-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-rockpro64-rk3399) - (installer install-rockpro64-rk3399-u-boot))) + (disk-image-installer install-rockpro64-rk3399-u-boot))) (define u-boot-pinebook-pro-rk3399-bootloader ;; SD and eMMC use the same format (bootloader (inherit u-boot-bootloader) (package u-boot-pinebook-pro-rk3399) - (installer install-pinebook-pro-rk3399-u-boot))) + (disk-image-installer install-pinebook-pro-rk3399-u-boot))) |