all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Resize Filesystem Service
@ 2023-12-04 15:33 Wicki Gabriel (wicg)
  2023-12-04 20:18 ` Felix Lechner via
  0 siblings, 1 reply; 7+ messages in thread
From: Wicki Gabriel (wicg) @ 2023-12-04 15:33 UTC (permalink / raw)
  To: help-guix@gnu.org

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]

Hi

For a small embedded software project I need a resize-fs-service: a one-shot service started during boot that ensures that the rootfs (created from a guix system image foo.scm​ command) uses all of the medium's space -- creating an image of the correct size is completely infeasible as you may imagine.

I crafted the service in the file attached but this doesn't work and i neither know where to look nor how to debug the issue.

Any ideas are deeply appreciated!

Thanks for your time and effort!
Gabriel aka gabber

--
Gabriel Wicki
Research Assistant

ZHAW, Zurich University of Applied Sciences
InES, Institute of Embedded Systems
High Integrity Systems Group

Technikumstrasse 22, Postfach
CH-8401 Winterthur
--
E-Mail: wicg@zhaw.ch
Web: http://ines.zhaw.ch

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: resize-fs.scm --]
[-- Type: text/x-scheme; name="resize-fs.scm", Size: 2320 bytes --]

(define-module (resize-fs)
  #:use-module (gnu packages disk)
  #:use-module (gnu packages linux)

  #:use-module (guix build utils)
  #:use-module (guix packages)

  #:use-module (gnu services)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (gnu services shepherd))

(define (resize-fs-service config)
  (use-modules (guix gexp))
  (define parted #$(string-append (or (resize-fs-configuration-parted config)
                                      parted)
                                  "/sbin/parted"))
  (define resize2fs #$(string-append (or (resize-fs-configuration-e2fsprogs config)
                                         e2fsprogs)
                                     "/sbin/resize2fs"))
  (define size #$(resize-fs-configuration-size config))
  (define device #$(resize-fs-configuration-device config))
  (define partition #$(resize-fs-configuration-partition config))
  (define device+partition (string-append device "p" partition))

  (shepherd-service
   (documentation "Resize a file-system.  Intended for Guix Systems that are booted from an image")
   (provision '(resize-fs))
   (one-shot? #t)
   (requirement '())
   (start #~(invoke (plain-file "resize_partition.bash"
                                (string-append
                                 "#!/bin/sh
parted " #$device " ---pretend-input-tty <<EOF
resizepart
" #$partition "
Yes
" #$size"
EOF
" $#resize2fs " " device+partition))))))

(define-record-type* <resize-fs-configuration>
  resize-fs-configuration make-resize-fs-configuration
  resize-fs-configuration?
  ;; the utilities doing the job
  (parted resize-fs-configuraiton-parted
          (default parted))
  (e2fsprogs resize-fs-configuration-e2fsprogs
             (default e2fsprogs))
  ;; path of a device
  (device resize-fs-configuration-device
          (default "/dev/mmcblk0")) ; #f may be preferrable here
  ;; integer
  (partition resize-fs-configuration-partition
             (default 2))
  ;; size - as understood by parted
  (size resize-fs-configuration-size
        (default "100%")))

(define-public resize-fs-service-type
  (service-type
   (name 'resize-fs)
   (extensions
    (list (service-extension shepherd-root-service-type resize-fs-service)))
   (description "Resize a partition.")
   (default-value (resize-fs-configuration))))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
  2023-12-04 15:33 Resize Filesystem Service Wicki Gabriel (wicg)
@ 2023-12-04 20:18 ` Felix Lechner via
  2023-12-07  9:25   ` Wicki Gabriel (wicg)
  0 siblings, 1 reply; 7+ messages in thread
From: Felix Lechner via @ 2023-12-04 20:18 UTC (permalink / raw)
  To: Wicki Gabriel (wicg), help-guix@gnu.org

Hi Gabriel,

On Mon, Dec 04 2023, Wicki Gabriel wrote:

> I crafted the service in the file attached but this doesn't work and i
> neither know where to look nor how to debug the issue.

Writing services is probably more complex than it should be, but it can
be done.

Please have a look at the cachefilesd-service [1] which I wrote together
with Bruno Victal (mirai) and which was accepted, or the Heimdal
Kerberos services that are still waiting for review. [2]

My most immediate suggestion is that I would use define-configuration
even when no serialization (which helps write configuration files) is
needed. Also, you have to think carefully about where to place the
G-Expressions, which can be tough to wrap your mind arround. Finally, I
would use "file-append" instead of string-append for some of the
configurable executable paths.

Kind regards
Felix

[1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
[2] https://issues.guix.gnu.org/67555


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
  2023-12-04 20:18 ` Felix Lechner via
