fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

8.6K
active users

#ZFSBootMenu

0 posts0 participants0 posts today

My ZFS snapshot and replication setup on Ubuntu ft. sanoid and syncoid

I have known about ZFS since 2009, when I was working for Sun Microsystems as a campus ambassador at my college. But it wasn’t until I started hearing Jim Salter (on the TechSNAP and 2.5 Admins podcasts) and Allan Jude (on the 2.5 Admins podcast) evangelize ZFS that I became interested in using it on my computers and servers. With Ubuntu shipping ZFS in the kernel for many years now, I had access to native ZFS!,

Here is an overview of my setup running Ubuntu + ZFS before I explain and document some of the details.

  • cube – A headless server running Ubuntu 24.04 LTS (at the time of writing) with ZFS on root and a lot of ZFS storage powered by mirror vdevs. Has sanoid for automatic snapshots.
  • Desktops and laptops in my home run (K)Ubuntu (24.04 or later; versions vary) with encrypted (ZFS native encryption) ZFS on root and ZFSBootMenu. These computers also use sanoid for automatic snapshots.

Sanoid configuration

On my personal computers, I use a minimal sanoid configuration that looks like

############# datasets #############[zroot]        use_template = production        recursive = zfs############## templates ##############[template_production]        frequently = 0        hourly = 26        daily = 30        monthly = 3        yearly = 0        autosnap = yes        autoprune = yes[template_ignore]        autoprune = no        autosnap = no        monitor = no

On servers, the sanoid configuration has some additional tweaks, like the following template to not snapshot replicated datasets.

[template_backup]        frequently = 0        hourly = 36        daily = 30        monthly = 3        yearly = 0        # don't take new snapshots - snapshots        # on backup datasets are replicated in        # from source, not generated locally        autosnap = no

Pre-apt snapshots

While sanoid provides periodic ZFS snapshots, I also wanted to wrap apt transactions in ZFS snapshots for the ability to roll back any bad updates/upgrades. For this, I used the following shell script,

#!/usr/bin/env bashDATE="$(/bin/date +%F-%T)"zfs snapshot -r zroot@snap_pre_apt_"$DATE"

with the following apt hook in /etc/apt/apt.conf.d/90zfs-pre-apt-snapshot.

// Takes a snapshot of the system before package changes.DPkg::Pre-Invoke {"[ -x /usr/local/sbin/zfs-pre-apt-snapshot ] && /usr/local/sbin/zfs-pre-apt-snapshot || true";};

