From patchwork Wed Oct 28 13:54:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 24845 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8042327BBF3; Wed, 28 Oct 2020 13:56:17 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id CAE7527BBF2 for ; Wed, 28 Oct 2020 13:56:16 +0000 (GMT) Received: from localhost ([::1]:40594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvz-0000gm-RH for patchwork@mira.cbaines.net; Wed, 28 Oct 2020 09:56:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0000fz-IC for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXlvm-0003XW-4i for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kXlvl-0006gO-Pa for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44169] [PATCH v2 1/3] file-systems: Allow swap space lookup by UUID/label. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Oct 2020 13:56:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44169@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 44169-submit@debbugs.gnu.org id=B44169.160389334525659 (code B ref 44169); Wed, 28 Oct 2020 13:56:01 +0000 Received: (at 44169) by debbugs.gnu.org; 28 Oct 2020 13:55:45 +0000 Received: from localhost ([127.0.0.1]:49972 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvU-0006fm-To for submit@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:45 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51906) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvT-0006dq-VN for 44169@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:44 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:44162) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvO-0003UP-04; Wed, 28 Oct 2020 09:55:38 -0400 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:38634 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kXlvN-0001bF-Hw; Wed, 28 Oct 2020 09:55:37 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 28 Oct 2020 14:54:55 +0100 Message-Id: <20201028135457.23335-1-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <87imaxdwv5.fsf@gnu.org> References: <87imaxdwv5.fsf@gnu.org> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/build/file-systems.scm (%linux-swap-magic, %page-size): New variables. (linux-swap-superblock?, read-linux-swap-superblock) (linux-swap-superblock-uuid, linux-swap-superblock-volume-name): New procedures. (%partition-label-readers, %partition-uuid-readers): Add them. --- gnu/build/file-systems.scm | 46 +++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/gnu/build/file-systems.scm b/gnu/build/file-systems.scm index 734d648575..8ec8eac896 100644 --- a/gnu/build/file-systems.scm +++ b/gnu/build/file-systems.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017, 2018 Ludovic Courtès +;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2020 Ludovic Courtès ;;; Copyright © 2016, 2017 David Craven ;;; Copyright © 2017 Mathieu Othacehe ;;; Copyright © 2019 Guillaume Le Vaillant @@ -179,6 +179,46 @@ if DEVICE does not contain an ext2 file system." (2 'reboot-required) (_ 'fatal-error))) + +;;; +;;; Linux swap. +;;; + +;; Linux "swap space" is not a file system but it has a UUID and volume name, +;; like actual file systems, and we want to be able to look up swap partitions +;; by UUID and by label. + +(define %linux-swap-magic + (string->utf8 "SWAPSPACE2")) + +;; Like 'PAGE_SIZE' in Linux, arch/x86/include/asm/page.h. +;; XXX: This is always 4K on x86_64, i386, and ARMv7. However, on AArch64, +;; this is determined by 'CONFIG_ARM64_PAGE_SHIFT' in the kernel, which is 12 +;; by default (4K) but can be 14 or 16. +(define %page-size 4096) + +(define (linux-swap-superblock? sblock) + "Return #t when SBLOCK is an linux-swap superblock." + (and (= (bytevector-length sblock) %page-size) + (bytevector=? (sub-bytevector sblock (- %page-size 10) 10) + %linux-swap-magic))) + +(define (read-linux-swap-superblock device) + "Return the raw contents of DEVICE's linux-swap superblock as a bytevector, or #f +if DEVICE does not contain an linux-swap file system." + (read-superblock device 0 %page-size linux-swap-superblock?)) + +;; See 'union swap_header' in 'include/linux/swap.h'. + +(define (linux-swap-superblock-uuid sblock) + "Return the UUID of Linux-swap superblock SBLOCK as a 16-byte bytevector." + (sub-bytevector sblock (+ 1024 4 4 4) 16)) + +(define (linux-swap-superblock-volume-name sblock) + "Return the label of Linux-swap superblock SBLOCK as a string." + (null-terminated-latin1->string + (sub-bytevector sblock (+ 1024 4 4 4 16) 16))) + ;;; ;;; Btrfs file systems. @@ -596,6 +636,8 @@ partition field reader that returned a value." iso9660-superblock-volume-name) (partition-field-reader read-ext2-superblock ext2-superblock-volume-name) + (partition-field-reader read-linux-swap-superblock + linux-swap-superblock-volume-name) (partition-field-reader read-btrfs-superblock btrfs-superblock-volume-name) (partition-field-reader read-fat32-superblock @@ -612,6 +654,8 @@ partition field reader that returned a value." iso9660-superblock-uuid) (partition-field-reader read-ext2-superblock ext2-superblock-uuid) + (partition-field-reader read-linux-swap-superblock + linux-swap-superblock-uuid) (partition-field-reader read-btrfs-superblock btrfs-superblock-uuid) (partition-field-reader read-fat32-superblock From patchwork Wed Oct 28 13:54:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 24846 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 3D98C27BBF3; Wed, 28 Oct 2020 13:56:21 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 6C4AB27BBF2 for ; Wed, 28 Oct 2020 13:56:20 +0000 (GMT) Received: from localhost ([::1]:40622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlw3-0000hg-Kb for patchwork@mira.cbaines.net; Wed, 28 Oct 2020 09:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52084) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0000g0-IF for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXlvm-0003XY-Ia for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kXlvm-0006gV-FI for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44169] [PATCH v2 2/3] services: swap: Allow for UUIDs and file system labels. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Oct 2020 13:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44169@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 44169-submit@debbugs.gnu.org id=B44169.160389335025676 (code B ref 44169); Wed, 28 Oct 2020 13:56:02 +0000 Received: (at 44169) by debbugs.gnu.org; 28 Oct 2020 13:55:50 +0000 Received: from localhost ([127.0.0.1]:49976 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlva-0006g3-Cr for submit@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:50 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51910) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvU-0006f5-Uk for 44169@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:45 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:44164) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvP-0003VA-NY; Wed, 28 Oct 2020 09:55:39 -0400 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:38634 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kXlvO-0001bF-Lo; Wed, 28 Oct 2020 09:55:39 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 28 Oct 2020 14:54:56 +0100 Message-Id: <20201028135457.23335-2-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201028135457.23335-1-ludo@gnu.org> References: <87imaxdwv5.fsf@gnu.org> <20201028135457.23335-1-ludo@gnu.org> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/services/base.scm (swap-service-type)[device-lookup, device-name]: New variables. Add 'modules' field to 'shepherd-service'. In 'start' and 'stop', use 'device-lookup' to resolve UUIDs and labels. * doc/guix.texi (operating-system Reference): Adjust accordingly. --- doc/guix.texi | 34 +++++++++++++++++++++++---- gnu/services/base.scm | 54 +++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 17 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index efb4ea1c47..feb5760129 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13043,14 +13043,38 @@ A list of mapped devices. @xref{Mapped Devices}. @item @code{file-systems} A list of file systems. @xref{File Systems}. -@item @code{swap-devices} (default: @code{'()}) @cindex swap devices -A list of strings identifying devices or files to be used for ``swap +@cindex swap space +@item @code{swap-devices} (default: @code{'()}) +A list of UUIDs, file system labels, or strings identifying devices or +files to be used for ``swap space'' (@pxref{Memory Concepts,,, libc, The GNU C Library Reference -Manual}). For example, @code{'("/dev/sda3")} or @code{'("/swapfile")}. +Manual}). Here are some examples: + +@table @code +@item (list (uuid "4dab5feb-d176-45de-b287-9b0a6e4c01cb")) +Use the swap partition with the given UUID. You can learn the UUID of a +Linux swap partition by running @command{swaplabel @var{device}}, where +@var{device} is the @file{/dev} file name of that partition. + +@item (list (file-system-label "swap")) +Use the partition with label @code{swap}. Again, the +@command{swaplabel} command allows you to view and change the label of a +Linux swap partition. + +@item (list "/swapfile") +Use the file @file{/swapfile} as swap space. + +@item (list "/dev/sda3" "/dev/sdb2") +Use the @file{/dev/sda3} and @file{/dev/sdb2} partitions as swap space. +We recommend referring to swap devices by UUIDs or labels as shown above +instead. +@end table + It is possible to specify a swap file in a file system on a mapped -device, provided that the necessary device mapping and file system are -also specified. @xref{Mapped Devices} and @ref{File Systems}. +device (under @file{/dev/mapper}), provided that the necessary device +mapping and file system are also specified. @xref{Mapped Devices} and +@ref{File Systems}. @item @code{users} (default: @code{%base-user-accounts}) @itemx @code{groups} (default: @code{%base-groups}) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 37b0a13ea7..07d9089b0a 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -2104,22 +2104,52 @@ instance." 'swap (lambda (device) (define requirement - (if (string-prefix? "/dev/mapper/" device) + (if (and (string? device) + (string-prefix? "/dev/mapper/" device)) (list (symbol-append 'device-mapping- (string->symbol (basename device)))) '())) - (shepherd-service - (provision (list (symbol-append 'swap- (string->symbol device)))) - (requirement `(udev ,@requirement)) - (documentation "Enable the given swap device.") - (start #~(lambda () - (restart-on-EINTR (swapon #$device)) - #t)) - (stop #~(lambda _ - (restart-on-EINTR (swapoff #$device)) - #f)) - (respawn? #f))))) + (define (device-lookup device) + ;; The generic 'find-partition' procedures could return a partition + ;; that's not swap space, but that's unlikely. + (cond ((uuid? device) + #~(find-partition-by-uuid #$(uuid-bytevector device))) + ((file-system-label? device) + #~(find-partition-by-label + #$(file-system-label->string device))) + (else + device))) + + (define service-name + (symbol-append 'swap- + (string->symbol + (cond ((uuid? device) + (string-take (uuid->string device) 6)) + ((file-system-label? device) + (file-system-label->string device)) + (else + device))))) + + (with-imported-modules (source-module-closure '((gnu build file-systems))) + (shepherd-service + (provision (list service-name)) + (requirement `(udev ,@requirement)) + (documentation "Enable the given swap device.") + (modules `((gnu build file-systems) + ,@%default-modules)) + (start #~(lambda () + (let ((device #$(device-lookup device))) + (and device + (begin + (restart-on-EINTR (swapon device)) + #t))))) + (stop #~(lambda _ + (let ((device #$(device-lookup device))) + (when device + (restart-on-EINTR (swapoff device))) + #f))) + (respawn? #f)))))) (define (swap-service device) "Return a service that uses @var{device} as a swap device." From patchwork Wed Oct 28 13:54:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 24847 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 106E727BBF3; Wed, 28 Oct 2020 14:03:21 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 183B627BBF2 for ; Wed, 28 Oct 2020 14:03:20 +0000 (GMT) Received: from localhost ([::1]:42622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXm2p-00025m-AS for patchwork@mira.cbaines.net; Wed, 28 Oct 2020 10:03:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0000g1-I2 for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:38434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kXlvn-0003Xa-7o for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kXlvm-0006gd-TD for guix-patches@gnu.org; Wed, 28 Oct 2020 09:56:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#44169] [PATCH v2 3/3] installer: Use UUIDs in the 'swap-devices' field. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 28 Oct 2020 13:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44169 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44169@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 44169-submit@debbugs.gnu.org id=B44169.160389335125682 (code B ref 44169); Wed, 28 Oct 2020 13:56:02 +0000 Received: (at 44169) by debbugs.gnu.org; 28 Oct 2020 13:55:51 +0000 Received: from localhost ([127.0.0.1]:49978 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlva-0006g5-O6 for submit@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:51 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51916) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kXlvW-0006fg-Db for 44169@debbugs.gnu.org; Wed, 28 Oct 2020 09:55:46 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:44165) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kXlvR-0003Vv-5s; Wed, 28 Oct 2020 09:55:41 -0400 Received: from vpn-0-27.aquilenet.fr ([2a0c:e300:4:27::]:38634 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kXlvQ-0001bF-9r; Wed, 28 Oct 2020 09:55:40 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 28 Oct 2020 14:54:57 +0100 Message-Id: <20201028135457.23335-3-ludo@gnu.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201028135457.23335-1-ludo@gnu.org> References: <87imaxdwv5.fsf@gnu.org> <20201028135457.23335-1-ludo@gnu.org> MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Note: This change requires an updated 'guix' package that contains Linux-swap support in (gnu build file-systems). * gnu/installer/parted.scm (user-partitions->configuration): Use UUIDs in the 'swap-devices' field. * gnu/installer/newt/final.scm (run-final-page)[wait-for-clients]: New procedure. Use it. * gnu/installer/tests.scm (choose-partitioning): Wait for 'starting-final-step' message and move configuration file dialog handling to... (conclude-installation): ... here. Send over PORT the reply corresponding to 'starting-final-step'. * gnu/tests/install.scm (gui-test-program): When ENCRYPTED? is false, invoke 'swaplabel' in the marionette. (installation-target-os-for-gui-tests): When ENCRYPTED? is false, except a fixed UUID. --- gnu/installer/newt/final.scm | 14 ++++++++++++++ gnu/installer/parted.scm | 7 ++++++- gnu/installer/tests.scm | 31 +++++++++++++++++++++++-------- gnu/tests/install.scm | 18 ++++++++++++++++-- 4 files changed, 59 insertions(+), 11 deletions(-) diff --git a/gnu/installer/newt/final.scm b/gnu/installer/newt/final.scm index 89684c4d8a..5019a67429 100644 --- a/gnu/installer/newt/final.scm +++ b/gnu/installer/newt/final.scm @@ -29,6 +29,7 @@ #:use-module (srfi srfi-34) #:use-module (srfi srfi-35) #:use-module (ice-9 match) + #:use-module ((ice-9 rdelim) #:select (read-line)) #:use-module (newt) #:export (run-final-page)) @@ -107,6 +108,19 @@ a specific step, or restart the installer.")) install-ok?)) (define (run-final-page result prev-steps) + (define (wait-for-clients) + (unless (null? (current-clients)) + (syslog "waiting with clients before starting final step~%") + (send-to-clients '(starting-final-step)) + (match (select (current-clients) '() '()) + (((port _ ...) _ _) + (read-line port))))) + + ;; Before generating the configuration file, give clients a chance to do + ;; things such as changing the swap partition label. + (wait-for-clients) + + (syslog "proceeding with final step~%") (let* ((configuration (format-configuration prev-steps result)) (user-partitions (result-step result 'partition)) (locale (result-step result 'locale)) diff --git a/gnu/installer/parted.scm b/gnu/installer/parted.scm index fffd5abf3b..d799ee0e73 100644 --- a/gnu/installer/parted.scm +++ b/gnu/installer/parted.scm @@ -1327,7 +1327,12 @@ USER-PARTITIONS, or return nothing." ,@(initrd-configuration user-partitions) ,@(if (null? swap-devices) '() - `((swap-devices (list ,@swap-devices)))) + (let* ((uuids (map (lambda (file) + (uuid->string (read-partition-uuid file))) + swap-devices))) + `((swap-devices (list ,@(map (lambda (uuid) + `(uuid ,uuid)) + uuids)))))) ,@(if (null? encrypted-partitions) '() `((mapped-devices diff --git a/gnu/installer/tests.scm b/gnu/installer/tests.scm index 58bf0a2700..f318546a2f 100644 --- a/gnu/installer/tests.scm +++ b/gnu/installer/tests.scm @@ -286,8 +286,9 @@ instrumented for further testing." edit-configuration-file)) "Converse over PORT to choose the partitioning method. When ENCRYPTED? is true, choose full-disk encryption with PASSPHRASE as the LUKS passphrase. -This conversation goes past the final dialog box that shows the configuration -file, actually starting the installation process." +This conversation stops when the user partitions have been formatted, right +before the installer generates the configuration file and shows it in a dialog +box." (converse port ((list-selection (title "Partitioning method") (multiple-choices? #f) @@ -330,15 +331,29 @@ file, actually starting the installation process." #t) ((info (title "Preparing partitions") _ ...) (values)) ;nothing to return + ((starting-final-step) + ;; Do not return anything. The reply will be sent by + ;; 'conclude-installation' and in the meantime the installer just waits + ;; for us, giving us a chance to do things such as changing partition + ;; UUIDs before it generates the configuration file. + (values)))) + +(define (conclude-installation port) + "Conclude the installation by checking over PORT that we get the generated +configuration file, accepting it and starting the installation, and then +receiving the final messages once the 'guix system init' process has +completed." + ;; Assume the previous message received was 'starting-final-step'; here we + ;; send the reply to that message, which lets the installer continue. + (write #t port) + (newline port) + (force-output port) + + (converse port ((file-dialog (title "Configuration file") (text _) (file ,configuration-file)) - (edit-configuration-file configuration-file)))) - -(define (conclude-installation port) - "Conclude the installation by checking over PORT that we get the final -messages once the 'guix system init' process has completed." - (converse port + (edit-configuration-file configuration-file)) ((pause) ;"Press Enter to continue." #t) ((installation-complete) ;congratulations! diff --git a/gnu/tests/install.scm b/gnu/tests/install.scm index 86bd93966b..2d62a873ca 100644 --- a/gnu/tests/install.scm +++ b/gnu/tests/install.scm @@ -1211,6 +1211,16 @@ build (current-guix) and then store a couple of full system images.") #$marionette) (screenshot "installer-run.ppm") + (unless #$encrypted? + ;; At this point, user partitions are formatted and the installer is + ;; waiting for us to start the final step: generating the + ;; configuration file, etc. Set a fixed UUID on the swap partition + ;; that matches what 'installation-target-os-for-gui-tests' expects. + (marionette-eval* '(invoke #$(file-append util-linux "/sbin/swaplabel") + "-U" "11111111-2222-3333-4444-123456789abc" + "/dev/vda2") + #$marionette)) + (marionette-eval* '(conclude-installation installer-socket) #$marionette) @@ -1257,8 +1267,12 @@ build (current-guix) and then store a couple of full system images.") '("wheel" "audio" "video")))) %base-user-accounts)) ;; The installer does not create a swap device in guided mode with - ;; encryption support. - (swap-devices (if encrypted? '() '("/dev/vda2"))) + ;; encryption support. The installer produces a UUID for the partition; + ;; this "UUID" is explicitly set in 'gui-test-program' to the value shown + ;; below. + (swap-devices (if encrypted? + '() + (list (uuid "11111111-2222-3333-4444-123456789abc")))) (services (cons (service dhcp-client-service-type) (operating-system-user-services %minimal-os-on-vda)))))