From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms8.migadu.com with LMTPS id QE+XJNTWymXavQAA62LTzQ:P1 (envelope-from ) for ; Tue, 13 Feb 2024 03:41:24 +0100 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id QE+XJNTWymXavQAA62LTzQ (envelope-from ) for ; Tue, 13 Feb 2024 03:41:24 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none; 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=1707792084; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:list-id:list-help:list-unsubscribe:list-subscribe: list-post; bh=tJK0nktJiIbX/1Po1tVj+PgWny/B3dhxwdmsDdTLx0Q=; b=LBfl99c6ShKqOOIH/Io8utB8eTDM7WJW34a+tAcR8U6iee/yA9GdvO3MCIMO23CZHy99H1 qKHchwduW+gr/pIsvL0E1ZTHd1+gVD8NAlxk3JDQ06R7s1FWs8uzatqAX9PKDdCwp/NCJs 9mizBpdIMEWO2UR4b+QaG/0HByzUxvPVfJjS2hWJbFFduK+vYbaQ+au0UwWRrbPyOVpx+1 Zu68flo6UG+6gQbxreNwNCNwfTSI33qFwKmS/4Ds8pbVBx5VEvymFd1Zg3PFIkpDSPOcIl T7XPi12qHq08kXCE8GerRFaA0AFmqUVh5nKF70HspqDl91Ln9MVhlCij9LiLjg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; 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=1707792084; a=rsa-sha256; cv=none; b=KDYIaThs3/QiK1PUTxlj6kJyKAW3c/wJ/17YuLeC/S6fljAQ4dlz638nfxwG5Q09AUYAKn 3aEPG6tSjIK1wZFC9w4XzznvdZOacXB/2qBEJ96CybAXJLHkdD09xGQF9vlj95c6GP+ki3 X4t4ooNcyTEB5u+MxcVgn5z7+s9xoe5DmQyWs9A408tRaXNQ26Bxl/nLAzFGtwJ8hN2j2T 6/rrEJS98ZAnHU5abvwp19yselG4/TDWoWzY7v5UdUiseMECNUBd5suC5CrqHpPPolIRuR C3jKuI5Vw+6WCdeZnl8dd/9Aor9PdM+/q2nq8/+AhcNGr5NTiRt7KiBvIcNh9g== 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 CE94E161C4 for ; Tue, 13 Feb 2024 03:41:23 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rZij7-0001U7-HN; Mon, 12 Feb 2024 21:40:53 -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 1rZij0-0001R6-6h for guix-patches@gnu.org; Mon, 12 Feb 2024 21:40:46 -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 1rZiiz-0002tW-Sm for guix-patches@gnu.org; Mon, 12 Feb 2024 21:40:45 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rZijG-0004Pb-Vt for guix-patches@gnu.org; Mon, 12 Feb 2024 21:41:03 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#69090] [PATCH] gnu: services: Add resize-fs-service. Resent-From: Gabriel Wicki Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 13 Feb 2024 02:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69090 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 69090@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170779202716858 (code B ref -1); Tue, 13 Feb 2024 02:41:02 +0000 Received: (at submit) by debbugs.gnu.org; 13 Feb 2024 02:40:27 +0000 Received: from localhost ([127.0.0.1]:38411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZiig-0004Ni-D7 for submit@debbugs.gnu.org; Mon, 12 Feb 2024 21:40:27 -0500 Received: from lists.gnu.org ([209.51.188.17]:39802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rZiWw-0003rl-63 for submit@debbugs.gnu.org; Mon, 12 Feb 2024 21:28:19 -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 1rZfc5-0006Zz-Gl for guix-patches@gnu.org; Mon, 12 Feb 2024 18:21:25 -0500 Received: from cotopaxi.ee.ethz.ch ([129.132.148.196]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rZfc3-0004KI-Bc for guix-patches@gnu.org; Mon, 12 Feb 2024 18:21:25 -0500 Received: from localhost (antispam.ee.ethz.ch [129.132.2.16]) by cotopaxi.ee.ethz.ch (Postfix) with ESMTP id 493301FE40 for ; Tue, 13 Feb 2024 00:21:07 +0100 (CET) X-Virus-Scanned: by amavisd at antispam.ee.ethz.ch Received: from cotopaxi.ee.ethz.ch ([129.132.148.196]) by localhost (antispam.ee.ethz.ch [129.132.2.16]) (amavisd-new, port 10028) with ESMTP id BXgq4H3Bg5Kz for ; Tue, 13 Feb 2024 00:21:05 +0100 (CET) Received: from blackbox (212-51-128-25.fiber7.init7.net [212.51.128.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: gabriel) by cotopaxi.ee.ethz.ch (Postfix) with ESMTPSA for ; Tue, 13 Feb 2024 00:21:05 +0100 (CET) Date: Tue, 13 Feb 2024 00:21:02 +0100 From: Gabriel Wicki Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Received-SPF: permerror client-ip=129.132.148.196; envelope-from=gabriel@erlikon.ch; helo=cotopaxi.ee.ethz.ch X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_PERMERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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-Spam-Score: -6.17 X-Migadu-Scanner: mx13.migadu.com X-Spam-Score: -6.17 X-Migadu-Queue-Id: CE94E161C4 X-TUID: ljy8SrJx7byZ Aloha and hello As promised a while back here is my patch adding a resize filesystem service that would typically be used either when flashing images onto an SD card or using an uploadable image on a VPS. Thanks for review and merge in advance, gabber >From 9b44e851252445bc628d70eb9e26574455620caf Mon Sep 17 00:00:00 2001 Message-ID: <9b44e851252445bc628d70eb9e26574455620caf.1707779839.git.gabriel@erlikon.ch> From: Gabriel Wicki Date: Tue, 13 Feb 2024 00:07:24 +0100 Subject: [PATCH] gnu: services: Add resize-fs-service. * 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 --- 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 04119a5955..093a35a331 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -40746,6 +40746,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: bb4f0509b7cce750fc944e604aa919ea89910ea7 -- 2.41.0