From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.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 wJ6uOFw3aGe11AAA62LTzQ:P1 (envelope-from ) for ; Sun, 22 Dec 2024 15:59:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id wJ6uOFw3aGe11AAA62LTzQ (envelope-from ) for ; Sun, 22 Dec 2024 16:59:25 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=lACq2uMo; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Xl+y+3hO; 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=1734883164; 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=LKEHxvuQ4/obm7hdWg9CpLpWf4kF865pu5Qjm8+YguM=; b=VdMh6lWKFKrQRP1RvQSHQTBSKptpsWd6+2l5crpt+q/Bhm5o8GcOwDFUu1WOzF4qq+rQIq RmlOj2wIQWfrpBbuboAJThYFWY6XZNXXXxibfGWWozV1F0PAh0YgtzUW6zZh3qJ+zcU2Oy w9UR7ZlJ/p81E52LgL2S4yMMe6z7+q2RxFm/Oy45p9KMRMHIC0I+YulZMiRaGReV9tJp1J 705oPKifxQYW4eGhSx6VJQXhTk2Z8FJDbyGpdQAmi+VhtDrko9nJydqD1NXm/wqIU/rSyI hlhck0VtF11XgCRDDFHfBx6ebmltjRQ0TderXiAFKQWFlDHaRyRWRDi9bFdldw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=lACq2uMo; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=Xl+y+3hO; 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=1734883164; a=rsa-sha256; cv=none; b=mlUwJ/WRf5CkEyigX4aDXnm1coxz6zb3+2QJAZggCzAJyJs40moxhmjG0cD+QzlrhibBjf 5aYoJmIt7OIJz5oKINyhsjhCUWv/4FpaFPdVTbcX9IQ+TSwwz+ys9U/qFBEi4hMnCAWv19 YBG+ZySQCkBNEsUqCq6S49K7uJpDpLsIte29mombygI6DE1rvX4x9hNcrWm35NUV3eJC7P P0LKx1bux9uG2v9ugtBMeEfJ70arfTqiWvIfTCAlOrB7dkjylqz5TWCVaVApIE/dwYsNUi D1zvOnknXCPW9DA03I//8NzV8QI4vf+TyPn7m60rxJoP6+R+1eClxftMNcRtww== 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 53C1F80495 for ; Sun, 22 Dec 2024 16:59:24 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tPOMF-00051Z-Fl; Sun, 22 Dec 2024 10:59: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 1tPOMD-00050r-MR for guix-patches@gnu.org; Sun, 22 Dec 2024 10:59: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 1tPOMD-00089b-Dm; Sun, 22 Dec 2024 10:59: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=LKEHxvuQ4/obm7hdWg9CpLpWf4kF865pu5Qjm8+YguM=; b=lACq2uMoDsA4XTHqaEg5IpodXO4AF/KbLVVXLfgooTcum+6wjeNqnC3kP82acNAsuv2wuHJBi/4hzbyzDdHajrP4B66kb84jC5GoaOcGt5RX8TYcPBeu3Jx7TM4AfOW0P7iXtR6mH/fJHjfsnE6o0Df2ADolBu6dEdecPGVxmdS1IzJPoVtFIlFHzzF52R2/rbCOnS5bDh+fOWVdLSuJo9gQGLT/LNZn1JWo2BIlNE28Ze1Cu1/kNpD/y5npuNzeeeLaFzEyza9tfHXgT/doe2p02Pqn5ZjHrQkXCCvmbPKRJ1eqgQ1fNNAy1jp9/bFjg6q9eoxt+usk9FLuhUHn2Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tPOMA-0003P2-GV; Sun, 22 Dec 2024 10:59:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75027] [PATCH 3/3] reconfigure: Call =?UTF-8?Q?=E2=80=98kexec-load-file=E2=80=99.?= 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, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 22 Dec 2024 15:59:02 +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 , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75027-submit@debbugs.gnu.org id=B75027.173488312113045 (code B ref 75027); Sun, 22 Dec 2024 15:59:02 +0000 Received: (at 75027) by debbugs.gnu.org; 22 Dec 2024 15:58:41 +0000 Received: from localhost ([127.0.0.1]:51551 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPOLo-0003OJ-Oq for submit@debbugs.gnu.org; Sun, 22 Dec 2024 10:58:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:60910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tPOLi-0003Nq-VG for 75027@debbugs.gnu.org; Sun, 22 Dec 2024 10:58:35 -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 1tPOLd-000845-P5; Sun, 22 Dec 2024 10:58:29 -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=LKEHxvuQ4/obm7hdWg9CpLpWf4kF865pu5Qjm8+YguM=; b=Xl+y+3hO3xUOeafM8HIz a8+5GQ/bXdaNJPzCcwrurrXGLlKHdp8ZxW53YHbal8k8By/21nAiEp3/e+SfCsaX7yghrFEGtn2aI c1WJK4h8XPHBTcyz4kYHTVGu+1WQ9k7ymDzUyTJFhkj5KHpBGYS/3e9NvyTJevfAAUOHLtstXfha4 YsI3aO8CidoqpWmOe/Dl6LoTtF/VEmmczNaQsPU5o0IRK4wie3ayEVvCSCEppUbzfyu4HkHDQeAum lN5bSfWSKyhZ8f85Q9jvw+AmnJIf6qPhcvoHlU+arBFm4IFa3FsIQoMo8KrK8o6FFqkIRQTKVtwXr 8saW8oMBZCxPHw==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sun, 22 Dec 2024 16:57:43 +0100 Message-ID: <137b2d758c517c45aaa71e9555076df6ab7dd477.1734882676.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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: -6.12 X-Spam-Score: -6.12 X-Migadu-Queue-Id: 53C1F80495 X-TUID: Af4LUgEKICYs This allows rebooting straight into the new system with ‘reboot -k’. * guix/scripts/system/reconfigure.scm (kexec-loading-program): New procedure. (upgrade-shepherd-services): Use it. * gnu/tests/reconfigure.scm (run-kexec-test): New procedure. (%test-upgrade-kexec): New variable. Change-Id: I86d11f1c348e4359bc9e73c86e5aebff60fe875c --- gnu/tests/reconfigure.scm | 77 +++++++++++++++++++++++++++++ guix/scripts/system/reconfigure.scm | 25 ++++++++++ 2 files changed, 102 insertions(+) diff --git a/gnu/tests/reconfigure.scm b/gnu/tests/reconfigure.scm index bcc7645fa3..8d33bdac9b 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,72 @@ (define* (run-upgrade-services-test) (disable (upgrade-services-program '() '() '(dummy) '()))) (test enable disable)))) +(define* (run-kexec-test) + (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 +339,12 @@ (define %test-upgrade-services loading new services.") (value (run-upgrade-services-test)))) +(define %test-upgrade-kexec + (system-test + (name "upgrade-kexec") + (description "FIXME") + (value (run-kexec-test)))) + (define %test-install-bootloader (system-test (name "install-bootloader") diff --git a/guix/scripts/system/reconfigure.scm b/guix/scripts/system/reconfigure.scm index ddb561d28c..9e08179613 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) @@ -51,6 +52,7 @@ (define-module (guix scripts system reconfigure) upgrade-services-program upgrade-shepherd-services + kexec-loading-program install-bootloader-program install-bootloader @@ -176,6 +178,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 @@ -200,6 +223,8 @@ (define* (upgrade-shepherd-services eval os) running)) (service-files (map shepherd-service-file target-services))) (eval #~(parameterize ((current-warning-port (%make-void-port "w"))) + (when (string-contains %host-type "-linux") + (primitive-load #$(kexec-loading-program os))) (primitive-load #$(upgrade-services-program service-files to-start to-unload -- 2.46.0