From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 4IRuDqn37GZuLwAAqHPOHw:P1 (envelope-from ) for ; Fri, 20 Sep 2024 04:18:49 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 4IRuDqn37GZuLwAAqHPOHw (envelope-from ) for ; Fri, 20 Sep 2024 06:18:49 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=i8KLxeW0; dkim=fail ("headers rsa verify failed") header.d=lunabee.space header.s=purelymail3 header.b=p8ahLyCt; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=Fvf3bpqy; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726805928; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=W8VAygEyNCbbOC4n8gnnfwe+dFyVy83ARb/7rTKOsHk=; b=bS71ujwe60DSV6iJq6jxC1+aT0V0MLyydhm3trsi0f/6h3tjebHxUrnCK95ZvQFtD5M0OW Xbh7GjJaepWBQDpz+N5peO6bTGTloLCa9siTQBiqJNFyEAiJ5dmS2sHAfK7zT2JlpyLm/J 5qizE+5eoNLiwg6M3lihh1DwBSH5LdS4wFMF7zVB+mQn9G/40D7raj4nQaah4Ra5+WUCDO Ji6Jskd9F9Z+ZsxfxJTVm0oEuUJiAKDutjFG8sX5P9Hzbjqv0R5Vhfb9Qd0z3vB+VCV15H B/j99UM8E5vLgjxIIoBj2VBeKFeBoobq+sQQXm2+hieyLfBey8WWpRwih4x/4A== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=i8KLxeW0; dkim=fail ("headers rsa verify failed") header.d=lunabee.space header.s=purelymail3 header.b=p8ahLyCt; dkim=fail ("headers rsa verify failed") header.d=purelymail.com header.s=purelymail3 header.b=Fvf3bpqy; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726805928; a=rsa-sha256; cv=none; b=cG0mZCbgN6DnIrt/CO6zgNVZ5B9B7/8pHtqqzA0EJT+pJyJ9TnBJkB7naPFw3UMoMsQChp JfwpLUzrPCIS2PWy9+hTjgcQ29rAFRbqrPzBr6PTa9I+AvOvO3JLVBtl2DU7RnuSTMmpib KoT12qREXCU7Qw6dKVEo13YzSuBkGXqb3QGkBBfynn4H3mCXqES1Q0GbvgXKykzEHfaceP cA3/B9MyJOaC9CyxqioXRyQy6PP79eymYvmTXhsWIHu1FxU2+tAaw5FMQxs7soAArpF9Eg mBIi8PqX3ZSe1lRBNeziWruxYh8PhsVe9O5SVq1Xl/6Ie5BIDlwqlE1Z89J7GA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.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 A20A47D044 for ; Fri, 20 Sep 2024 06:18:48 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srV5f-0008DR-8S; Fri, 20 Sep 2024 00:17:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1srV5Y-0008BW-Vi for guix-patches@gnu.org; Fri, 20 Sep 2024 00:17:49 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1srV5Y-0006Fz-DT; Fri, 20 Sep 2024 00:17:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=W8VAygEyNCbbOC4n8gnnfwe+dFyVy83ARb/7rTKOsHk=; b=i8KLxeW0buSvAMEiDPkrjN9E1E8yC6upI5u/86oUcG7MvU/ONeJHgKpQkbKO/IW/Gmuz5CiTk8748dmWouZY2TCH0EqhaPPLIojndVG02+GwyGGa/S6tmut5Ltut5AaCx6TC9wDMLrvrSNJh4ZVKoLS9HQwyty8PW15FEnAIRvRtV18LKfcpi6yXw4s9FonJU+3aa7UCXaz2jNi0cQG6qMOSXCT0jr3sjcyhaiqR6qd+vQ1ADBox2+SNmgPCy7Yh8eis207dME88zfhuuxzcKwORSDJEr4AicQetZ8T9xgmCezTzkf/qSf1thWwMkCU/9lQJIfasoJEAOt0t1asJQA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1srV5n-0005TJ-Ft; Fri, 20 Sep 2024 00:18:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#69343] [PATCH v4 02/11] Move record to a separate file. Resent-From: Lilah Tascheter Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 20 Sep 2024 04:18:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69343 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69343@debbugs.gnu.org Cc: Herman Rimm , Felix Lechner , Christopher Baines , Josselin Poiret , Ludovic Court??s , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic Court??s , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 69343-submit@debbugs.gnu.org id=B69343.172680586720918 (code B ref 69343); Fri, 20 Sep 2024 04:18:03 +0000 Received: (at 69343) by debbugs.gnu.org; 20 Sep 2024 04:17:47 +0000 Received: from localhost ([127.0.0.1]:33739 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srV5V-0005RC-8Y for submit@debbugs.gnu.org; Fri, 20 Sep 2024 00:17:47 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:45752) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srV5P-0005QN-RP for 69343@debbugs.gnu.org; Fri, 20 Sep 2024 00:17:42 -0400 DKIM-Signature: a=rsa-sha256; b=p8ahLyCtvSM3gl6l/TgGjeSCfAMPOPrkVp6zEaB8k/IVszuxIKP1Yx1xEXdIqszSFjXYF/fNVnNA1UqUnqnw2BNPv+ZJ2ixZSxe0anUSQ3B4uQiR1lmARb49cy+nnQUYY72vzW5bAyPWqBexRUGD2gohe/l5u9jakblJnc/79SQWIqI3dYHn7TGsRtYaOtgnpsjBJEyfxjWUWqGxox6bPg1dER2QjtmjI9/POxCuRZLEiP+2Ri848vo6PVrQGu3qVcI47dAnDWteE7MyV3vjhNmWrNTiWUF6cQpmoXt5ZJTU4O/E6nGql/iKSjnY49Vgy3a0/9/Qn2BV30KsgiI0Eg==; s=purelymail3; d=lunabee.space; v=1; bh=oRaTEmS2mej/tH6xcejZxpSD254H6b/VBo3LygsmuCo=; h=Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=Fvf3bpqyeBlwoqlTayA8a7FIV11HjZ85KQwX9iX1VA6LhuI5jMR5VdAtTdubV1g1puk8CmmhULeAVNE/JdrruWDUE5uIRGK8GYcRpPgo0HUZD52rTwq16GW+yp9bpCBEa4Hnp/HU5TaYJpuOzSZuuvCeEhgABJEM2SHqKT86z0RkxkFEgCcv7j0ajTJljx7yumuS9ne5lw96Yf2H/P45+Cp2AqT/cPgyjriBJZzA83UD954WOb4teBMXbAZfUVNn3T/OTgc/smpSjKPWlRJdPO85PqnPYh45czRP6Yh6x0iMwHybXfevl6f7l61ftP8z3kW2GDcT3sHcly8TZ6H1ew==; s=purelymail3; d=purelymail.com; v=1; bh=oRaTEmS2mej/tH6xcejZxpSD254H6b/VBo3LygsmuCo=; h=Feedback-ID:Received:From:To:Subject:Date; Feedback-ID: 8937:2070:null:purelymail X-Pm-Original-To: 69343@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -100958845; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Fri, 20 Sep 2024 04:17:13 +0000 (UTC) Date: Thu, 19 Sep 2024 23:15:56 -0500 Message-ID: <1f574c422d47205d1f5e0fc139959d0e93280576.1726805765.git.lilah@lunabee.space> In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Lilah Tascheter via Guix-patches Reply-To: Lilah Tascheter Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: A20A47D044 X-Migadu-Scanner: mx11.migadu.com X-Spam-Score: -5.51 X-Migadu-Spam-Score: -5.51 X-TUID: jKXZp+CrsKWv From: Felix Lechner Required to avoid a missing dependency error on build-side. * gnu/system.scm (): Move this record, and... (system-linux-image-file-name, %boot-parameters-version, bootable-kernel-arguments, ensure-not-/dev, read-boot-parameters, read-boot-parameters-file, boot-parameters->menu-entry): ...these procedures, to... * gnu/system/boot.scm: ...this new file. * gnu/machine/ssh.scm, gnu/system.scm, guix/scripts/system.scm, tests/boot-parameters.scm: Use new module above. * gnu/local.mk (GNU_SYSTEM_MODULES): Add new module above. * gnu/machine/ssh.scm (machine-boot-parameters): Don't private-import bootable-kernel-arguments. --- gnu/local.mk | 1 + gnu/machine/ssh.scm | 4 +- gnu/system.scm | 287 +------------------------------- gnu/system/boot.scm | 341 ++++++++++++++++++++++++++++++++++++++ guix/scripts/system.scm | 1 + tests/boot-parameters.scm | 1 + 6 files changed, 346 insertions(+), 289 deletions(-) create mode 100644 gnu/system/boot.scm diff --git a/gnu/local.mk b/gnu/local.mk index 6d2b14e72d..8375e13709 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -758,6 +758,7 @@ GNU_SYSTEM_MODULES =3D=09=09=09=09\ =09=09=09=09=09=09\ %D%/system.scm=09=09=09=09\ %D%/system/accounts.scm=09=09=09\ + %D%/system/boot.scm=09=09=09=09\ %D%/system/file-systems.scm=09=09=09\ %D%/system/hurd.scm=09=09=09=09\ %D%/system/image.scm =09=09=09=09\ diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 0be9ebbc0d..749aa2b6d8 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -23,6 +23,7 @@ (define-module (gnu machine ssh) #:use-module (gnu machine) #:autoload (gnu packages gnupg) (guile-gcrypt) #:use-module (gnu system) + #:use-module (gnu system boot) #:use-module (gnu system file-systems) #:use-module (gnu system uuid) #:use-module ((gnu services) #:select (sexp->system-provenance)) @@ -417,9 +418,6 @@ (define not-config? (define (machine-boot-parameters machine) "Monadic procedure returning a list of 'boot-parameters' for the generat= ions of MACHINE's system profile, ordered from most recent to oldest." - (define bootable-kernel-arguments - (@@ (gnu system) bootable-kernel-arguments)) - (define remote-exp (with-extensions (list guile-gcrypt) (with-imported-modules `(((guix config) =3D> ,(make-config.scm)) diff --git a/gnu/system.scm b/gnu/system.scm index c76f4d7c50..4a084b2ecf 100644 --- a/gnu/system.scm +++ b/gnu/system.scm @@ -72,6 +72,7 @@ (define-module (gnu system) #:use-module (gnu services shepherd) #:use-module (gnu services base) #:use-module (gnu bootloader) + #:use-module (gnu system boot) #:use-module (gnu system shadow) #:use-module (gnu system nss) #:use-module (gnu system locale) @@ -145,33 +146,11 @@ (define-module (gnu system) operating-system-boot-script operating-system-uuid =20 - system-linux-image-file-name operating-system-with-gc-roots operating-system-with-provenance =20 hurd-default-essential-services =20 - boot-parameters - boot-parameters? - boot-parameters-label - boot-parameters-root-device - boot-parameters-bootloader-name - boot-parameters-bootloader-menu-entries - boot-parameters-store-crypto-devices - boot-parameters-store-device - boot-parameters-store-directory-prefix - boot-parameters-store-mount-point - boot-parameters-locale - boot-parameters-kernel - boot-parameters-kernel-arguments - boot-parameters-initrd - boot-parameters-multiboot-modules - boot-parameters-version - %boot-parameters-version - read-boot-parameters - read-boot-parameters-file - boot-parameters->menu-entry - local-host-aliases ;deprecated %root-account %setuid-programs @@ -192,29 +171,6 @@ (define-module (gnu system) ;;; ;;; Code: =20 -(define* (bootable-kernel-arguments system root-device version) - "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVI= CE. -VERSION is the target version of the boot-parameters record." - ;; If the version is newer than 0, we use the new style initrd parameter - ;; names, otherwise we use the legacy ones. This is to maintain backwar= d - ;; compatibility when producing bootloader configurations for older - ;; generations. - (define version>0? (> version 0)) - (let ((root (file-system-device->string root-device - #:uuid-type 'dce))) - (append - (if (string=3D? root "none") - '() ; Ignore the case where the root is "none" (typically tmpfs)= . - ;; Note: Always use the DCE format because that's what - ;; (gnu build linux-boot) expects for the 'root' - ;; kernel command-line option. - (list (string-append (if version>0? "root=3D" "--root=3D") root))= ) - (list #~(string-append (if #$version>0? "gnu.system=3D" "--system=3D"= ) #$system) - #~(string-append (if #$version>0? "gnu.load=3D" "--load=3D") - #$system "/boot"))))) - -;; System-wide configuration. - (define-with-syntax-properties (warn-hosts-file-field-deprecation (value properties)) (when value @@ -356,236 +312,6 @@ (define* (operating-system-kernel-arguments (append (bootable-kernel-arguments os root-device version) (operating-system-user-kernel-arguments os))) =20 -=0C -;;; -;;; Boot parameters -;;; - -;;; Version 1 was introduced early 2022 to mark the departure from long op= tion -;;; names such as '--load' to the more conventional initrd option names li= ke -;;; 'gnu.load'. -;;; -;;; When bumping the boot-parameters version, increment it by one (1). -(define %boot-parameters-version 1) - -(define-record-type* - boot-parameters make-boot-parameters boot-parameters? - (label boot-parameters-label) - ;; Because we will use the 'store-device' to create the GRUB search comm= and, - ;; the 'store-device' has slightly different semantics than 'root-device= '. - ;; The 'store-device' can be a file system uuid, a file system label, or= #f, - ;; but it cannot be a device file name such as "/dev/sda3", since GRUB w= ould - ;; not understand that. The 'root-device', on the other hand, correspon= ds - ;; exactly to the device field of the object representing = the - ;; OS's root file system, so it might be a device file name like - ;; "/dev/sda3". The 'store-directory-prefix' field contains #f or the s= tore - ;; file name inside the 'store-device' as it is seen by GRUB, e.g. it wo= uld - ;; contain "/storefs" if the store is located in that subvolume of a btr= fs - ;; partition. - (root-device boot-parameters-root-device) - (bootloader-name boot-parameters-bootloader-name) - (bootloader-menu-entries ;list of - boot-parameters-bootloader-menu-entries) - (store-device boot-parameters-store-device) - (store-mount-point boot-parameters-store-mount-point) - (store-directory-prefix boot-parameters-store-directory-prefix) - (store-crypto-devices boot-parameters-store-crypto-devices - (default '())) - (locale boot-parameters-locale) - (kernel boot-parameters-kernel) - (kernel-arguments boot-parameters-kernel-arguments) - (initrd boot-parameters-initrd) - (multiboot-modules boot-parameters-multiboot-modules) - (version boot-parameters-version ;positive integer - (default %boot-parameters-version))) - -(define (ensure-not-/dev device) - "If DEVICE starts with a slash, return #f. This is meant to filter out -Linux device names such as /dev/sda, and to preserve GRUB device names and -file system labels." - (if (and (string? device) (string-prefix? "/" device)) - #f - device)) - -(define (read-boot-parameters port) - "Read boot parameters from PORT and return the corresponding - object. Raise an error if the format is unrecognized." - (define device-sexp->device - (match-lambda - (('uuid (? symbol? type) (? bytevector? bv)) - (bytevector->uuid bv type)) - (('file-system-label (? string? label)) - (file-system-label label)) - ((? bytevector? bv) ;old format - (bytevector->uuid bv 'dce)) - ((? string? device) - (if (string-contains device ":/") - device ; nfs-root - ;; It used to be that we would not distinguish between labels a= nd - ;; device names. Try to infer the right thing here. - (if (string-prefix? "/" device) - device - (file-system-label device)))))) - (define uuid-sexp->uuid - (match-lambda - (('uuid (? symbol? type) (? bytevector? bv)) - (bytevector->uuid bv type)) - (x - (warning (G_ "unrecognized uuid ~a at '~a'~%") x (port-filename por= t)) - #f))) - - ;; New versions are not backward-compatible, so only accept past and cur= rent - ;; versions, not future ones. - (define (version? n) - (member n (iota (1+ %boot-parameters-version)))) - - (match (read port) - (('boot-parameters ('version (? version? version)) - ('label label) ('root-device root) - ('kernel kernel) - rest ...) - (boot-parameters - (version version) - (label label) - (root-device (device-sexp->device root)) - - (bootloader-name - (match (assq 'bootloader-name rest) - ((_ args) args) - (#f 'grub))) ; for compatibility reasons. - - (bootloader-menu-entries - (match (assq 'bootloader-menu-entries rest) - ((_ entries) (map sexp->menu-entry entries)) - (#f '()))) - - ;; In the past, we would store the directory name of linux instead o= f - ;; the absolute file name of its image. Detect that and correct it. - (kernel (if (string=3D? kernel (direct-store-path kernel)) - (string-append kernel "/" - (system-linux-image-file-name)) - kernel)) - - (kernel-arguments - (match (assq 'kernel-arguments rest) - ((_ args) args) - (#f '()))) ;the old format - - (initrd - (match (assq 'initrd rest) - (('initrd ('string-append directory file)) ;the old format - (string-append directory file)) - (('initrd (? string? file)) - file) - (#f #f))) - - (multiboot-modules - (match (assq 'multiboot-modules rest) - ((_ args) args) - (#f '()))) - - (locale - (match (assq 'locale rest) - ((_ locale) locale) - (#f #f))) - - (store-device - ;; Linux device names like "/dev/sda1" are not suitable GRUB device - ;; identifiers, so we just filter them out. - (ensure-not-/dev - (match (assq 'store rest) - (('store ('device #f) _ ...) - root-device) - (('store ('device device) _ ...) - (device-sexp->device device)) - (_ ;the old format - root-device)))) - - (store-directory-prefix - (match (assq 'store rest) - (('store . store-data) - (match (assq 'directory-prefix store-data) - (('directory-prefix prefix) prefix) - ;; No directory-prefix found. - (_ #f))) - (_ - ;; No store found, old format. - #f))) - - (store-crypto-devices - (match (assq 'store rest) - (('store . store-data) - (match (assq 'crypto-devices store-data) - (('crypto-devices (devices ...)) - (map uuid-sexp->uuid devices)) - (('crypto-devices dev) - (warning (G_ "unrecognized crypto-devices ~S at '~a'~%") - dev (port-filename port)) - '()) - (_ - ;; No crypto-devices found. - '()))) - (_ - ;; No store found, old format. - '()))) - - (store-mount-point - (match (assq 'store rest) - (('store ('device _) ('mount-point mount-point) _ ...) - mount-point) - (_ ;the old format - "/"))))) - (x ;unsupported format - (raise - (make-compound-condition - (formatted-message - (G_ "unrecognized boot parameters at '~a'~%") - (port-filename port)) - (condition - (&fix-hint (hint (format #f (G_ "This probably means that this ver= sion -of Guix is older than the one that created @file{~a}. To address this, yo= u -need to update Guix: - -@example -guix pull -@end example") - (port-filename port)))))))))) - -(define (read-boot-parameters-file system) - "Read boot parameters from SYSTEM's (system or generation) \"parameters\= " -file and returns the corresponding object or #f if the -format is unrecognized. -The object has its kernel-arguments extended in order to make it bootable.= " - (let* ((file (string-append system "/parameters")) - (params (call-with-input-file file read-boot-parameters)) - (root (boot-parameters-root-device params)) - (version (boot-parameters-version params))) - (boot-parameters - (inherit params) - (kernel-arguments (append (bootable-kernel-arguments system root vers= ion) - (boot-parameters-kernel-arguments params)))= ))) - -(define (boot-parameters->menu-entry conf) - "Return a instance given CONF, a instance= ." - (let* ((kernel (boot-parameters-kernel conf)) - (multiboot-modules (boot-parameters-multiboot-modules conf)) - (multiboot? (pair? multiboot-modules))) - (menu-entry - (label (boot-parameters-label conf)) - (device (boot-parameters-store-device conf)) - (device-mount-point (boot-parameters-store-mount-point conf)) - (linux (and (not multiboot?) kernel)) - (linux-arguments (if (not multiboot?) - (boot-parameters-kernel-arguments conf) - '())) - (initrd (boot-parameters-initrd conf)) - (multiboot-kernel (and multiboot? kernel)) - (multiboot-arguments (if multiboot? - (boot-parameters-kernel-arguments conf) - '())) - (multiboot-modules (if multiboot? - (boot-parameters-multiboot-modules conf) - '()))))) =20 =0C ;;; @@ -726,17 +452,6 @@ (define (swap-services os) (map (compose swap-service filter-deps) (operating-system-swap-devices os))) =20 -(define* (system-linux-image-file-name #:optional - (target (or (%current-target-system= ) - (%current-system)))) - "Return the basename of the kernel image file for TARGET." - (cond - ((string-prefix? "arm" target) "zImage") - ((string-prefix? "mips" target) "vmlinuz") - ((string-prefix? "aarch64" target) "Image") - ((string-prefix? "riscv64" target) "Image") - (else "bzImage"))) - (define (operating-system-kernel-file os) "Return an object representing the absolute file name of the kernel imag= e of OS." diff --git a/gnu/system/boot.scm b/gnu/system/boot.scm new file mode 100644 index 0000000000..df27b8aea4 --- /dev/null +++ b/gnu/system/boot.scm @@ -0,0 +1,341 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright =C2=A9 2013-2022 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2015 Mark H Weaver +;;; Copyright =C2=A9 2015, 2016 Alex Kost +;;; Copyright =C2=A9 2016 Chris Marusich +;;; Copyright =C2=A9 2017 Mathieu Othacehe +;;; Copyright =C2=A9 2019 Meiyo Peng +;;; Copyright =C2=A9 2019, 2020 Miguel =C3=81ngel Arruga Vivas +;;; Copyright =C2=A9 2020 Danny Milosavljevic +;;; Copyright =C2=A9 2020, 2021 Brice Waegeneire +;;; Copyright =C2=A9 2020 Florian Pelz +;;; Copyright =C2=A9 2020, 2022 Maxim Cournoyer +;;; Copyright =C2=A9 2020, 2023 Janneke Nieuwenhuizen +;;; Copyright =C2=A9 2020, 2022 Efraim Flashner +;;; Copyright =C2=A9 2021 Maxime Devos +;;; Copyright =C2=A9 2021 raid5atemyhomework +;;; Copyright =C2=A9 2023 Bruno Victal +;;; Copyright =C2=A9 2023 Felix Lechner +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu system boot) + #:use-module (guix gexp) + #:use-module (guix diagnostics) + #:use-module (guix i18n) + #:use-module (guix records) + #:use-module (guix store) + #:use-module (guix utils) + #:use-module (gnu bootloader) + #:use-module (gnu system file-systems) + #:use-module (gnu system uuid) + #:use-module (ice-9 format) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) + #:use-module (rnrs bytevectors) + #:export (boot-parameters + boot-parameters? + boot-parameters-label + boot-parameters-root-device + boot-parameters-bootloader-name + boot-parameters-bootloader-menu-entries + boot-parameters-store-crypto-devices + boot-parameters-store-device + boot-parameters-store-directory-prefix + boot-parameters-store-mount-point + boot-parameters-locale + boot-parameters-kernel + boot-parameters-kernel-arguments + boot-parameters-initrd + boot-parameters-multiboot-modules + boot-parameters-version + %boot-parameters-version + + read-boot-parameters + read-boot-parameters-file + bootable-kernel-arguments + + boot-parameters->menu-entry + + ensure-not-/dev + system-linux-image-file-name)) + +;;; +;;; Boot parameters +;;; + +;;; Version 1 was introduced early 2022 to mark the departure from long op= tion +;;; names such as '--load' to the more conventional initrd option names li= ke +;;; 'gnu.load'. +;;; +;;; When bumping the boot-parameters version, increment it by one (1). +(define %boot-parameters-version 1) + +(define-record-type* + boot-parameters make-boot-parameters boot-parameters? + (label boot-parameters-label) + ;; Because we will use the 'store-device' to create the GRUB search comm= and, + ;; the 'store-device' has slightly different semantics than 'root-device= '. + ;; The 'store-device' can be a file system uuid, a file system label, or= #f, + ;; but it cannot be a device file name such as "/dev/sda3", since GRUB w= ould + ;; not understand that. The 'root-device', on the other hand, correspon= ds + ;; exactly to the device field of the object representing = the + ;; OS's root file system, so it might be a device file name like + ;; "/dev/sda3". The 'store-directory-prefix' field contains #f or the s= tore + ;; file name inside the 'store-device' as it is seen by GRUB, e.g. it wo= uld + ;; contain "/storefs" if the store is located in that subvolume of a btr= fs + ;; partition. + (root-device boot-parameters-root-device) + (bootloader-name boot-parameters-bootloader-name) + (bootloader-menu-entries ;list of + boot-parameters-bootloader-menu-entries) + (store-device boot-parameters-store-device) + (store-mount-point boot-parameters-store-mount-point) + (store-directory-prefix boot-parameters-store-directory-prefix) + (store-crypto-devices boot-parameters-store-crypto-devices + (default '())) + (locale boot-parameters-locale) + (kernel boot-parameters-kernel) + (kernel-arguments boot-parameters-kernel-arguments) + (initrd boot-parameters-initrd) + (multiboot-modules boot-parameters-multiboot-modules) + (version boot-parameters-version ;positive integer + (default %boot-parameters-version))) + +(define (read-boot-parameters port) + "Read boot parameters from PORT and return the corresponding + object. Raise an error if the format is unrecognized." + (define device-sexp->device + (match-lambda + (('uuid (? symbol? type) (? bytevector? bv)) + (bytevector->uuid bv type)) + (('file-system-label (? string? label)) + (file-system-label label)) + ((? bytevector? bv) ;old format + (bytevector->uuid bv 'dce)) + ((? string? device) + (if (string-contains device ":/") + device ; nfs-root + ;; It used to be that we would not distinguish between labels a= nd + ;; device names. Try to infer the right thing here. + (if (string-prefix? "/" device) + device + (file-system-label device)))))) + (define uuid-sexp->uuid + (match-lambda + (('uuid (? symbol? type) (? bytevector? bv)) + (bytevector->uuid bv type)) + (x + (warning (G_ "unrecognized uuid ~a at '~a'~%") x (port-filename por= t)) + #f))) + + ;; New versions are not backward-compatible, so only accept past and cur= rent + ;; versions, not future ones. + (define (version? n) + (member n (iota (1+ %boot-parameters-version)))) + + (match (read port) + (('boot-parameters ('version (? version? version)) + ('label label) ('root-device root) + ('kernel kernel) + rest ...) + (boot-parameters + (version version) + (label label) + (root-device (device-sexp->device root)) + + (bootloader-name + (match (assq 'bootloader-name rest) + ((_ args) args) + (#f 'grub))) ; for compatibility reasons. + + (bootloader-menu-entries + (match (assq 'bootloader-menu-entries rest) + ((_ entries) (map sexp->menu-entry entries)) + (#f '()))) + + ;; In the past, we would store the directory name of linux instead o= f + ;; the absolute file name of its image. Detect that and correct it. + (kernel (if (string=3D? kernel (direct-store-path kernel)) + (string-append kernel "/" + (system-linux-image-file-name)) + kernel)) + + (kernel-arguments + (match (assq 'kernel-arguments rest) + ((_ args) args) + (#f '()))) ;the old format + + (initrd + (match (assq 'initrd rest) + (('initrd ('string-append directory file)) ;the old format + (string-append directory file)) + (('initrd (? string? file)) + file) + (#f #f))) + + (multiboot-modules + (match (assq 'multiboot-modules rest) + ((_ args) args) + (#f '()))) + + (locale + (match (assq 'locale rest) + ((_ locale) locale) + (#f #f))) + + (store-device + ;; Linux device names like "/dev/sda1" are not suitable GRUB device + ;; identifiers, so we just filter them out. + (ensure-not-/dev + (match (assq 'store rest) + (('store ('device #f) _ ...) + root-device) + (('store ('device device) _ ...) + (device-sexp->device device)) + (_ ;the old format + root-device)))) + + (store-directory-prefix + (match (assq 'store rest) + (('store . store-data) + (match (assq 'directory-prefix store-data) + (('directory-prefix prefix) prefix) + ;; No directory-prefix found. + (_ #f))) + (_ + ;; No store found, old format. + #f))) + + (store-crypto-devices + (match (assq 'store rest) + (('store . store-data) + (match (assq 'crypto-devices store-data) + (('crypto-devices (devices ...)) + (map uuid-sexp->uuid devices)) + (('crypto-devices dev) + (warning (G_ "unrecognized crypto-devices ~S at '~a'~%") + dev (port-filename port)) + '()) + (_ + ;; No crypto-devices found. + '()))) + (_ + ;; No store found, old format. + '()))) + + (store-mount-point + (match (assq 'store rest) + (('store ('device _) ('mount-point mount-point) _ ...) + mount-point) + (_ ;the old format + "/"))))) + (x ;unsupported format + (raise + (make-compound-condition + (formatted-message + (G_ "unrecognized boot parameters at '~a'~%") + (port-filename port)) + (condition + (&fix-hint (hint (format #f (G_ "This probably means that this ver= sion +of Guix is older than the one that created @file{~a}. To address this, yo= u +need to update Guix: + +@example +guix pull +@end example") + (port-filename port)))))))))) + +(define (read-boot-parameters-file system) + "Read boot parameters from SYSTEM's (system or generation) \"parameters\= " +file and returns the corresponding object or #f if the +format is unrecognized. +The object has its kernel-arguments extended in order to make it bootable.= " + (let* ((file (string-append system "/parameters")) + (params (call-with-input-file file read-boot-parameters)) + (root (boot-parameters-root-device params)) + (version (boot-parameters-version params))) + (boot-parameters + (inherit params) + (kernel-arguments (append (bootable-kernel-arguments system root vers= ion) + (boot-parameters-kernel-arguments params)))= ))) + +(define* (bootable-kernel-arguments system root-device version) + "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVI= CE. +VERSION is the target version of the boot-parameters record." + ;; If the version is newer than 0, we use the new style initrd parameter + ;; names, otherwise we use the legacy ones. This is to maintain backwar= d + ;; compatibility when producing bootloader configurations for older + ;; generations. + (define version>0? (> version 0)) + (let ((root (file-system-device->string root-device + #:uuid-type 'dce))) + (append + (if (string=3D? root "none") + '() ; Ignore the case where the root is "none" (typically tmpfs)= . + ;; Note: Always use the DCE format because that's what + ;; (gnu build linux-boot) expects for the 'root' + ;; kernel command-line option. + (list (string-append (if version>0? "root=3D" "--root=3D") root))= ) + (list #~(string-append (if #$version>0? "gnu.system=3D" "--system=3D"= ) #$system) + #~(string-append (if #$version>0? "gnu.load=3D" "--load=3D") + #$system "/boot"))))) + +(define (boot-parameters->menu-entry conf) + "Return a instance given CONF, a instance= ." + (let* ((kernel (boot-parameters-kernel conf)) + (multiboot-modules (boot-parameters-multiboot-modules conf)) + (multiboot? (pair? multiboot-modules))) + (menu-entry + (label (boot-parameters-label conf)) + (device (boot-parameters-store-device conf)) + (device-mount-point (boot-parameters-store-mount-point conf)) + (linux (and (not multiboot?) kernel)) + (linux-arguments (if (not multiboot?) + (boot-parameters-kernel-arguments conf) + '())) + (initrd (boot-parameters-initrd conf)) + (multiboot-kernel (and multiboot? kernel)) + (multiboot-arguments (if multiboot? + (boot-parameters-kernel-arguments conf) + '())) + (multiboot-modules (if multiboot? + (boot-parameters-multiboot-modules conf) + '()))))) + +(define (ensure-not-/dev device) + "If DEVICE starts with a slash, return #f. This is meant to filter out +Linux device names such as /dev/sda, and to preserve GRUB device names and +file system labels." + (if (and (string? device) (string-prefix? "/" device)) + #f + device)) + +;; XXX: defined here instead of (gnu system) to prevent dependency loop +(define* (system-linux-image-file-name #:optional + (target (or (%current-target-system= ) + (%current-system)))) + "Return the basename of the kernel image file for TARGET." + (cond + ((string-prefix? "arm" target) "zImage") + ((string-prefix? "mips" target) "vmlinuz") + ((string-prefix? "aarch64" target) "Image") + ((string-prefix? "riscv64" target) "Image") + (else "bzImage"))) + +;;; boot.scm ends here diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 0305128763..7000c470ed 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -70,6 +70,7 @@ (define-module (guix scripts system) #:use-module (gnu image) #:use-module (gnu system) #:use-module (gnu bootloader) + #:use-module (gnu system boot) #:use-module (gnu system file-systems) #:use-module (gnu system image) #:use-module (gnu system mapped-devices) diff --git a/tests/boot-parameters.scm b/tests/boot-parameters.scm index 03a1d01aff..2e7976aa6c 100644 --- a/tests/boot-parameters.scm +++ b/tests/boot-parameters.scm @@ -27,6 +27,7 @@ (define-module (test-boot-parameters) #:use-module (gnu bootloader) #:use-module (gnu bootloader grub) #:use-module (gnu system) + #:use-module (gnu system boot) #:use-module (gnu system file-systems) #:use-module (gnu system uuid) #:use-module ((guix diagnostics) #:select (formatted-message?)) --=20 2.45.2