This handles taking snapshots before apt transactions but doesn’t prune the snapshots at all. For that, I used the zfs-prune-snapshots script (from https://github.com/bahamas10/zfs-prune-snapshots) in a wrapper cron shell (schedule varies per computer) script that looks like

#!/bin/sh/usr/local/sbin/zfs-prune-snapshots \    -p 'snap_pre_apt_' \    1w 2>&1 | logger \    -t cleanup-zfs-pre-apt-snapshots

Snapshot replication

The cube server has sufficient disk space to provide a replication target for all my other personal computers using ZFS. It has a pool named dpool, which will be referenced in the details to follow.

For automating snapshot replication, I chose to use syncoid from the same sanoid package. To avoid giving privileged access to the sending and the receiving user accounts, my setup closely follows the path in https://klarasystems.com/articles/improving-replication-security-with-openzfs-delegation/.

On my personal computer, I granted my unprivileged (but has sudo 🤷‍♂️) local user account the hold and send permissions on the root dataset, zroot.

sudo zfs allow send-user hold,send zrootzfs allow zroot---- Permissions on zroot --------------------------------------------Local+Descendent permissions:        user send-user hold,send

On the cube server, I created an unprivileged user (no sudo permissions here 😌) and granted it the create,mount,receive permissions temporarily on the parent of the target dataset, dpool.

Then I performed an initial full replication of a local snapshot by running the following commands as the unprivileged user.

zfs send \  zroot@snapshot-name | ssh \  remote-user@cube \  zfs receive -u \  dpool/local-hostnamezfs send \  zroot/ROOT@snapshot-name | ssh \  remote-user@cube \  zfs receive -u \  dpool/local-hostname/ROOTzfs send \  zroot/ROOT/os-name@snapshot-name | ssh \  remote-user@cube \  zfs receive -u \    dpool/local-hostname/ROOT/os-namezfs send \  zroot/home@snapshot-name | ssh \  remote-user@cube \  zfs receive -u \  dpool/local-hostname/home

The -u flag in the zfs receive commands above will prevent it from trying to mount the remote dataset. The target remote dataset must not exist when running this initial full replication.

As it is not a good practice to allow unprivileged users to mount filesystems, I disabled automatic mounting by running

zfs set mountpoint=none dpool/local-hostname

as the sudo user on the target server.

Then I narrowed down the permissions of the receiving user to only its own dataset by running

zfs unallow remote-user \  create,mount,receive dpoolzfs allow remote-user \  create,mount,receive dpool/local-hostname

on the target server.

Next, I tried to test the snapshot replication by running syncoid manually like

syncoid -r \  --no-privilege-elevation \  --no-sync-snap \  zroot \  remote-user@cube:dpool/local-hostname

and it replicated all the other snapshots all on the local datasets (we had only replicated one snapshot previously).

The sanoid package in Debian and Ubuntu does not ship with a systemd timer for syncoid. So I created a user service and a timer that look like the following examples.

# ~/.config/systemd/user/syncoid.service[Unit]Description=Replicate sanoid snapshots[Service]Type=oneshotExecStart=/usr/sbin/syncoid -r --no-privilege-elevation --no-sync-snap zroot remote-user@cube:dpool/local-hostname
# ~/.config/systemd/user/syncoid.timer[Unit]Description=Run Syncoid to replicate ZFS snapshots to cube[Timer]OnCalendar=*:0/15Persistent=true[Install]WantedBy=timers.target

Then I reloaded systemd, enabled and started the above timer to have everything working smoothly.

mercenarysysadmin.comJim's Social Media links:
Replied in thread

@paul @linus @stefano @whynothugo I chose Ubuntu (for KDE Plasma) because the installer provides root-on-ZFS.

With that base, I have not yet figured out which of these will be the simplest way forward:

― bemgr
― zectl
― ZFSBootMenu.

<gist.github.com/grahamperrin/a>

I see verbose guides, the verbosity creates a sense of complication.

I'd like the simplest possible guide to getting started, with any of the three options, where the boot environment layout/structure is predetermined by the installer for Ubuntu.

TIA

GistFreeBSD, GhostBSD, NomadBSD, Ubuntu, Kubuntu, KDE PlasmaFreeBSD, GhostBSD, NomadBSD, Ubuntu, Kubuntu, KDE Plasma - somesystems.md
Replied in thread

@ahoyboyhoy @andreasgoebel in addition to ZFSBootMenu …

I'm looking at zectl, <ramsdenj.com/posts/2020-03-18->

― zectl ZFS Boot Environment Manager for Linux · John Ramsden

Back to Manjaro. Reading <github.com/calamares/calamares> (2021) alongside <en.wikipedia.org/wiki/Calamare>, I wonder why ZFS on root is not an option.

<theregister.com/2024/08/01/lin> @lproven mentions licencing …

― Linux updates with an undo function? Some distros have that • The Register

Maybe I'll never need to undo :-)

John Ramsden · zectl ZFS Boot Environment Manager for LinuxI’m happy to announce a new ZFS boot environment manager written completely from scratch in C - zectl. In 2018 I wrote zedenv, a ZFS Boot Environment manager, I’ve taken what I learned from zedenv and added improvements in workflow, performance and reliability. For a summary on what a boot environment manager is, and how it can be used see my previous post. Why the Rewrite Link to heading I had been having misgivings about writing my original implementation in Python. At the time of writing there was no libzfs library interface for python and I wrote my own “wrapper library” - pyzfscmds - that simply called out to the zfs binary. While the wrapper has worked, it meant a lot of extra work was done parsing string output from zfs subcommands. Directly using the libzfs library allows for more robust code, significantly better performance, and error handling. I was considering porting the python tool to use py-libzfs, or writing it in C when the tool bectl came out for FreeBSD. Seeing bectl’s impressive implementation I was inspired to do the rewrite in C.

For a switch away from everyday use of FreeBSD 15.0-CURRENT with KDE Plasma and ZFS boot environments:

― which of these two Linux distros might be best for me?

<manjaro.org/>

<sparkylinux.org/>

Emphases: easy installation, non-complicated upgrades, GUI.

Root on ZFS, and ZFS boot environments, will be nice, but not essential. If not easily achievable now, I can switch more than once:

– first to Linux, then from one distro to another.

Whatever Linux distros I use: I'll continue with Plasma.

I began toying with SparkyLinux in February 2024. Prior experience with Manjaro was excellent.

manjaro.orgManjaro Linux OfficialThis page provides an overview of Manjaro Linux, an open source operating system designed for ease of use. Learn about its features, installation, and support options. Get the most out of Manjaro Linux with the latest news, downloads, and tips from our helpful community.

Edit:
While I still haven’t the slightest idea exactly was causing the issue, I did find a resolution to it

Thank you Arch Wiki
========
Okay my fellow #OpenZFS on #Linux peoples, I need help

I've attempted installs of #Debian Bookworm and Trixie in GNOME Boxes, and unlike my previous Boxes installations, this time around I'm getting this weird error (image attached) that is preventing it from booting the OS

#ZFS is the root file system, and #ZFSBootMenu is being used

I've done this exact installation method multiple times before successfully, both in VMs and real hardware, however for reasons unbeknownst to me they are now failing

Have not tried this on real hardware to see if it's just a VM thing (don't wanna grab a spare machine out at this time of night)

