How to install ZFS in Debian 12

The procedure is as follows:

  1. Open your terminal application.
  2. For remote server login using the ssh command:
    ssh user@debian-12-server
  3. Add or enable contrib repo to /etc/apt/sources.list using sed command:
    sed -r -i'.BAK' 's/^deb(.*)$/deb\1 contrib/g' /etc/apt/sources.list
    Here is how it looks when contrib is appended to each line:deb http://deb.debian.org/debian bookworm main non-free non-free-firmware contrib deb http://deb.debian.org/debian bookworm-updates main non-free non-free-firmware contrib deb http://deb.debian.org/debian-security/ bookworm-security main non-free non-free-firmware contrib
  4. Update apt repo database, type:
    apt update
  5. NOTE: If you have recently installed a new Linux kernel update on Debian 12, you must reboot your machine or virtual machine. Failure to do so may result in compilation errors by the zfs-dkms package, as the command will try to use header files from the newly installed Linux kernel and fail.Install zfs package on a Debian Linux 12:
    apt install linux-headers-amd64 zfsutils-linux zfs-dkms zfs-zed
    Are you using a cloud server with cloud Linux kernel? Try:
    apt install linux-headers-cloud-amd64 zfsutils-linux zfs-dkms zfs-zed
  6. Test it by running zfs version command:
    modprobe zfs #<--load the module
    zfs version

    Outputs:zfs-2.1.11-1 zfs-kmod-2.1.11-1