Join WhatsApp
Join Now
Join Telegram
Join Now

Installing ZFS on Linux (ZoL): Running ZFS on Root for Ubuntu/Debian

By Noman Mohammad

Published on:

Your rating ?

ZFS on Root: What I Wished I Knew My First Round

I almost gave up on ZFS. Three years ago I lost an entire weekend trying to get it running as my main Ubuntu disk. Today? My laptop boots to ZFS in 8 seconds flat and my photos survived a coffee spill that fried the SSD controller. Here’s the exact path I now walk friends through.

Why I Picked ZFS (Even After the Headache)

Regular ext4 forgives nothing. One power cut at the wrong time and… poof, project gone. ZFS keeps every block checksum-checked. Think tidy housekeeper vs. the roommate who stuffs cables in drawers.

Another perk: snapshots. One keystroke gives me a save-point I can roll back to in 15 seconds. Installed a bad update? I type four words and the OS rewinds to yesterday. No external USB disk needed.

Before We Start – A 10-Minute Checklist

  • Two empty USB drives. One becomes the install stick, the other backs up anything you care about.
  • A cup of coffee. First install will take ~75 minutes once you know the steps.
  • An Ubuntu 22.04 or newer ISO. Anything older ships an ancient ZFS that hates UEFI.

Step 1 – Grab the Right Packages

Pop open a terminal on your live USB and run:

sudo apt update
sudo apt install zfsutils-linux -y

On Debian? Two extra lines:

sudo add-apt-repository contrib
sudo apt install zfs-dkms zfsutils-linux

Unwritten rule: If apt complains about missing kernel headers, reboot into a newer kernel. It saves you twenty forum dives later.

Step 2 – Partitioning the Disk (the Visual Way)

I used to fear gdisk. Then I discovered cgdisk. Way simpler.

Open it on the target disk (replace sda with yours):

cgdisk /dev/sda

Layout I stick to

  • 512 MiB EFI = ESP (type EF00, gets /boot/efi later)
  • 2,000 MiB swap (type 8200)
  • Everything left = ZFS root (type BF01)

Save and quit.

Step 3 – Build the Pool

I name mine zubuntu so I know who it belongs to:

sudo zpool create -o ashift=12 -o autotrim=on \
  -O compression=lz4 -O mountpoint=/mnt -O canmount=off \
  zubuntu /dev/sda3

Quick notes

  • ashift=12 tells ZFS your SSD uses 4-K sectors. If you’ve got cheap flash, this one line triples write speed.
  • autotrim=on is like defrag— except you never run it manually again.

Step 4 – Slice the Pool Into Datasets

Think of datasets as smart folders that you can snapshot independently.

sudo zfs create -o canmount=noauto -o mountpoint=/ zubuntu/root
sudo zfs mount zubuntu/root

sudo zfs create                           zubuntu/home
sudo zfs create -o mountpoint=/var        zubuntu/var
sudo zfs create -o mountpoint=/opt        zubuntu/opt

I keep /tmp off ZFS to dodge endless “tank full” warnings.

Step 5 – Stuff Ubuntu Into the Dataset

Standard procedure, minus all the scary flags forum posts throw around:

sudo debootstrap jammy /mnt http://archive.ubuntu.com/ubuntu/

(Swap “jammy” for “noble” if you want the newest long-term release in 2025.)

Step 6 – Chroot, the 90-Second Way

sudo cp /etc/resolv.conf /mnt/etc/
sudo mount --bind /dev /mnt/dev
sudo mount -t proc proc /mnt/proc
sudo mount -t sysfs sys /mnt/sys
sudo chroot /mnt /bin/bash

Step 7 – Install the Boring But Critical Bits

apt update
apt install -y linux-generic linux-headers-generic
apt install -y grub-efi-amd64 zfs-initramfs cryptsetup

Pro tweak: Edit /etc/default/grub and add on one line:

GRUB_PRELOAD_MODULES="part_gpt zfs"

Then run:

update-grub
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu

Finally, create the RAM disk:

update-initramfs -u -k all

Step 8 – Cross-Your-Fingers Moment

exit
sudo zpool export zubuntu
sudo reboot

If you see the Ubuntu logo, you’re golden. If GRUB drops you to rescue? Nine times out of ten it’s because the EFI partition wasn’t mounted when you ran grub-install. Reboot back to live USB and re-run just that command.

Day-One Tweaks That Make Life Easier

  • Autosnapshots: Install zfs-auto-snapshot; it takes hourly snapshots you can delete after a month.
  • LUKS e-mail alerts: If you encrypted the pool, smartd can mail you the second any disk hiccups.
  • Keep the last kernel: I pin two kernels inside the EFI partition. That way if an update breaks, I can reboot into yesterday’s code.

Cheat-Sheet URLs You’ll Actually Bookmark

My laptop has run Ubuntu on ZFS since early 2022 and survived two SSD replacements and one motherboard swap. The file system didn’t even notice. Give it a shot; worst case you’ll learn where Linux hides its start button.

Leave a Comment

Exit mobile version