unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: raid5atemyhomework <raid5atemyhomework@protonmail.com>
To: "guix-devel@gnu.org" <guix-devel@gnu.org>
Subject: Re: ZFS on Guix
Date: Mon, 08 Feb 2021 02:13:13 +0000	[thread overview]
Message-ID: <BwsjjkFjW7wwYSYYp-YUhl5t1-1OtA8t3wbDftsQTZBXHNxcR2tBprzJmBYvNrMKnCeiu0d5bPz7V8IaKIdYu9NP7kDsd16z6gMPpR89-3c=@protonmail.com> (raw)
In-Reply-To: <VnQXBr-z8pdZxWrb6VtIu5pv0UeG1II5uUu4Q7BU3NsJMQbxhiQyWJE4fhEIWJO3VWrjetf1SMIu4_gi5r2AlYq8dADCXCDwW30RYaJ6seA=@protonmail.com>

Greetings guix-developers and other people trying to use Guix,

The patchset currently dying on issues.guix.gnu.org would provide a nice simple single-step way to enable *very basic* ZFS support on your Guix system.  Until it gets merged, however, you can still enable *very very basic* ZFS support on your Guix system by following the below minimal guide.

First, select a Linux kernel that the latest ZFS package on Guix supports.  Current on Guix is ZFS 2.0.1.  That supports up to Linux 5.10.  So I suggest using a `linux-libre-5.10` kernel.  Don't go with the default `linux-libre` or `linux-libre-lts` since those could be updated to past what the ZFS on Guix supports, be explicit with what kernel version you have.  Just remember to update to a later LTS version if ZFS on Guix ever gets updated to a later version.

Then, you need to create a ZFS package, by adding some declarations before the `operating-system` form:

```scheme
(use-modules #;...
             (guix packages))
(use-package-modules #;... linux file-systems)

(define my-kernel linux-libre-5.10)
(define my-zfs
  (package
    (inherit zfs)
    (arguments (cons* #:linux my-kernel (package-arguments zfs)))))
```

Then in the `operating-system` form, you need to add the following bits:

* Add ZFS to the kernel-loadable modules so that the installed kernel knows how to read and write ZFS disks.
* Add ZFS to the system profile packages so that you can easily manage ZFS disks.

So you have to modify a number of places:

```scheme
(operating-system
  (kernel my-kernel)
  (kernel-loadable-modules (list (list my-zfs "module")))
  #;...
  (packages
    (append (map specification->package (list "nss-certs"))
            (list my-zfs)
            %base-packages))
  #;...)
```

With the above you get a ***ridiculously minimal*** ZFS support.

* You have to `sudo modprobe zfs` explicitly at startup.
* You have to `sudo zpool import -a` explicitly at startup.

To do the above automatically at startup you need to add a Shepherd service to do the `zpool import`, and add a `kernel-module-loader` extension.  This requires a bit more code to be added to your `configuration.scm`.

Here's what I got in my `configuration.scm`:

