From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id EITzCQ+RbWc2AgEA62LTzQ:P1 (envelope-from ) for ; Thu, 26 Dec 2024 17:23:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id EITzCQ+RbWc2AgEA62LTzQ (envelope-from ) for ; Thu, 26 Dec 2024 18:23:27 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=mrn1iYpN; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=kZmPNaFv; 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=1735233806; h=from:from:sender:sender: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=9P4utUHWmRsPORMY3XA2mVA2MNuJaXM/puZA2rLk+UE=; b=CJpfHh0qhgRVYEgbTaXmFfQdsihD0cc8bAnaSmEGZi6zbUHy84RyM3uHzFhlueXC9ROZ4z CTnEciiyzyvKj1remZTZjflgdn7vEPB2pIWwAeb16WkA+dC6fj/3qpDoM9sefnnyhfzj9j vqDjka2iqOhOepkNvanNANQqrQWn+hbZu4tu2luG+wf9jbq8cKCcK43EZDOCIQja5Xp4m2 wKJjy+Q2iNlI3HPpDyuuW/7RQ0lxsuUH2fQWzwoypcgAZP1Qd0Tai3LeP8LxmX/9AB73bK Ifi8Za6Ta6Rg6caSmh1Ap4A6AiNq5daCAst3wkMvoo4+XnMyHWNP4knnOq7WAQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=mrn1iYpN; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=kZmPNaFv; 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=1735233806; a=rsa-sha256; cv=none; b=UAe5+nesbqj6u2iy7i8McWJSfSI0OU2RV8FIQJmwqo2zds+hduw1so30GAECj3nM+pnHAM O2nYPgpkdNDHtxHoeIBLBhx6GXLYSXzYUsk7wLcv5P8pyRwdF/9217RdXA66Q4VkeobEHc ypbVI7+gWmxghBltqrsHrmT2def0MdbHKScE+Ad9nz0fUwV1gEI/6/w+qFdxTs6/00zaYo zCrREUyQDwxDefY4nL7de0H9RWrJ5Qbz+UNyYknaRqZF68DTW4xTqhiFtuOELhXr3zDDfP pTKTbEWzjM/IL5GTjRcJjoHKhF8UnV1H+o1SjN8vcfCD2L8l/jn+HDi1Lg57Ig== 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 A0CD297EE7 for ; Thu, 26 Dec 2024 18:23:26 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tQrZj-0002Sd-9L; Thu, 26 Dec 2024 12:23:07 -0500 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 1tQrZh-0002S2-JT for guix-patches@gnu.org; Thu, 26 Dec 2024 12:23:05 -0500 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 1tQrZh-0002wR-AY; Thu, 26 Dec 2024 12:23:05 -0500 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=/tWSKi0lZ78pv0mBa49SUzvFnysFfR7QOqCUlW91oPI=; b=mrn1iYpN10Uz09hIANcJ24gnqTxenl6Qy0zlh+e7oZCdJEh7DItSnaNGQ6kceVtfphjHS9eR7UZBST+t1ZN0P1W4MFuLoGoK15D/Zyf6NoJTtzzwM/5PxbVxNPBxU8oribgYn6cDDq3GrBG73sqKqj04RZ+fwZ3i4OCV0G7EINQHfd/a9lBWbQspya9CD95sd93YivRljiwjN6So2JJVaODqugu+Gto1Hr2p81hrG0gEzRDTLtW2v036DfVGwOWyjCb3k2nHRujX9YQIRd99ubgYHCTXfo+wiwiqTBnq7+qH594cTklnBksSokoxtFLNmvkNO7w4ttVhT+RQEHFXfA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tQrZf-0000Qz-6d; Thu, 26 Dec 2024 12:23:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75027] [PATCH v2 3/3] reconfigure: Support loading the system for kexec reboot. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 26 Dec 2024 17:23:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75027 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75027@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75027-submit@debbugs.gnu.org id=B75027.17352337251555 (code B ref 75027); Thu, 26 Dec 2024 17:23:03 +0000 Received: (at 75027) by debbugs.gnu.org; 26 Dec 2024 17:22:05 +0000 Received: from localhost ([127.0.0.1]:42057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQrYi-0000Ou-VN for submit@debbugs.gnu.org; Thu, 26 Dec 2024 12:22:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33128) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tQrYX-0000NP-Rr for 75027@debbugs.gnu.org; Thu, 26 Dec 2024 12:21:55 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tQrYS-0002sv-At; Thu, 26 Dec 2024 12:21:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=/tWSKi0lZ78pv0mBa49SUzvFnysFfR7QOqCUlW91oPI=; b=kZmPNaFvytAL2TxHjRAN xkG8TJ2gtHjYh7uuFT3iqHpSvouPZha8LqmD4T8N+kA1YKPv6LI6BkARpF2tP4g7EGjzPaaDd7Rml 7NTIdbLISAKKLQ1GrtGw7anuHG8yJ9Vhfh/y1FMt3cu6zIt2blOXz5jbfJm1LjkHRYGcF9KvhSlhc u2uEqOcw6UCleBqjj7Hh2b6PBM1d3LuEppyVyjWGLjH/UHh83Vh9VHRFk3BMLpjQRrNhX16Lrb3Ox L4EUgY2GQsKQ8C8I9XcoYbW25P1nqj2OC2s6foPBCMmfSBgjLCvtB+GXpPTwYAExrXd8De/HuZYXM txov5J6u6AUqgQ==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 26 Dec 2024 18:21:27 +0100 Message-ID: <9a41b8595756a8eb9e792236097f175d6f952257.1735233263.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.61 X-Spam-Score: -4.61 X-Migadu-Queue-Id: A0CD297EE7 X-Migadu-Scanner: mx10.migadu.com X-TUID: F/SzfGP7mYe9 This allows rebooting straight into the new system with ‘reboot -k’. * guix/scripts/system/reconfigure.scm (kexec-loading-program) (load-system-for-kexec): New procedures. * gnu/tests/reconfigure.scm (run-kexec-test): New procedure. (%test-upgrade-kexec): New variable. * guix/scripts/system.scm (perform-action): Add #:load-for-kexec?. Call ‘load-system-for-kexec’. (show-help, %options): Add ‘--no-kexec’. (%default-options): Add ‘load-for-kexec?’. (process-action): Honor it and pass it to ‘perform-action’. * gnu/machine/ssh.scm (deploy-managed-host): Add call to ‘load-system-for-kexec’. * doc/guix.texi (Invoking guix system): Document it. Change-Id: I86d11f1c348e4359bc9e73c86e5aebff60fe875c --- doc/guix.texi | 11 +++- gnu/machine/ssh.scm | 9 +++- gnu/tests/reconfigure.scm | 78 +++++++++++++++++++++++++++++ guix/scripts/system.scm | 17 ++++++- guix/scripts/system/reconfigure.scm | 31 ++++++++++++ 5 files changed, 143 insertions(+), 3 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index da4d2f5ebc..7bf14a49e9 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -43599,11 +43599,20 @@ Invoking guix system overwritten. This behavior mirrors that of @command{guix package} (@pxref{Invoking guix package}). -It also adds a bootloader menu entry for the new OS configuration, +It adds a bootloader menu entry for the new OS configuration, ---unless @option{--no-bootloader} is passed. For GRUB, it moves entries for older configurations to a submenu, allowing you to choose an older system generation at boot time should you need it. +@cindex kexec, for fast reboots +@cindex rebooting @i{via} Linux kexec +On Linux, @command{guix system reconfigure} also loads the new system +for fast reboot @i{via} kexec: running @command{reboot --kexec} will +boot the new system by directly executing its kernel, thus bypassing the +BIOS initialization phase and bootloader (@pxref{Invoking reboot,,, +shepherd, The GNU Shepherd Manual}). You can avoid this behavior by +passing the @option{--no-kexec} option. + @cindex provenance tracking, of the operating system Upon completion, the new system is deployed under @file{/run/current-system}. This directory contains @dfn{provenance diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 3e10d984e7..f58fcdaf4a 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Jakob L. Kreuze -;;; Copyright © 2020-2023 Ludovic Courtès +;;; Copyright © 2020-2024 Ludovic Courtès ;;; Copyright © 2024 Ricardo ;;; ;;; This file is part of GNU Guix. @@ -552,6 +552,13 @@ (define (deploy-managed-host machine) (inferior-exception-arguments c))) os) + (load-system-for-kexec (eval/error-handling c + (warning (G_ "\ +failed to load system of '~a' for kexec reboot:~%~{~s ~}~%") + host + (inferior-exception-arguments + c))) + os) (install-bootloader (eval/error-handling c (raise (formatted-message (G_ "\ diff --git a/gnu/tests/reconfigure.scm b/gnu/tests/reconfigure.scm index bcc7645fa3..a24a953e6e 100644 --- a/gnu/tests/reconfigure.scm +++ b/gnu/tests/reconfigure.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Jakob L. Kreuze +;;; Copyright © 2024 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -18,9 +19,12 @@ (define-module (gnu tests reconfigure) #:use-module (gnu bootloader) + #:use-module (gnu services) + #:use-module (gnu services base) #:use-module (gnu services shepherd) #:use-module (gnu system) #:use-module (gnu system accounts) + #:use-module (gnu system file-systems) #:use-module (gnu system shadow) #:use-module (gnu system vm) #:use-module (gnu tests) @@ -31,6 +35,7 @@ (define-module (gnu tests reconfigure) #:use-module (guix store) #:export (%test-switch-to-system %test-upgrade-services + %test-upgrade-kexec %test-install-bootloader)) ;;; Commentary: @@ -178,6 +183,73 @@ (define* (run-upgrade-services-test) (disable (upgrade-services-program '() '() '(dummy) '()))) (test enable disable)))) +(define (run-kexec-test) + "Run a test aiming to reboot via Linux kexec into a new system." + (define os + (marionette-operating-system + (operating-system + (inherit %simple-os) + (services (modify-services %base-services + (syslog-service-type + config => (syslog-configuration + (inherit config) + (config-file + (plain-file + "syslog.conf" + "*.* /dev/console\n"))))))) + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define new-os + (marionette-operating-system + (virtualized-operating-system ;run as with "guix system vm" + (operating-system + (inherit %simple-os) + (host-name "the-new-os") + (kernel-arguments '("console=ttyS0"))) ;be verbose + #:volatile? #t) ;mount root read-only + #:imported-modules '((gnu services herd) + (guix combinators)))) + + (define vm (virtual-machine os)) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "kexec") + + (test-equal "host name" + #$(operating-system-host-name os) + (marionette-eval '(gethostname) marionette)) + + (test-assert "kexec-loading-program" + (marionette-eval + '(primitive-load #$(kexec-loading-program new-os)) + marionette)) + + (test-assert "reboot/kexec" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (with-shepherd-action 'root ('kexec) result + (pk 'reboot-kexec result))) + marionette)) + + (test-equal "host name of new OS" + #$(operating-system-host-name new-os) + (marionette-eval '(gethostname) marionette)) + + (test-end)))) + + (gexp->derivation "kexec-test" test)) + (define* (run-install-bootloader-test) "Run a test of an OS running INSTALL-BOOTLOADER-PROGRAM, which installs a bootloader's configuration file." @@ -268,6 +340,12 @@ (define %test-upgrade-services loading new services.") (value (run-upgrade-services-test)))) +(define %test-upgrade-kexec + (system-test + (name "upgrade-kexec") + (description "Load a system and reboot into it via Linux kexec.") + (value (run-kexec-test)))) + (define %test-install-bootloader (system-test (name "install-bootloader") diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index dd34f6cd15..f174c8ada1 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -798,6 +798,7 @@ (define* (perform-action action image save-provenance? skip-safety-checks? install-bootloader? + load-for-kexec? dry-run? derivations-only? use-substitutes? target full-boot? @@ -900,7 +901,13 @@ (define* (perform-action action image To complete the upgrade, run 'herd restart SERVICE' to stop, upgrade, and restart each service that was not automatically restarted.\n"))) (return (format #t (G_ "\ -Run 'herd status' to view the list of services on your system.\n")))))) +Run 'herd status' to view the list of services on your system.\n")))) + (mwhen load-for-kexec? + (mlet %store-monad ((kexec? (load-system-for-kexec local-eval + os))) + (mwhen kexec? + (return (info (G_ "system loaded for fast reboot \ + with 'reboot --kexec'~%")))))))) ((init) (newline) (format #t (G_ "initializing operating system under '~a'...~%") @@ -1025,6 +1032,8 @@ (define (show-help) --image-size=SIZE for 'image', produce an image of SIZE")) (display (G_ " --no-bootloader for 'init', do not install a bootloader")) + (display (G_ " + --no-kexec for 'reconfigure', do not load system for kexec reboot")) (display (G_ " --volatile for 'image', make the root file system volatile")) (display (G_ " @@ -1127,6 +1136,9 @@ (define %options (option '("no-bootloader" "no-grub") #f #f (lambda (opt name arg result) (alist-cons 'install-bootloader? #f result))) + (option '("no-kexec") #f #f + (lambda (opt name arg result) + (alist-cons 'load-for-kexec? #f result))) (option '("volatile") #f #f (lambda (opt name arg result) (alist-cons 'volatile-image-root? #t result))) @@ -1198,6 +1210,7 @@ (define %default-options (image-type . mbr-hybrid-raw) (image-size . guess) (install-bootloader? . #t) + (load-for-kexec? . #t) (label . #f) (volatile-image-root? . #f) (volatile-vm-root? . #t) @@ -1275,6 +1288,7 @@ (define (process-action action args opts) (leave (G_ "no configuration specified~%"))))))) (dry? (assoc-ref opts 'dry-run?)) (bootloader? (assoc-ref opts 'install-bootloader?)) + (kexec? (assoc-ref opts 'load-for-kexec?)) (label (assoc-ref opts 'label)) (image-type (lookup-image-type-by-name (assoc-ref opts 'image-type))) @@ -1360,6 +1374,7 @@ (define (process-action action args opts) (_ #f)) opts) #:install-bootloader? bootloader? + #:load-for-kexec? kexec? #:target target-file #:gc-root (assoc-ref opts 'gc-root))))) #:target target diff --git a/guix/scripts/system/reconfigure.scm b/guix/scripts/system/reconfigure.scm index ddb561d28c..e9e16e3422 100644 --- a/guix/scripts/system/reconfigure.scm +++ b/guix/scripts/system/reconfigure.scm @@ -31,6 +31,7 @@ (define-module (guix scripts system reconfigure) #:use-module (gnu services herd) #:use-module (gnu services shepherd) #:use-module (gnu system) + #:autoload (gnu system file-systems) (file-system-device) #:use-module (guix gexp) #:use-module (guix modules) #:use-module (guix monads) @@ -52,6 +53,9 @@ (define-module (guix scripts system reconfigure) upgrade-services-program upgrade-shepherd-services + kexec-loading-program + load-system-for-kexec + install-bootloader-program install-bootloader @@ -176,6 +180,27 @@ (define (upgrade-services-program service-files to-start to-unload to-restart) (for-each unload-service '#$to-unload) (for-each start-service '#$to-start))))) +(define (kexec-loading-program os) + "Return a program that calls 'kexec_file_load' to allow rebooting into OS +via 'kexec'." + (let ((root-device (file-system-device + (operating-system-root-file-system os)))) + (program-file + "kexec-load-system.scm" + (with-imported-modules '((guix build syscalls)) + #~(begin + (use-modules (guix build syscalls)) + + (let ((kernel (open-fdes #$(operating-system-kernel-file os) + O_RDONLY)) + (initrd (open-fdes #$(operating-system-initrd-file os) + O_RDONLY))) + (kexec-load-file kernel initrd + (string-join + (list #$@(operating-system-kernel-arguments + os root-device))) + KEXEC_FILE_DEBUG))))))) + (define* (upgrade-shepherd-services eval os) "Using EVAL, a monadic procedure taking a single G-Expression as an argument, upgrade the Shepherd (PID 1) by unloading obsolete services and loading new @@ -205,6 +230,12 @@ (define* (upgrade-shepherd-services eval os) to-unload to-restart))))))) +(define (load-system-for-kexec eval os) + "Load OS so that it can be rebooted into via kexec, if supported. Return +true on success." + (eval #~(and (string-contains %host-type "-linux") + (primitive-load #$(kexec-loading-program os))))) + ;;; ;;; Bootloader configuration. -- 2.46.0