mastodon.xyz is one of the many independent Mastodon servers you can use to participate in the fediverse.
A Mastodon instance, open to everyone, but mainly English and French speaking.

Administered by:

Server stats:

739
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 to ahoyboyhoy

@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.

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

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

Replied in thread
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

Replied in thread

@samurro @stefano I could be wrong, but ZFS support is no longer a unique feature of BSD. OpenZFS is now a shared codebase and many Linux distros package it. Paired with #zfsbootmenu, it's a fantastic experience. I run zbm (root on zfs) with both a laptop and desktop. I also run a raidz pool on the desktop that replicates to an offsite pool attached to a raspberry pi. Aside from the USB enclosures I've connected to the pi, it's been very stable for years.

I am beyond exhausted this weekend. I had been sick the week before, and this was the first one pushing for a "back to business" rhythm. Yeah, that can be draining.

I'll try and lay low for the weekend and treat myself experimenting with a demo root-on-zfs installation of Void with ZFSBootMenu on an external drive just to practice and take notes because it seems that will be my laptop's new OS for now. I've been pretty happy with it.

I'd really like to run either FreeBSD or NetBSD on this machine, but sadly the hardware is not a match, either sound or suspend or touchpad scrolling being flaky.

On related news, I think I'll eventually get a kvm so that I can start using my current "server" as a desktop machine too, since a full set of screen/mouse/keyboard is already right there next to it, being useful only when I plug the laptop to them.

That way I can see about having a BSD machine ready to go besides this portable machine I carry around.