@ 2023-12-07  9:25   ` Wicki Gabriel (wicg)
  2023-12-07 10:14     ` Efraim Flashner
  0 siblings, 1 reply; 7+ messages in thread
From: Wicki Gabriel (wicg) @ 2023-12-07  9:25 UTC (permalink / raw)
  To: help-guix@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1491 bytes --]

Hi

Thanks for the input, Felix.  I finally managed to get it to work (with additional input from ludo).  I attach the service to this mail.  If people think this might be a nice-to-have in upstream guix i'll happily craft a patch.

g
________________________________
From: Felix Lechner <felix.lechner@lease-up.com>
Sent: Monday, December 4, 2023 9:18 PM
To: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
Subject: Re: Resize Filesystem Service

Hi Gabriel,

On Mon, Dec 04 2023, Wicki Gabriel wrote:

> I crafted the service in the file attached but this doesn't work and i
> neither know where to look nor how to debug the issue.

Writing services is probably more complex than it should be, but it can
be done.

Please have a look at the cachefilesd-service [1] which I wrote together
with Bruno Victal (mirai) and which was accepted, or the Heimdal
Kerberos services that are still waiting for review. [2]

My most immediate suggestion is that I would use define-configuration
even when no serialization (which helps write configuration files) is
needed. Also, you have to think carefully about where to place the
G-Expressions, which can be tough to wrap your mind arround. Finally, I
would use "file-append" instead of string-append for some of the
configurable executable paths.

Kind regards
Felix

[1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
[2] https://issues.guix.gnu.org/67555

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: resize-fs.scm --]
[-- Type: text/x-scheme; name="resize-fs.scm", Size: 2957 bytes --]