My "Google Fu" must be rusty, because I'm not really finding anything helpful in troubleshooting this

Replied in thread

@mroach @hyperreal if you're using UEFI, I prefer to use instead of - because it has great ZFS root support (no need for ext4 /boot file system), and supports boot environments (easy rollback from failed upgrade)!

In which case, these are the better instructions to follow (fully replacing the other instructions you linked to): docs.zfsbootmenu.org/en/latest

docs.zfsbootmenu.orgBookworm (12) UEFI — ZFSBootMenu 3.0.1 documentation

Even though I've managed to run #Ubuntu 24.04 desktop quite stable, it still doesn't inflict too much confidence. Hence my #Linux attempt no. 2: Fedora desktop 41. Which, amazingly, runs smooth and stable as it should. And since I find ZFS a nice fit, I'm trying to install it using #zfsbootmenu. Almost done except EFI boot. Tomorrow is an EFI day I guess. @lapor

Starting to get the itch to re-do my server, as this is the year Ubuntu 20.04 LTS loses support. Was thinking TrueNAS but wanted a little more freedom with lower ports. Now thinking about using #ZFSBootMenu on Alpine as a host for converting most everything to #docker :

docs.zfsbootmenu.org/en/v3.0.x…

Then make a few zpools for different benefits for my nextcloud docks and the other services I use...

Now not to get tempted with getting a refurb DL580 G9. 😅

docs.zfsbootmenu.orgUEFI — ZFSBootMenu 3.0.1 documentation
My #AMD #ThinkPad P14s with 16Gb ram certainly boots faster than it did when I ran #ChimeraLinux with #ZFS and #ZFSBootMenu . Shutting down using the poweroff command I'd say #Linux wins but not by much, though I am using #Geli for encryption on my FreeBSD laptop which maybe slows it a little ? The rest of the speeds for general use it's hard to tell so far and as for resilience I've had no issues as yet and the same could be said for my #HomeLab too.
Why did I choose FreeBSD ? As I was already leaning towards #BSD using Chimera Linux I thought I'd have a read up on various and really liked ZFS so it was obvious that I would choose FreeBSD really. I have read up on #OpenBSD but looking at the docs, reviews and their software repo's I decided it was for me right now. I will be honest some things do seems harder but that's what makes it exciting again as I'm having to relearn stuff and you know how I like a challenge.

If you use #zfsbootmenu remember to update it or you won't be able to boot when you update your #zfs pool.

If you end up there put the binary efi recovery image from the projects website on a stick and boot from there - at least for me that worked like a charm ✨

Best experience I ever had with broken boot. Wow.

For my new Linux laptop home server setup ... I bounced between FreeBSD, Alpine, Debian with LUKS + ext4, and have finally settled in with Debian and Root-on-ZFS with native encryption (FreeBSD got me interested in ZFS) and using ZFSBootMenu as the bootloader.

I need to learn more about ZFS. I hear good things about @mwl 's ZFS books.

Updated my Debian ZFS install notes:

dwarmstrong.org/debian-install