From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.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 mLhzE2H6XWf52QAAqHPOHw:P1 (envelope-from ) for ; Sat, 14 Dec 2024 21:36:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id mLhzE2H6XWf52QAAqHPOHw (envelope-from ) for ; Sat, 14 Dec 2024 22:36:33 +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=NmW4QpDO; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=NRJedDfc; 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=1734212192; 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=l3uvQNvWFqWfshxw9qgbCR8vwJS5olGAtbEhgceSMD8=; b=LsSPcI4bK0RtJ3t4sU8DxbuOOQ4TRHTLt+yhdBXxQjE64cSWD5bbqcSL5Kid/yUYNWGx8J soGS/vJB8dGThXVACxBDsHrONp2uDxr4aucOOuFIVJT5Oyu/wZVfXRiFNq0bNw2cHgd1S8 5bZgzWVLDPtYHlNeBVFrUhR4/Tp0cxvi0poyGw3Gb2Qo/+MCnsCGY5e8wjguK6a9mCd3G5 CyucKYwB+tIyKM6LxHn1fKtb84WxqRirmMHAjYxgsy4duMNdeSrhHfpd4HCE9PelmqZIGH q2TGx8DOnWA+w4bqupYcUw7vRX2fU7Rd1SyHybn01GxA4wxqt8IPHX3ujtAbYQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1734212192; a=rsa-sha256; cv=none; b=b4W0MW7v2bf8gtG/GKUcELH3g+4a5QdtHk8sVlbBqNWjkKbmqxBaxfQvJSoFYMQqADfA3X 0umuGXyY2b3aW+BGFEQ3+XPVjmZgdxNFUxv5akTDPa29eXxk6OFDteIGxD6+RzJsnHKvgL QmCWXncnkJ4Rg+EnuMXPOUnGbL08KQ0QIWJiiDeiCtE45/w2W9gvwUKfRUzmdtT7r9JtoH amSKSzF6AicXhkI9QS5gfSwRPy7JknDVZdIGARuB7qCiLrDmeNZKRMoGSNJNWBQQBaJGKS Obo7Vbv7KOgy5iiJwx7SWo4b5Sm+k0YTmaomfTRi1p9xvJtuD6PHaGAppMPgdQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=NmW4QpDO; dkim=fail ("headers rsa verify failed") header.d=freakingpenguin.com header.s=x header.b=NRJedDfc; 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 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 491F2840F8 for ; Sat, 14 Dec 2024 22:36:30 +0100 (CET) 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=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 Content-Type: text/plain; charset=utf-8 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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -7.31 X-Spam-Score: -7.31 X-Migadu-Queue-Id: 491F2840F8 X-Migadu-Scanner: mx11.migadu.com X-TUID: le5mZCBM9qAU * 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 -- 2.46.0