```scheme
(define zfs-shepherd-services
  (let ((zpool            (file-append my-zfs "/sbin/zpool"))
        (zfs              (file-append my-zfs "/sbin/zfs"))
        (scheme-modules   `((srfi srfi-1)
                            (srfi srfi-34)
                            (srfi srfi-35)
                            (rnrs io ports)
                            ,@%default-modules)))
    (define zfs-scan
      (shepherd-service
        (provision '(zfs-scan))
        (documentation "Scans for ZFS pools.")
        (requirement '(kernel-module-loader udev))
        (modules scheme-modules)
        (start #~(lambda _
                   (invoke/quiet #$zpool "import" "-a" "-N")))
        (stop #~(const #f))))
    (define zfs-automount
      (shepherd-service
        (provision '(zfs-automount))
        (documentation "Automounts ZFS data sets.")
        (requirement '(zfs-scan))
        (modules scheme-modules)
        (start #~(lambda _
                   (with-output-to-port
                     (current-error-port)
                     (lambda ()
                       (invoke #$zfs "mount" "-a" "-l")))))
        (stop #~(lambda _
                  (chdir "/")
                  (invoke/quiet #$zfs "unmount" "-a" "-f")
                  #f))))
    (list zfs-scan
          zfs-automount)))
```

Then, add some `simple-service`s to your `operating-system`:

```scheme
(use-modules
  #;...
  (gnu services))
(use-service-modules linux shepherd #;...)

#;...

(operating-system
  #;...
  (services
    (append
      (list
        #;...
        (simple-service 'zfs-loader
                        kernel-module-loader-service-type
                        '("zfs"))
        (simple-service 'zfs-shepherd-services
                        shepherd-root-service-type
                        zfs-shepherd-services)
        (simple-service 'zfs-shepherd-services-user-processes
                        user-processes-service-type
                        '(zfs-automount))
        #;...)
      #;...
      %desktop-services))
  #;...)
```

The above lets you mount ZFS pools automatically at startup.  Encrypted pools with `keylocation=prompt` will prompt at the console on bootup.

Caveats:

* You can't have a `/home` on ZFS mount.  ZFS has to be mounted before `file-systems` target starts, otherwise Guix will fill up the root-mounr's `/home` directory and ZFS will refuse to mount over that.  No `/` or `/boot` on ZFS either.  Probably no good way to put `/gnu/store` on ZFS either, because Guix inherently assumes it's on the `/` mount.
* The above setup does not maintain a `/etc/zfs/zpool.cache` file, because I'm not really certain whether it's kosher in Guix to have a file maintained by ZFS in the `/etc` dir hierarchy.  This has a number of consequences:
  * `zdb` doesn't work because it looks for `/etc/zfs/zpool.cache`.  Good luck trying to figure out why your pool is slow.
  * You can't practically have more than a few dozen disks in your system, because the above uses `zpool import -a` which will cause ZFS to scan all the disks at bootup which would probably be slow if you have lots of disks.
* You can't practically use `zvol`s to back other filesystems in such a way that you can put them in a `file-system` declaration.  Though why use any file-system other than ZFS amirite.  You can still use `zvol`s to e.g. back a virtual machine that you launch manually when the system boot is finished, or from a Shepherd service that explicitly lists `user-processes` as a requirement.  Though hmmm the above doesn't use `zvol_wait` anywhere... sigh.
* There's no ZED.  No automatic replacement of failing drives with a hot spare.  No monitoring.  You can probably try launching it in its own Shepherd service, but you need to figure out how to populate `/etc/zfs/zed/` yourself.  If you do, you probably will not be doing it from the `configuration.scm` file meaning it'll be hard to replicate the setup elsewhere.


Thanks
raid5atemyhomework


  reply	other threads:[~2021-02-08  2:13 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-02  6:16 ZFS on Guix raid5atemyhomework
2021-01-02  6:40 ` raid5atemyhomework
2021-01-03 15:50   ` Danny Milosavljevic
     [not found]     ` <Kyzl4xnRrDtWbTkAmBf1i8mtSZvu-AYatdazY1NsABFAzqqi7HQl-t0d2LWAInr8n7KxGyJWfIfTWqrefrxdgWelKbr2SWc9ATV5P8zrVtw=3D@protonmail.com>
     [not found]       ` <DmzbKm-kVn1tCfYc4eAXeEEbj3RN28qvXJaLL6dHtBBeNdXE-e-vN-a4Y-De38H8jI5lt19mauUTz9k0JArMyOT2ciYoxKY8mXFw3xeHGqo=3D@protonmail.com>
     [not found]         ` <guGWV=5FuA7tRqi0SzCiial7b5W7uKlmcMRhQXIlhtzyf1Fgq91eakr8d5EQrZ2fJPJK1OqKMCJfMgE2H4SjRSph-31ms=5F2g-mFiddv9ppiaQ=3D@protonmail.com>
2021-01-04  0:50     ` raid5atemyhomework
2021-01-04  1:15       ` raid5atemyhomework
2021-01-05 11:02         ` raid5atemyhomework
2021-01-05 14:56           ` raid5atemyhomework
2021-01-06  0:59             ` Carlo Zancanaro
2021-01-06  3:50               ` raid5atemyhomework
2021-01-06  3:58                 ` Carlo Zancanaro
     [not found]                   ` <t=5Ft9LHglTTJw2Bhtd2xX4JCJeZBi5Drqg0t04vJsfRLfoENqpftZcuHO8LYi2AO05P71lbbCgQC5etCDiPsdcssJmw1pHGyCY3 gUT-9w9?= =?us-ascii?Q?=5Fo=3D@protonmail.com>
     [not found]                     ` <Zd8uMcxWfNY1RxDn4gwrCZjHKAUxSQgcuBsNDAqa0tMqj=5FufQWE-URr7L49OBWMGDfQB8v=5F8eRdnhlsZTxU0Xq=5FF6tu-92jvvc1lSh-2tdA=3D@protonmail.com>
     [not found]                       ` <vzCMYS=5FrSzkd3ZDA5TktzybU2LmfZsjWLmrd0ABQ1bIKyulAreAghoDBo0yjb-bEbH5ZmKhOO3D9WPjuDoMMUs0O eUWA1WakV?= =?us-ascii?Q?WFo6H61IHY=3D@protonmail.com>
     [not found]                         ` <07kwAFNpjhGFe7ArkjjAtRhr564wvMPGhHFyjGb=5FXdmmPNddKTmT9Swky1NbbUxHBC4xw3p-m=5F3JyW16Ql9J7PLyk6UdhCsA2cdkHehdti8=3D@protonmail.com>
     [not found]                           ` <VnQXBr-z8pdZxWrb6VtIu5pv0UeG1II5uUu4Q7BU3NsJMQbxhiQyWJE4fhEIWJO3VWrjetf1SMIu4=5Fgi5r2AlYq8dADCXCDwW30RYaJ6seA=3D@protonmail.com>
     [not found]                             ` <BwsjjkFjW7wwYSYYp-YUhl5t1-1OtA8t3wbDftsQTZBXHNxcR2tBprzJmBYvNrMKnCeiu0d5bPz7V8IaKIdYu9NP7kDsd16z6gMPpR89-3c=3D@protonmail.c om>
     [not found]                           ` <VnQXBr-z8pdZxWrb6VtIu5pv0UeG1II5uUu4Q7BU3NsJMQbxhiQyWJE4fhEIWJO3VWrjetf1SMIu4=5Fgi5r2AlY q8dADCXCD?= =?us-ascii?Q?wW30RYaJ6seA=3D@protonmail.com>
     [not found]                             ` <BwsjjkFjW7wwYSYYp-YUhl5t1-1OtA8t3wbDftsQTZBXHNxcR2tBprzJmBYvNrMKnCeiu0d5bPz7V8IaKIdYu9NP7kDsd16z6gMPpR89-3c=3D@protonmail.com>
2021-01-06  4:41                   ` raid5atemyhomework
2021-01-06  5:20                     ` raid5atemyhomework
2021-01-06 15:58                       ` raid5atemyhomework
2021-01-09 18:14                         ` raid5atemyhomework
2021-01-10  5:17                           ` raid5atemyhomework
2021-02-08  2:13                             ` raid5atemyhomework [this message]
2021-02-08  3:51                               ` Joshua Branson
2021-02-08  6:04                                 ` raid5atemyhomework
2021-02-08  6:13                               ` raid5atemyhomework
2021-02-08  9:17                               ` Maxime Devos
2021-02-08  9:32                                 ` raid5atemyhomework
2021-02-08  9:35                                   ` Maxime Devos
2021-02-10  8:29                                   ` Efraim Flashner
2021-02-08  2:16                 ` Danny Milosavljevic
2021-02-10  7:37                   ` raid5atemyhomework
     [not found] <=5F1CLe9QSGsoMlu5WxBMXm4CbFLM=5FM9iRG1XQF9GDsK0GP208jpngdymfix4tAfoLP94mhMTt-Tx6OP2xN=5Fn78Jhx5KQzkiqPpIci=5F44C9OI=3D@protonmail.com>

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='BwsjjkFjW7wwYSYYp-YUhl5t1-1OtA8t3wbDftsQTZBXHNxcR2tBprzJmBYvNrMKnCeiu0d5bPz7V8IaKIdYu9NP7kDsd16z6gMPpR89-3c=@protonmail.com' \
    --to=raid5atemyhomework@protonmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).