Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
create and mount a zvol for use with systemd-container
title author date
btrfs zvol for systemd-container

calculating volume

btrfs zvol for use with systemd-container

avoid weird bugs due to machinectl unsupported fs

Wanting to use systemd-container, but you're running zfs? Make sure /var/lib/machines has a supported filesystem mounted - xfs or btrfs. systemd-importd had known bug that was fixed where would not rename container image on pull and would fail as a result. See here and here

Although issue was resolved in systemd 249, issue persists with zfs as storage filesystem. Thankfully, with zvols one can mount a supported filesystem as a workaround.

You'll basically need to be root the whole time, so

$ su

If you don't have root account, (ie ubuntu disabled by default), you can

$ sudo su


$ sudo passwd root
<enter passwd 2x>, and
$ su

sudo -i might work, too (unconfirmed)

  • clear out /var/lib/machines:
# rm -rf /var/lib/machines after backup

Note: where ubuntu_UUID in dataset name, yours will be different. $ zfs list

  • make zvol:
# zfs create -v 100G -s -o volblocksize=1M -o compress=zstd rpool/ROOT/ubuntu_pd3ehl/var/lib/machines
  • create gpt partition structure:
# fdisk /dev/zvol/rpool/ROOT/ubuntu_pd3ehl/var/lib/machines
<keys> g, w <exits>
  • create partition - full size (in this case, 100G):
# fdisk /dev/zvol/rpool/ROOT/ubuntu_pd3ehl/var/lib/machines
n  <enter> <enter> <enter> w <exits>
  • mount against emptied /var/lib/machines folder:
# mount -t  /dev/zvol/rpool/ROOT/ubuntu_pd3ehl/var/lib/machines-part1 /var/lib/machines
  • create filesystem:
# mkfs.btrfs /dev/zvol/rpool/ROOT/ubuntu_pd3ehl/var/lib/machines-part1
  • add to /etc/fstab:
# echo '/dev/zvol/rpool/ROOT/ubuntu_pd3ehl/var/lib/machines-part1 /var/lib/machines btrfs space_cache=v2,noatime,compress=zstd 0 0' >> /etc/fstab

Note: sometimes adding zvols to fstab prevents boot, if you end up in recovery on reboot, enter password, edit /etc/fstab, comment out this line and exit . You'll do fine.

If you'd rather run a systemd unit to mount your zvol at boot, there's a walk-through here (as well as a slightly different take on how to set up the zvol):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment