From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id IKvsH8qkT2aIHwEAA41jLg (envelope-from ) for ; Thu, 23 May 2024 22:19:22 +0200 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 cKIyGsqkT2bYKgAA62LTzQ (envelope-from ) for ; Thu, 23 May 2024 22:19:22 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=jdd1bqq+; 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=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1716495562; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: 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=fsy1bq4hTJxL8SDNgw72Q3AYmlAUzE/aQTP7QnA6sDE=; b=JG+tFE3uhanlm2z5QdoHGvohukw/DNen+8Nv6EslELCKbWoXAnHzlF0eRzmquhx4yrXI50 0wp3hmAP4p0mkVfFfZkp+Vl7c0GdQuezozp7SoLHpdTNsN7IJKtVrM1OBiOYFQphykIu3A NYoEquXRAk4Pqwj7WF3yhJr3nitTDj3BeWGbZWaB6f0qqVVTAhIJvCkvGjm6KklAkA8q38 Ut1HU72GbSOKcd9G3kNsJW2HnEpk/2fQZD/tEP3ftU5nwcSCdrevHSPIAUS5HerJIHjS+t SNFGX1v64FtGLesewnbdXHoSypcrB8bO1c1TqXak4yElIpIsuF+stf+JJSIwhQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=jdd1bqq+; 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=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1716495562; a=rsa-sha256; cv=none; b=IwypaW4QzBtLM05qZ+WKDzRWI1dUKXVTxMOav1FmML1Xhx3yExWrfyfetihg4Czec+/K8X uh9EY1eU2My6SJR54Dl7+XeDiVglq+/5pDSl+Kxp3eOYgfJVN73c1zJwDynLn51dIbAOK6 /p4WNlubHrjvwjqBvreX9vMyp9Z0q1vpRZk6YsICfJgbJt9LpT+BOS99+vnE7kGW2YluKL msooFfMwciAV7GhMDV27ZqPZddGKjWPkuhBfcXZQSAiKdl8tRpUvCAbO5ju8JEnHCqOLoh 4grs7AYLqRB+ddrSdgt4Ok8jYQZ3UUJ61JFiqTY/QmSwWUL/H57/+b1TRaPRQQ== 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 CB3AA7B2E5 for ; Thu, 23 May 2024 22:19:21 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAEtv-0008Te-SZ; Thu, 23 May 2024 16:18:59 -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 1sAEtu-0008R9-7G for guix-patches@gnu.org; Thu, 23 May 2024 16:18:58 -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 1sAEtt-0002CD-Rv; Thu, 23 May 2024 16:18:57 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sAEtx-00075b-UC; Thu, 23 May 2024 16:19:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#69090] [PATCH v2] gnu: services: Add resize-fs-service. References: In-Reply-To: Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, matt@excalamus.com, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Thu, 23 May 2024 20:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69090 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69090@debbugs.gnu.org Cc: Gabriel Wicki , Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Matthew Trzcinski , Maxim Cournoyer Received: via spool by 69090-submit@debbugs.gnu.org id=B69090.171649552727243 (code B ref 69090); Thu, 23 May 2024 20:19:01 +0000 Received: (at 69090) by debbugs.gnu.org; 23 May 2024 20:18:47 +0000 Received: from localhost ([127.0.0.1]:60772 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAEti-00075L-9r for submit@debbugs.gnu.org; Thu, 23 May 2024 16:18:46 -0400 Received: from mail-108-mta242.mxroute.com ([136.175.108.242]:42429) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAEtc-00075F-Gk for 69090@debbugs.gnu.org; Thu, 23 May 2024 16:18:44 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta242.mxroute.com (ZoneMTA) with ESMTPSA id 18fa71aec9a000efce.001 for <69090@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Thu, 23 May 2024 20:18:30 +0000 X-Zone-Loop: 6cf7acee79be6471acf49c2b560a8a6b2e1f70707238 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: 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:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z96Gcmw1oEuVffEwTjG+Wz6jyBWMN1L8rElZWDUzc6I=; b=jdd1bqq+P/ctRT0K/wh+tV5MdG 6k6L42aof1BiaBxpaUV5TGbOMyMTOuISrDNwUirGM52T08giJuT1qv9e47xU5RxE2CSzUmbDspaWl vLw3xrE80LV4rEcNknBfLWNE1TfJr5FlM8LJUrdm/A4mMHN+BL46fMMntYSu5Vajmt0wubZDRMQJi PnO6wQgyeCb+M0F44sqfzrlFcyiKl2Ra8F1mhyAOlQE6ntcAzG26ZZ0WLQMdBzZX3bs3Bmlj7szOT +uDXFyENI0jKxVeBcdklxracNWlE0Ku0Qb/zBpzo/+w/wxivX4xK5siV7iCLWWxBhPAbaPODOZAuI C6Wka6lg==; From: Richard Sent Date: Thu, 23 May 2024 16:07:04 -0400 Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -3.36 X-Migadu-Queue-Id: CB3AA7B2E5 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -3.36 X-TUID: bcom3wC1KZOr From: Gabriel Wicki * gnu/services/admin.scm (resize-fs-configuration): New configuration type. (resize-fs-script, resize-fs-shepherd-service): New procedures. resize-fs-service-type): New variable. * doc/guix.texi (Miscallaneous Services): Document it. Change-Id: Ib80c1af99ff62b68a79d7c463a5173f530514227 --- Hi Guix! This is a resubmission of V1 this patch. It looks like the email got messed up a bit and QA missed it. If QA still misses it I might send it out again as a separate issue and link back to here. To be 100% clear, this is Gabriel Wicki's code, not mine! Credit goes to them for the contribution. Some feedback: resize-fs-configuration's device field shouldn't be a hardcoded string. It should be as flexible as the file-system record, i.e. allow for labels and UUIDs. This should be possible using canonicalize-device-name in gnu build file-system. The service should also be extendable. Depending on how parted operates this might not be trivial. I'm not familiar with the tool, but I'd hope it can operate on partition device files just as well as a block device + partition #. doc/guix.texi | 41 +++++++++++++++++++ gnu/services/admin.scm | 89 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 129 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 8073e3f6d4..29fde6bad5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -41090,6 +41090,47 @@ Miscellaneous Services @c End of auto-generated fail2ban documentation. +@cindex resize-fs +@subsubheading Resize Filesystem service + +This service type lets you resize a live file-system during boot, which +can be convenient if you flashed Guix on an SD Card (e.g. for an +embedded device) or uploaded the image 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-fs-service-type + (resize-fs-configuration + (device "/dev/mmcblk0") + (partition 2))) +@end lisp + +Be extra cautious to use the correct device, partiion and end value, for +the service will circumvent parted's safety checks - wrong use could end +in loss of data or the corruption of your operating system. + +@table @asis + +@item @code{parted} (default: @code{parted}) (type: file-like) +The parted package to use. + +@item @code{e2fsprogs} (default: @code{e2fsprogs}) (type: file-like) +The e2fsprogs package to use. + +@item @code{device} (default: @code{"/dev/sdZ"}) (type: string) +The device containing the file-system that shall be resized. + +@item @code{partition} (default: @code{-1}) (type: number) +The partition number of the file-system that shall be resized. + +@item @code{end} (default: @code{"100%"}) (type: string) +The end position of the resized partition as understood by the parted +utility (e.g. "100%", "500M" or "16GiB"). + +@end table + + @node Setuid Programs @section Setuid Programs diff --git a/gnu/services/admin.scm b/gnu/services/admin.scm index 0b325fddb1..acd7cacd3e 100644 --- a/gnu/services/admin.scm +++ b/gnu/services/admin.scm @@ -23,8 +23,11 @@ (define-module (gnu services admin) #:use-module (gnu packages admin) #:use-module ((gnu packages base) #:select (canonical-package findutils coreutils sed)) + #:use-module (gnu packages bash) #: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 +96,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-fs-configuration + resize-fs-configuration? + resize-fs-configuration-parted + resize-fs-configuration-e2fsprogs + resize-fs-configuration-device + resize-fs-configuration-partition + resize-fs-configuration-end + resize-fs-service-type)) ;;; Commentary: ;;; @@ -537,4 +549,79 @@ (define unattended-upgrade-service-type "Periodically upgrade the system from the current configuration.") (default-value (unattended-upgrade-configuration)))) + +;;; +;;; Resize filesystem. +;;; + +(define-configuration/no-serialization resize-fs-configuration + (parted + (file-like parted) + "The parted package to use.") + (e2fsprogs + (file-like e2fsprogs) + "The e2fsprogs package providing the resize2fs utility.") + (device + (string "/dev/sdZ") + "The device containing the partition to be resized.") + (partition + (number -1) + "The partition number that is to be resized.") + (end + (string "100%") + "The end position of the resized partition as understood by the parted \ +utility (e.g. \"100%\", \"500M\" or \"16GiB\").")) + +(define (resize-fs-script config) + (match-record + config (parted e2fsprogs device partition end) + (let ((parted-bin (file-append parted "/sbin/parted")) + (resize2fs (file-append e2fsprogs "/sbin/resize2fs")) + (device+partition (string-append device "p" (number->string partition)))) + (mixed-text-file "resize-fs.sh" + "#!/bin/sh +echoerr() { printf \"$*\\n\" >&2 ; } + +cmd() { + " parted-bin " " device " ---pretend-input-tty <string partition) " +Yes +" end " +EOF +} + +set -o errexit +set -o pipefail + +if cmd; then + echoerr \"Resizing successful\" +else + echoerr \"resize-script returned $?\" +fi +")))) + +(define (resize-fs-shepherd-service config) + "Return a list of for resize-fs-service for CONFIG." + (let ((resize-script (resize-fs-script config))) + (shepherd-service + (documentation "Resize a file-system. Intended for Guix Systems that are \ +booted from a system image flashed onto a larger medium.") + (provision '(resize-fs)) + (requirement '(user-processes)) + (one-shot? #t) + (respawn? #f) + (start #~(make-forkexec-constructor + (list #$(file-append bash "/bin/sh") #$resize-script)))))) + +(define resize-fs-service-type + (service-type + (name 'resize-fs) + (description "Resize a partition during boot.") + (extensions + (list + (service-extension shepherd-root-service-type + (compose list resize-fs-shepherd-service)))) + (default-value (resize-fs-configuration)))) + ;;; admin.scm ends here base-commit: 3597c736588c45efde3c22d533ea8774c3fdd235 -- 2.41.0