(define-module (services resize-fs)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (gnu packages bash)
  #:use-module (gnu packages disk) ; parted
  #:use-module (gnu packages linux); e2fsprogs
  #:use-module (guix build utils)
  #:use-module (guix packages)
  #:use-module (gnu services)
  #:use-module (gnu services configuration)
  #:use-module (gnu services shepherd)
  #:export (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))

(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/mmcblk0") ;; #f may be preferrable here to prevent accidental resizing of wrong file-system
   "The device containing the partition to be resized.")
  (partition
   (number 2)
   "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 <resize-fs-configuration> (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 <<EOF && " resize2fs " " device+partition "
resizepart
" (number->string partition) "
Yes
" end "
EOF
}

set -o errexit
set -o pipefail

echoerr hello from resize-fs script

if cmd; then
  echoerr \"Resizing successful\"
else
  echoerr \"resize-script returned $?\"
fi
"))))

(define (resize-fs-shepherd-service config)
  "Return a list of <shepherd-service> 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 an image")
     (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.")
   (extensions
    (list
     (service-extension shepherd-root-service-type
                        (compose list resize-fs-shepherd-service))))
   (default-value (resize-fs-configuration))))

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
  2023-12-07  9:25   ` Wicki Gabriel (wicg)
@ 2023-12-07 10:14     ` Efraim Flashner
  2023-12-10 17:03       ` Csepp
  0 siblings, 1 reply; 7+ messages in thread
From: Efraim Flashner @ 2023-12-07 10:14 UTC (permalink / raw)
  To: Wicki Gabriel (wicg); +Cc: help-guix@gnu.org

[-- Attachment #1: Type: text/plain, Size: 5448 bytes --]

On Thu, Dec 07, 2023 at 09:25:43AM +0000, Wicki Gabriel (wicg) wrote:
> Hi
> 
> Thanks for the input, Felix.  I finally managed to get it to work (with additional input from ludo).  I attach the service to this mail.  If people think this might be a nice-to-have in upstream guix i'll happily craft a patch.
> 
> g
> ________________________________
> From: Felix Lechner <felix.lechner@lease-up.com>
> Sent: Monday, December 4, 2023 9:18 PM
> To: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
> Subject: Re: Resize Filesystem Service
> 
> Hi Gabriel,
> 
> On Mon, Dec 04 2023, Wicki Gabriel wrote:
> 
> > I crafted the service in the file attached but this doesn't work and i
> > neither know where to look nor how to debug the issue.
> 
> Writing services is probably more complex than it should be, but it can
> be done.
> 
> Please have a look at the cachefilesd-service [1] which I wrote together
> with Bruno Victal (mirai) and which was accepted, or the Heimdal
> Kerberos services that are still waiting for review. [2]
> 
> My most immediate suggestion is that I would use define-configuration
> even when no serialization (which helps write configuration files) is
> needed. Also, you have to think carefully about where to place the
> G-Expressions, which can be tough to wrap your mind arround. Finally, I
> would use "file-append" instead of string-append for some of the
> configurable executable paths.
> 
> Kind regards
> Felix
> 
> [1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
> [2] https://issues.guix.gnu.org/67555

> (define-module (services resize-fs)
>   #:use-module (guix gexp)
>   #:use-module (guix records)
>   #:use-module (gnu packages bash)
>   #:use-module (gnu packages disk) ; parted
>   #:use-module (gnu packages linux); e2fsprogs
>   #:use-module (guix build utils)
>   #:use-module (guix packages)
>   #:use-module (gnu services)
>   #:use-module (gnu services configuration)
>   #:use-module (gnu services shepherd)
>   #:export (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))
> 
> (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/mmcblk0") ;; #f may be preferrable here to prevent accidental resizing of wrong file-system
>    "The device containing the partition to be resized.")
>   (partition
>    (number 2)
>    "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 <resize-fs-configuration> (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 <<EOF && " resize2fs " " device+partition "
> resizepart
> " (number->string partition) "
> Yes
> " end "
> EOF
> }
> 
> set -o errexit
> set -o pipefail
> 
> echoerr hello from resize-fs script
> 
> if cmd; then
>   echoerr \"Resizing successful\"
> else
>   echoerr \"resize-script returned $?\"
> fi
> "))))
> 
> (define (resize-fs-shepherd-service config)
>   "Return a list of <shepherd-service> 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 an image")
>      (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.")
>    (extensions
>     (list
>      (service-extension shepherd-root-service-type
>                         (compose list resize-fs-shepherd-service))))
>    (default-value (resize-fs-configuration))))

I think it would be helpful to have upstream. I'm guessing it would be
useful not just on single board computers but also on VPSs and probably
other use cases.

Not directly related to upstreaming this service, this seems like a
useful service to offer for an 'on first boot' service, or as some sort
of special service to be loaded with 'sudo herd load root'.

-- 
Efraim Flashner   <efraim@flashner.co.il>   רנשלפ םירפא
GPG key = A28B F40C 3E55 1372 662D  14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
  2023-12-07 10:14     ` Efraim Flashner
@ 2023-12-10 17:03       ` Csepp
  2023-12-12  9:46           ` Wicki Gabriel (wicg)
  0 siblings, 1 reply; 7+ messages in thread
From: Csepp @ 2023-12-10 17:03 UTC (permalink / raw)
  To: Efraim Flashner; +Cc: Wicki Gabriel (wicg), help-guix

#+OPTIONS: html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil tex:dvipng d:nil
#+STARTUP: hidestars indent inlineimages
:PROPERTIES:
:reply-to: nil
:attachment: nil
:alternatives: (utf-8)
:END:

Efraim Flashner <efraim@flashner.co.il> writes:

> [[PGP Signed Part:Undecided]]
> On Thu, Dec 07, 2023 at 09:25:43AM +0000, Wicki Gabriel (wicg) wrote:
>> Hi
>>
>> Thanks for the input, Felix. I finally managed to get it to work (with
>> additional input from ludo). I attach the service to this mail. If people
>> think this might be a nice-to-have in upstream guix i'll happily craft a
>> patch.
>>
>> g
>> ________________________________
>> From: Felix Lechner <felix.lechner@lease-up.com>
>> Sent: Monday, December 4, 2023 9:18 PM
>> To: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
>> Subject: Re: Resize Filesystem Service
>>
>> Hi Gabriel,
>>
>> On Mon, Dec 04 2023, Wicki Gabriel wrote:
>>
>> > I crafted the service in the file attached but this doesn't work and i
>> > neither know where to look nor how to debug the issue.
>>
>> Writing services is probably more complex than it should be, but it can
>> be done.
>>
>> Please have a look at the cachefilesd-service [1] which I wrote together
>> with Bruno Victal (mirai) and which was accepted, or the Heimdal
>> Kerberos services that are still waiting for review. [2]
>>
>> My most immediate suggestion is that I would use define-configuration
>> even when no serialization (which helps write configuration files) is
>> needed. Also, you have to think carefully about where to place the
>> G-Expressions, which can be tough to wrap your mind arround. Finally, I
>> would use "file-append" instead of string-append for some of the
>> configurable executable paths.
>>
>> Kind regards
>> Felix
>>
>> [1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
>> [2] https://issues.guix.gnu.org/67555
>
>> (define-module (services resize-fs)
>>   #:use-module (guix gexp)
>>   #:use-module (guix records)
>>   #:use-module (gnu packages bash)
>>   #:use-module (gnu packages disk) ; parted
>>   #:use-module (gnu packages linux); e2fsprogs
>>   #:use-module (guix build utils)
>>   #:use-module (guix packages)
>>   #:use-module (gnu services)
>>   #:use-module (gnu services configuration)
>>   #:use-module (gnu services shepherd)
>>   #:export (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))
>>
>> (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/mmcblk0") ;; #f may be preferrable here to prevent accidental resizing of wrong file-system
>>    "The device containing the partition to be resized.")
>>   (partition
>>    (number 2)
>>    "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 <resize-fs-configuration> (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 <<EOF && " resize2fs " " device+partition "
>> resizepart
>> " (number->string partition) "
>> Yes
>> " end "
>> EOF
>> }
>>
>> set -o errexit
>> set -o pipefail
>>
>> echoerr hello from resize-fs script
>>
>> if cmd; then
>>   echoerr \"Resizing successful\"
>> else
>>   echoerr \"resize-script returned $?\"
>> fi
>> "))))
>>
>> (define (resize-fs-shepherd-service config)
>>   "Return a list of <shepherd-service> 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 an image")
>>      (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.")
>>    (extensions
>>     (list
>>      (service-extension shepherd-root-service-type
>>                         (compose list resize-fs-shepherd-service))))
>>    (default-value (resize-fs-configuration))))
>
> I think it would be helpful to have upstream. I'm guessing it would be
> useful not just on single board computers but also on VPSs and probably
> other use cases.
>
> Not directly related to upstreaming this service, this seems like a
> useful service to offer for an 'on first boot' service, or as some sort
> of special service to be loaded with 'sudo herd load root'.

I tried to write something similar for my VPS but it wasn't working at boot,
although it did if I restarted the service.
So I for one would be very grateful if a working resizer service were
upstreamed.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
@ 2023-12-12  9:46           ` Wicki Gabriel (wicg)
  0 siblings, 0 replies; 7+ messages in thread
From: Wicki Gabriel (wicg) @ 2023-12-12  9:46 UTC (permalink / raw)
  To: guix-devel@gnu.org; +Cc: help-guix@gnu.org, Csepp

Would you mind giving my previously attached service a try and tell me whether this works?

If there is no other input I will just prepare a patch where the service renders a bash script which (somewhat stupidly) attempts to resize the file-system at (every!) boot - mostly because I'm not sure whether we have the facilities to (or I wouldn't know how)

  1.  run a service once per system generation (or some other measure) and
  2.  to construct such a Shell-script in a more verifiable or maintainable fashion in Guile (though I'd be willing to write relevant helper functions)

Thanks for all your input!  If there is no more input I'll just prepare some patch from the existing service.

P.S. Since this isn't a classic "help" problem anymore I'm moving the discussion over to the devel-list.
________________________________
From: Csepp <raingloom@riseup.net>
Sent: Sunday, December 10, 2023 6:03 PM
To: Efraim Flashner <efraim@flashner.co.il>
Cc: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
Subject: Re: Resize Filesystem Service

#+OPTIONS: html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil tex:dvipng d:nil
#+STARTUP: hidestars indent inlineimages
:PROPERTIES:
:reply-to: nil
:attachment: nil
:alternatives: (utf-8)
:END:

Efraim Flashner <efraim@flashner.co.il> writes:

> [[PGP Signed Part:Undecided]]
> On Thu, Dec 07, 2023 at 09:25:43AM +0000, Wicki Gabriel (wicg) wrote:
>> Hi
>>
>> Thanks for the input, Felix. I finally managed to get it to work (with
>> additional input from ludo). I attach the service to this mail. If people
>> think this might be a nice-to-have in upstream guix i'll happily craft a
>> patch.
>>
>> g
>> ________________________________
>> From: Felix Lechner <felix.lechner@lease-up.com>
>> Sent: Monday, December 4, 2023 9:18 PM
>> To: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
>> Subject: Re: Resize Filesystem Service
>>
>> Hi Gabriel,
>>
>> On Mon, Dec 04 2023, Wicki Gabriel wrote:
>>
>> > I crafted the service in the file attached but this doesn't work and i
>> > neither know where to look nor how to debug the issue.
>>
>> Writing services is probably more complex than it should be, but it can
>> be done.
>>
>> Please have a look at the cachefilesd-service [1] which I wrote together
>> with Bruno Victal (mirai) and which was accepted, or the Heimdal
>> Kerberos services that are still waiting for review. [2]
>>
>> My most immediate suggestion is that I would use define-configuration
>> even when no serialization (which helps write configuration files) is
>> needed. Also, you have to think carefully about where to place the
>> G-Expressions, which can be tough to wrap your mind arround. Finally, I
>> would use "file-append" instead of string-append for some of the
>> configurable executable paths.
>>
>> Kind regards
>> Felix
>>
>> [1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
>> [2] https://issues.guix.gnu.org/67555
>
>> (define-module (services resize-fs)
>>   #:use-module (guix gexp)
>>   #:use-module (guix records)
>>   #:use-module (gnu packages bash)
>>   #:use-module (gnu packages disk) ; parted
>>   #:use-module (gnu packages linux); e2fsprogs
>>   #:use-module (guix build utils)
>>   #:use-module (guix packages)
>>   #:use-module (gnu services)
>>   #:use-module (gnu services configuration)
>>   #:use-module (gnu services shepherd)
>>   #:export (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))
>>
>> (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/mmcblk0") ;; #f may be preferrable here to prevent accidental resizing of wrong file-system
>>    "The device containing the partition to be resized.")
>>   (partition
>>    (number 2)
>>    "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 <resize-fs-configuration> (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 <<EOF && " resize2fs " " device+partition "
>> resizepart
>> " (number->string partition) "
>> Yes
>> " end "
>> EOF
>> }
>>
>> set -o errexit
>> set -o pipefail
>>
>> echoerr hello from resize-fs script
>>
>> if cmd; then
>>   echoerr \"Resizing successful\"
>> else
>>   echoerr \"resize-script returned $?\"
>> fi
>> "))))
>>
>> (define (resize-fs-shepherd-service config)
>>   "Return a list of <shepherd-service> 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 an image")
>>      (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.")
>>    (extensions
>>     (list
>>      (service-extension shepherd-root-service-type
>>                         (compose list resize-fs-shepherd-service))))
>>    (default-value (resize-fs-configuration))))
>
> I think it would be helpful to have upstream. I'm guessing it would be
> useful not just on single board computers but also on VPSs and probably
> other use cases.
>
> Not directly related to upstreaming this service, this seems like a
> useful service to offer for an 'on first boot' service, or as some sort
> of special service to be loaded with 'sudo herd load root'.

I tried to write something similar for my VPS but it wasn't working at boot,
although it did if I restarted the service.
So I for one would be very grateful if a working resizer service were
upstreamed.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Resize Filesystem Service
@ 2023-12-12  9:46           ` Wicki Gabriel (wicg)
  0 siblings, 0 replies; 7+ messages in thread
From: Wicki Gabriel (wicg) @ 2023-12-12  9:46 UTC (permalink / raw)
  To: guix-devel@gnu.org; +Cc: help-guix@gnu.org, Csepp

[-- Attachment #1: Type: text/plain, Size: 6967 bytes --]

Would you mind giving my previously attached service a try and tell me whether this works?

If there is no other input I will just prepare a patch where the service renders a bash script which (somewhat stupidly) attempts to resize the file-system at (every!) boot - mostly because I'm not sure whether we have the facilities to (or I wouldn't know how)

  1.  run a service once per system generation (or some other measure) and
  2.  to construct such a Shell-script in a more verifiable or maintainable fashion in Guile (though I'd be willing to write relevant helper functions)

Thanks for all your input!  If there is no more input I'll just prepare some patch from the existing service.

P.S. Since this isn't a classic "help" problem anymore I'm moving the discussion over to the devel-list.
________________________________
From: Csepp <raingloom@riseup.net>
Sent: Sunday, December 10, 2023 6:03 PM
To: Efraim Flashner <efraim@flashner.co.il>
Cc: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
Subject: Re: Resize Filesystem Service

#+OPTIONS: html-postamble:nil H:5 num:nil ^:{} toc:nil author:nil email:nil tex:dvipng d:nil
#+STARTUP: hidestars indent inlineimages
:PROPERTIES:
:reply-to: nil
:attachment: nil
:alternatives: (utf-8)
:END:

Efraim Flashner <efraim@flashner.co.il> writes:

> [[PGP Signed Part:Undecided]]
> On Thu, Dec 07, 2023 at 09:25:43AM +0000, Wicki Gabriel (wicg) wrote:
>> Hi
>>
>> Thanks for the input, Felix. I finally managed to get it to work (with
>> additional input from ludo). I attach the service to this mail. If people
>> think this might be a nice-to-have in upstream guix i'll happily craft a
>> patch.
>>
>> g
>> ________________________________
>> From: Felix Lechner <felix.lechner@lease-up.com>
>> Sent: Monday, December 4, 2023 9:18 PM
>> To: Wicki Gabriel (wicg) <wicg@zhaw.ch>; help-guix@gnu.org <help-guix@gnu.org>
>> Subject: Re: Resize Filesystem Service
>>
>> Hi Gabriel,
>>
>> On Mon, Dec 04 2023, Wicki Gabriel wrote:
>>
>> > I crafted the service in the file attached but this doesn't work and i
>> > neither know where to look nor how to debug the issue.
>>
>> Writing services is probably more complex than it should be, but it can
>> be done.
>>
>> Please have a look at the cachefilesd-service [1] which I wrote together
>> with Bruno Victal (mirai) and which was accepted, or the Heimdal
>> Kerberos services that are still waiting for review. [2]
>>
>> My most immediate suggestion is that I would use define-configuration
>> even when no serialization (which helps write configuration files) is
>> needed. Also, you have to think carefully about where to place the
>> G-Expressions, which can be tough to wrap your mind arround. Finally, I
>> would use "file-append" instead of string-append for some of the
>> configurable executable paths.
>>
>> Kind regards
>> Felix
>>
>> [1] https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/linux.scm#n492
>> [2] https://issues.guix.gnu.org/67555
>
>> (define-module (services resize-fs)
>>   #:use-module (guix gexp)
>>   #:use-module (guix records)
>>   #:use-module (gnu packages bash)
>>   #:use-module (gnu packages disk) ; parted
>>   #:use-module (gnu packages linux); e2fsprogs
>>   #:use-module (guix build utils)
>>   #:use-module (guix packages)
>>   #:use-module (gnu services)
>>   #:use-module (gnu services configuration)
>>   #:use-module (gnu services shepherd)
>>   #:export (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))
>>
>> (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/mmcblk0") ;; #f may be preferrable here to prevent accidental resizing of wrong file-system
>>    "The device containing the partition to be resized.")
>>   (partition
>>    (number 2)
>>    "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 <resize-fs-configuration> (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 <<EOF && " resize2fs " " device+partition "
>> resizepart
>> " (number->string partition) "
>> Yes
>> " end "
>> EOF
>> }
>>
>> set -o errexit
>> set -o pipefail
>>
>> echoerr hello from resize-fs script
>>
>> if cmd; then
>>   echoerr \"Resizing successful\"
>> else
>>   echoerr \"resize-script returned $?\"
>> fi
>> "))))
>>
>> (define (resize-fs-shepherd-service config)
>>   "Return a list of <shepherd-service> 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 an image")
>>      (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.")
>>    (extensions
>>     (list
>>      (service-extension shepherd-root-service-type
>>                         (compose list resize-fs-shepherd-service))))
>>    (default-value (resize-fs-configuration))))
>
> I think it would be helpful to have upstream. I'm guessing it would be
> useful not just on single board computers but also on VPSs and probably
> other use cases.
>
> Not directly related to upstreaming this service, this seems like a
> useful service to offer for an 'on first boot' service, or as some sort
> of special service to be loaded with 'sudo herd load root'.

I tried to write something similar for my VPS but it wasn't working at boot,
although it did if I restarted the service.
So I for one would be very grateful if a working resizer service were
upstreamed.

[-- Attachment #2: Type: text/html, Size: 13278 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-12-13 17:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-04 15:33 Resize Filesystem Service Wicki Gabriel (wicg)
2023-12-04 20:18 ` Felix Lechner via
2023-12-07  9:25   ` Wicki Gabriel (wicg)
2023-12-07 10:14     ` Efraim Flashner
2023-12-10 17:03       ` Csepp
2023-12-12  9:46         ` Wicki Gabriel (wicg)
2023-12-12  9:46           ` Wicki Gabriel (wicg)

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.