From patchwork Sat Dec 14 21:18:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 34897 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 BF5D627BBE9; Sat, 14 Dec 2024 21:36:32 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 73A0F27BBEA for ; Sat, 14 Dec 2024 21:36:31 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMZny-0001Yq-Js; Sat, 14 Dec 2024 16:36:06 -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 1tMZnv-0001YJ-O8 for guix-patches@gnu.org; Sat, 14 Dec 2024 16:36:03 -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 1tMZnv-0002ro-7y for guix-patches@gnu.org; Sat, 14 Dec 2024 16:36:03 -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=jgFpGQSvzQfbU1GOyo7XHeiORmcFd82Cb9Ue1E7DAzU=; b=veqRlioLpS1B5CsYU1q2NrhkdbZfHd1x++lOkdxIUWwFnPyzydy4lgBRyaHgk47ZXKuSt47xuAD73tcYeMI3eRfZGyl8TlgxWzEFYQtzaE1cntCYu5qXn2b9AfKmTzwt+Y31VXpwv+2kvZh/Zw/1PBbqR8idLUGlGgPFqrLynD3hh6J+2o049F0rboH+semxA7nQGKphtj0WY28cOuTmk5H3TkV8NAPMc05rSA7BgQVWioX98gsOYM++XZ74bMyFzQdwq4pmk9u3BklOW9wmMujSua3WYXwaJIIUCJE4iVBHI50A0yNOKMOEMhrk4WFgApHeQt8+mLHtuWinX1sJQg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMZnv-00011w-0w; Sat, 14 Dec 2024 16:36:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74837] [PATCH v3 1/2] packages: cloud-utils: Add missing growpart programs to path. Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: sharlatanus@gmail.com, guix-patches@gnu.org Resent-Date: Sat, 14 Dec 2024 21:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74837 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74837@debbugs.gnu.org Cc: Richard Sent , Sharlatan Hellseher X-Debbugs-Original-Xcc: Sharlatan Hellseher Received: via spool by 74837-submit@debbugs.gnu.org id=B74837.17342121553926 (code B ref 74837); Sat, 14 Dec 2024 21:36:02 +0000 Received: (at 74837) by debbugs.gnu.org; 14 Dec 2024 21:35:55 +0000 Received: from localhost ([127.0.0.1]:48610 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMZnm-00011E-Nz for submit@debbugs.gnu.org; Sat, 14 Dec 2024 16:35:55 -0500 Received: from mail-108-mta145.mxroute.com ([136.175.108.145]:34843) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMZni-00010p-Sv for 74837@debbugs.gnu.org; Sat, 14 Dec 2024 16:35:51 -0500 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta145.mxroute.com (ZoneMTA) with ESMTPSA id 193c719593f0003e01.001 for <74837@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 14 Dec 2024 21:35:47 +0000 X-Zone-Loop: 1a43edf5a32d7479dc4012180b002b34ead9272b1f39 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jgFpGQSvzQfbU1GOyo7XHeiORmcFd82Cb9Ue1E7DAzU=; b=WIaE0CWoqh+SCOXOJuFKs13xxP VVwxIL4jwEA6BvFmNhPsB+yGWo3EzAnDv3OOIi2+7iAwDNC9ZrZkoAbIGTKpDVQOJz2WdlKaCB7VG SPjDDYJLr5oiCcxF9TtcN50U+Hp9V7BrhP9A+7pagvsmcWuMjSbFVgoFeWwjkOL+H6SRLnfEXttYf IbyGD2qciWpSVVlHxXC8eCqpQE3gY8PDPgZOs75EcKkfzQELspCT0On/IIaX/OM6GbKhdda/tsrpd JapNov7AApwuMvL503wR8Es9oP+4F+7sBE6X/AsCF2pxKPH5E82TheZsLy+Lkz235Kct6YZmE3RJ7 TFLd+C7A==; From: Richard Sent Date: Sat, 14 Dec 2024 16:18:22 -0500 Message-ID: <449186592c56a84bd3bb02e26464fbcf8adea3d6.1734211103.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches This ensures growpart can run in environments that may not have a PATH variable set. * gnu/packages/admin.scm (cloud-utils): Augment growpart PATH with necessary programs. Change-Id: Idf0ca9e14e4c9d82208fbf715dd0b235cd5a371b --- gnu/packages/admin.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm index b1889ceea0..d39bc5adc5 100644 --- a/gnu/packages/admin.scm +++ b/gnu/packages/admin.scm @@ -581,12 +581,21 @@ (define-public cloud-utils ,(map dirname (map (cut search-input-file inputs <>) (list "bin/readlink" - "sbin/sfdisk"))))))))))) + "sbin/sfdisk" + "bin/sed" + "bin/grep" + "bin/awk" + "bin/udevadm" + "bin/flock"))))))))))) (inputs (list bash-minimal ;for wrap-program - coreutils ;for readlink + coreutils ;for readlink and cat + sed ;growpart + grep ;growpart + gawk ;awk for growpart + eudev ;udevadm for growpart python - util-linux)) ;sfdisk for growpart + util-linux)) ;sfdisk, flock, partx, blkid for growpart (home-page "https://launchpad.net/cloud-utils") (synopsis "Set of utilities for cloud computing environments") (description From patchwork Sat Dec 14 21:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 34898 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 7E22227BBE2; Sat, 14 Dec 2024 21:36:33 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D135727BBE2 for ; Sat, 14 Dec 2024 21:36:30 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tMZo1-0001Z8-Go; Sat, 14 Dec 2024 16:36:09 -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 1tMZnw-0001YN-1O for guix-patches@gnu.org; Sat, 14 Dec 2024 16:36:04 -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 1tMZnv-0002rv-OY; Sat, 14 Dec 2024 16:36:03 -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=l3uvQNvWFqWfshxw9qgbCR8vwJS5olGAtbEhgceSMD8=; b=NmW4QpDO7O1EYQbFYEVxz+etLQyrJ1+nD1VqaUSXMPeLWgp7i/2b2CoNKxHH1USOrBkKgNoxAd21h0i9PXP04hraXt8m9tVgMeOWSKCO7/4lkNQ/XUf1hLWjZb0MKx1htKBrNqoRZ4lJLW9dqLZZpVkwoXR9GD8VvRoSGBqHFGUAduOYLEOEVWjHxH1jJknj7XbNpX2XvFB4Y7kqH65tJmKP+Dy9Z/7g8Yn+vWwV2bBKECiBp7y7FzZA8fHTaGt1smL/5Nja3wVKQdfha4jTU4/VmMOUhq8iPTNCnOSx89Lqa5CavGiG1gQfvedzXT0mwsi9/0QsmypHi6FowxZJJA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tMZnv-000125-Jh; Sat, 14 Dec 2024 16:36:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74837] [PATCH v3 2/2] gnu: services: Add resize-file-system-service. Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sat, 14 Dec 2024 21:36:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74837 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74837@debbugs.gnu.org Cc: Richard Sent , Ludovic =?utf-8?q?Court?= =?utf-8?q?=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 74837-submit@debbugs.gnu.org id=B74837.17342121583942 (code B ref 74837); Sat, 14 Dec 2024 21:36:03 +0000 Received: (at 74837) by debbugs.gnu.org; 14 Dec 2024 21:35:58 +0000 Received: from localhost ([127.0.0.1]:48612 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMZnp-00011V-Cd for submit@debbugs.gnu.org; Sat, 14 Dec 2024 16:35:58 -0500 Received: from mail-108-mta135.mxroute.com ([136.175.108.135]:41651) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tMZnm-00011B-4p for 74837@debbugs.gnu.org; Sat, 14 Dec 2024 16:35:55 -0500 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta135.mxroute.com (ZoneMTA) with ESMTPSA id 193c719623c0003e01.001 for <74837@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sat, 14 Dec 2024 21:35:49 +0000 X-Zone-Loop: 26fec4fc7565e8e4b28944f7f2f85eb805af36fb5ba7 X-Originating-IP: [136.175.111.3] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:Content-Type: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=l3uvQNvWFqWfshxw9qgbCR8vwJS5olGAtbEhgceSMD8=; b=NRJedDfce3pVDNjXYSJP64h0Gx iRpO6vzSQ9PnDQX9YCnbgS/EgXpZZsHskAZ0xVezsmGyVN9gKELxO/2CfUw4yJbpHyeuTXZ8qQtrs yoSAQDqSUEgZ1MYvvJsejMCkl0ISpOWMuXSGSZ7tpPUm+1engMyuzCi4CkrNyDit7nVoepe54ou2A d3keG+17LXrraT47KSyvkEKy42S4Co+CpLxrJuff3CJCgiVmaruBnJXate3NvjsCaBEC6jhw8ejNN 2USFwtDtZuU/ZPfe7jgPdRmBxEJWa4Hxaoc6kOA1bQ/KU+QF3BZEejzSU/BQti04MRZElwh2RnaeA S5xpf56Q==; From: Richard Sent Date: Sat, 14 Dec 2024 16:18:23 -0500 Message-ID: <7dfc8384a8e73be14ae385b0761bd3f4280f405a.1734211103.git.richard@freakingpenguin.com> In-Reply-To: References: MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/admin.scm (resize-file-system-configuration): New configuration type. (resize-file-system-shepherd-service): New procedure. (resize-file-system-service-type): New variable. * doc/guix.texi (Miscallaneous Services): Document it. Change-Id: Icae2fefc9a8d936d4c3add47520258b341f689a4 --- doc/guix.texi | 54 +++++++++++++++++ gnu/services/admin.scm | 133 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 186 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index a2915de954..cc19fb6cff 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41891,6 +41891,60 @@ Miscellaneous Services @c End of auto-generated fail2ban documentation. +@cindex resize-file-system +@subsubheading Resize File System Service + +This service type lets you resize a live file system during boot, which +can be convenient if a Guix image is flashed on an SD Card (e.g. for an +embedded device) or uploaded to a VPS. In both cases the medium the +image will reside upon may be larger than the image you want to produce. + +For an embedded device booting from an SD card you may use something like: +@lisp +(service resize-file-system-service-type + (resize-file-system-configuration + (file-system + (file-system (device (file-system-label "root")) + (type "ext4"))))) +@end lisp + +@quotation Warning +Be extra cautious to use the correct device and type. The service has +little error handling of its own and relies on the underlying tools. +Wrong use could end in loss of data or the corruption of the operating +system. +@end quotation + +Partitions and file systems are grown to the maximum size available. +File systems can only grow when they are on the last partition on a +device and have empty space available. + +This service supports the ext2, ext3, ext4, btrfs, and bcachefs file +systems. + +@table @asis + +@item @code{file-system} (default: @code{#f}) (type: file-system) +The file-system object to resize (@pxref{File Systems}). This object +must have the @code{device} and @code{type} fields set. Other fields +are ignored. + +@item @code{cloud-utils} (default: @code{cloud-utils}) (type: file-like) +The cloud-utils package to use. This package is used for the +@code{growpart} command. + +@item @code{e2fsprogs} (default: @code{e2fsprogs}) (type: file-like) +The e2fsprogs package to use, used for resizing ext2, ext3, and ext4 +file systems. + +@item @code{btrfs-progs} (default: @code{btrfs-progs}) (type: file-like) +The btrfs-progs package to use, used for resizing the btrfs file system. + +@item @code{bcachefs-tools} (default: @code{bcachefs-tools}) (type: file-like) +The bcachefs-tools package to use, used for resizing the bcachefs file system. + +@end table + @cindex Backup @subsubheading Backup Services diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 24ff659a01..4a2f5cb12d 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -3,6 +3,8 @@ ;;; Copyright © 2016-2023 Ludovic Courtès ;;; Copyright © 2020 Brice Waegeneire ;;; Copyright © 2023 Giacomo Leidi +;;; Copyright © 2024 Gabriel Wicki +;;; Copyright © 2024 Richard Sent ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,11 +22,15 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu services admin) + #:use-module (gnu system file-systems) #:use-module (gnu packages admin) #:use-module ((gnu packages base) #:select (canonical-package findutils coreutils sed)) + #:use-module (gnu packages file-systems) #:use-module (gnu packages certs) + #:use-module (gnu packages disk) #:use-module (gnu packages package-management) + #:use-module (gnu packages linux) #:use-module (gnu services) #:use-module (gnu services configuration) #:use-module (gnu services mcron) @@ -93,7 +99,16 @@ (define-module (gnu services admin) unattended-upgrade-configuration-services-to-restart unattended-upgrade-configuration-system-expiration unattended-upgrade-configuration-maximum-duration - unattended-upgrade-configuration-log-file)) + unattended-upgrade-configuration-log-file + + resize-file-system-service-type + resize-file-system-configuration + resize-file-system-configuration? + resize-file-system-configuration-file-system + resize-file-system-configuration-cloud-utils + resize-file-system-configuration-e2fsprogs + resize-file-system-configuration-btrfs-progs + resize-file-system-configuration-bcachefs-tools)) ;;; Commentary: ;;; @@ -550,4 +565,120 @@ (define unattended-upgrade-service-type "Periodically upgrade the system from the current configuration.") (default-value (unattended-upgrade-configuration)))) +;;; +;;; Resize file system. +;;; + +(define-record-type* + resize-file-system-configuration make-resize-file-system-configuration + resize-file-system-configuration? + (file-system resize-file-system-file-system + (default #f)) + (cloud-utils resize-file-system-cloud-utils + (default cloud-utils)) + (e2fsprogs resize-file-system-e2fsprogs + (default e2fsprogs)) + (btrfs-progs resize-file-system-btrfs-progs + (default btrfs-progs)) + (bcachefs-tools resize-file-system-bcachefs-tools + (default bcachefs-tools))) + +(define (resize-file-system-shepherd-service config) + "Returns a for resize-file-system-service for CONFIG." + (match-record config + (file-system cloud-utils e2fsprogs btrfs-progs + bcachefs-tools) + (let ((fs-spec (file-system->spec file-system))) + (shepherd-service + (documentation "Resize a file system. Intended for Guix Systems that +are booted from a system image flashed onto a larger medium.") + ;; XXX: This could be extended with file-system info. + (provision '(resize-file-system)) + (requirement '(user-processes)) + (one-shot? #t) + (respawn? #f) + (modules '((guix build utils) + (gnu build file-systems) + (gnu system file-systems) + (ice-9 control) + (ice-9 match) + (ice-9 ftw) + (ice-9 rdelim) + (srfi srfi-34))) + (start (with-imported-modules (source-module-closure + '((guix build utils) + (gnu build file-systems) + (gnu system file-systems))) + #~(lambda _ + (use-modules (guix build utils) + (gnu build file-systems) + (gnu system file-systems) + (ice-9 control) + (ice-9 match) + (ice-9 ftw) + (ice-9 rdelim) + (srfi srfi-34)) + + (define file-system + (spec->file-system '#$fs-spec)) + + ;; Shepherd recommends the start constructor takes <1 + ;; minute, canonicalize-device-spec will hang for up to + ;; max-trials seconds (20 seconds) if an invalid device is + ;; connected. Revisit this if max-trials increases. + (define device (canonicalize-device-spec + (file-system-device file-system))) + + (define grow-partition-command + (let* ((sysfs-device + (string-append "/sys/class/block/" + (basename device))) + (partition-number + (with-input-from-file + (string-append sysfs-device + "/partition") + read-line)) + (parent (string-append + "/dev/" + (basename (dirname (readlink sysfs-device)))))) + (list #$(file-append cloud-utils "/bin/growpart") + parent partition-number))) + + (define grow-filesystem-command + (match (file-system-type file-system) + ((or "ext2" "ext3" "ext4") + (list #$(file-append e2fsprogs "/sbin/resize2fs") device)) + ("btrfs" + (list #$(file-append btrfs-progs "/bin/btrfs") + "filesystem" "resize" device)) + ("bcachefs" + (list #$(file-append bcachefs-tools "/sbin/bcachefs") + "device" "resize" device)) + (e (error "Unsupported filesystem type" e)))) + + (let/ec return + (guard (c ((and (invoke-error? c) + ;; growpart NOCHANGE exits with 1. It is + ;; unlikely the partition was resized + ;; while the file system was not. Just + ;; exit. + (equal? (invoke-error-exit-status c) 1)) + (format (current-error-port) + "The device ~a is already resized.~%" device) + ;; Must return something or Shepherd considers + ;; the service perpetually starting. + (return 0))) + (apply invoke grow-partition-command)) + (apply invoke grow-filesystem-command))))))))) + +(define resize-file-system-service-type + (service-type + (name 'resize-file-system) + (description "Resize a partition and the underlying file system during boot.") + (extensions + (list + (service-extension shepherd-root-service-type + (compose list resize-file-system-shepherd-service)))) + (default-value (resize-file-system-configuration)))) + ;;; admin.scm ends here