Skip to content

Debian ZFS Debootstrap Installation

Aaron S edited this page Sep 27, 2022 · 4 revisions

Installing Debian from Debootstrap for a ZFS Root System

Initially: Aug. 23, 2022 Latest update: Aug. 23, 2022

Set up the disks

  • Go into root user.
    sudo su -

  • Update apt, add contrib to apt.list, add backports to apt.list. Using the list from the Debian wiki is recommended. Make sure you add backports, as discussed below.
    apt update
    vi /etc/apt/sources.list

  • Add contrib and non-free to all the existing lines, then add a new line: “deb http://deb.debian.org/debian bullseye-backports main contrib non-free”

  • Update apt again. apt update

  • Install ZFS from backports sudo apt install -t bullseye-backports zfsutils-linux zfs-dkms
    systemctl start zfs-zed.service
    modprobe zfs

  • Find your partitions with lsblk and blkid

  • Go into each with fdisk /dev/sdX. (We will use sda for the remainder of the breakdown)

  • Create three partitions:

  • A 512M partition with the EFI label.

  • A 1G partition with a Linux Filesystem label.

  • A 32G (or whatever you feel size it should be) swap partition with the Linux swap label (19).

  • A third partition taking up the remaining space with a Linux label.

  • Write the disk with w.

  • Make the file systems for swap, boot and efi.
    mkfs.vfat /dev/sda1
    mkfs.ext4 /dev/sda2
    mkswap /dev/sda3

  • Make your zpool from your fourth partition. This is a basic zpool setup here, but feel free to update and increase complexity. Find your partuuid from blkid, then use that to create.
    zpool create -O compression=lz4 zroot PARTUUID
    zfs create zroot/ROOT
    zfs create zroot/ROOT/debian

  • Make your boot folders and mount them.
    mkdir /zroot/ROOT/debian/boot
    mount /dev/sda2 /zroot/ROOT/debian/boot
    mkdir /zroot/ROOT/debian/boot/efi
    mount /dev/sda1 /zroot/ROOT/debian/boot/efi

Install the system

  • Install debootstrap
    apt install debootstrap
  • Run debootstrap (here, we’re assuming we’re installing Bullseye).
    debootstrap bullseye /zroot/ROOT/debian
  • Copy the apt sources list.
    cp /etc/apt/sources.list /zroot/ROOT/debian/etc/apt
  • Edit the apt sources list in /zroot/ROOT/debian/etc/apt/sources.list and make sure the backports, contrib and non-free are added appropriately. If you copied from the live CD, these should be done already.
  • If the list is too short because you’re on Debian or something, visit the list for Debian here.
  • Mount the pseudo-filesystems
    for dir in sys dev proc; do mount --rbind /$dir /zroot/ROOT/debian/$dir && mount --make-rslave /zroot/ROOT/debian/$dir ; done
    cp /etc/resolv.conf /zroot/ROOT/debian/etc/
  • Time to chroot.
    chroot /zroot/ROOT/debian /bin/bash

Getting the System Running

  • Update apt.
    apt update && apt upgrade
  • Install zfs and locales.
    apt install locales
    dpkg-reconfigure locales
  • Pick our region (en_US.UTF-8 UTF-8)
  • Set the root password.
    passwd
  • Two options here:
  1. Install the stable kernel and important software plus important microcode, then install zfs support.
    apt install sudo linux-image-amd64 console-setup linux-headers-amd64 ntp network-manager vim amd64-microcode
    apt install -t bullseye-backports zfsutils-linux zfs-dkms zfs-initramfs
  2. Install the backported kernel and zfs utilities first. This guarantees a later backported kernel is updated properly.
    apt install -t bullseye-backports linux-image-amd64 console-setup linux-headers-amd64 zfsutils-linux zfs-dkms zfs-initramfs
    apt install sudo ntp network-manager vim amd64-microcode
  • Set up fstab
    cp /proc/mounts /etc/fstab
  • Remove lines in /etc/fstab that refer to proc, sys, devtmpfs and pts.
  • Replace references to /dev/sdXX, /dev/nvmeXnYpZ, etc. with their respective UUID, which can be found by running blkid. Don't touch the line about zroot.
  • Example: UUID=ffe9419a-500c-9c49-816f-41aebf92b55e
  • Change the last number in each line to 1 for the / and 2 for the /boot/efi.
  • Change tmpfs folder to /tmp.
  • Set the hostname.
    vi /etc/hostname
  • Type the hostname you choose for the box. For this example, we’ll use and type:
    debstrap vi /etc/hosts
  • Change all reference to localhost to debstrap.
  • Set the timezone.
    dpkg-reconfigure tzdata

Installing Grub

  • Install grub via apt first.
    apt install grub-efi-amd64
  • Install grub now.
    grub-install /dev/sda
  • Enable networking on boot.
    systemctl enable NetworkManager
  • Enable ZFS zpool loading so you can boot. VERY IMPORTANT.
    zpool set cachefile=/etc/zfs/zpool.cache <pool>
    systemctl enable zfs-zed.service
    systemctl enable zfs-mount.service
    systemctl enable zfs.target
    echo zfs >> /etc/modules
  • Update initramfs
    update-initramfs -u
    update-grub

Wrapping Up

  • Exit chroot
    exit
  • Unmount the zpool
    umount -R /zroot/ROOT/debian
  • Set your mounts
    zfs set mountpoint=/ zroot/ROOT/debian
    zpool export zroot
  • That's it. Reboot into your new ZFS Debian system.
    shutdown -r now