Skip to content

HOWTO install Ubuntu 18.04 to a Whole Disk Native ZFS Root Filesystem using Ubiquity GUI installer

Garrett Fields edited this page May 4, 2018 · 6 revisions

Currently, the Ubiquity installer in 18.04 does not support the ZFS filesystem, nor does the LiveCD environment have zfs tools preinstalled. This WIKI explains how to make the LiveCD environment ZFS capable, how to install Ubuntu to a ZFS zvol formatted as ext4, then concludes as if you are migrating an existing installation to ZFS. This method is unique to other methods because it utilizes ZFS whole disk formatting and does not require multiple hard drives. It is designed to be a guide showing the minimum effort needed to have a system JUST WORK.

System Requirements

  • 64-bit Ubuntu 18.04 full desktop install media (not server, netboot, or alternative)
  • 16Gb+ drive that is or can be completely wiped
  • Internet connection usable by LiveCD
  • 4GB memory recommended

Strategy

The Ubiquity installer for 18.04 does not recognize the ZFS filesystem as a usable target, however it can be installed to a ZFS Zvol then manually copied to the ZFS filesystem.

It is best practice, to use devices found in "/dev/disk/by-id/", not "/dev/" when creating pools. Some prefer to use "wwn-" devices listed in this directory, however not all devices have these identifiers. Please inventory what you have in your system and use the proper device names as you go along. In the examples below, we'll use a single disk "/dev/disk/by-id/ata-ST9999999999_10000000". Additionally, the ZFS pool name in this guide is "alexandria", however feel free to use any name you wish.

The Process

Install ZFS packages to the install environment

Initially, Ubuntu 18.04 LiveCD media is not ZFS aware. As you start the media, Select "Try Ubuntu", then open the terminal. First activate Ubuntu's "universe" repository, then install the zfs tools. Then, create a pool and a ZVOL within that pool. The example below is a single disk pool. Feel free to create mirror(s) or raidz(x) configurations if you wish. Doing so is beyond the scope of this wiki. The ZVOL is a block device that can be used just as a physical drive. Finally, we execute the Ubiquity installer.

Open Terminal (Ctrl+Alt+T)
$ sudo su
# apt-add-repository universe
# apt update
# apt install -y zfs-initramfs
# zpool create -f -o ashift=12 -O atime=off -O compression=lz4 -O normalization=formD -O recordsize=1M -O xattr=sa alexandria /dev/disk/by-id/ata-ST9999999999_10000000
# zfs create -V 10G alexandria/ubuntu-temp
# ubiquity --no-bootloader

Configuring the Ubiquity Installer

Choose any options you wish until you get to the "Installation Type" screen and select "Something Else"

Listed in the drive section, you will see "/dev/zd0". Select it and choose "New Partition Table...". "Continue" through the "Create new empty partition table on this device?" message. Then, Select /dev/zd0 Free Space and press the "+" button. Select "Use As: Ext4 journaling file system" and "Mount point: /", then click "OK" Click "Install Now" Acknowledge "Write the changes to disks?" dialog by clicking "Continue"

Additional screens will come up such as language, timezone, user account creation, and computer name. Complete these with your information. At the end of the install select "Continue testing"

Copy your Ubuntu image to the ZFS filesystem

In 18.04, Ubiquity does not unmount the ZVOL after it completes, so we will continue to use its mountpoint "/target". We need to create your ZFS OS filesystem, then rsync your Ubuntu install from the ZVOL to the ZFS OS filesystem. This example shows how to contain all contents of your system in a single filesystem. If you wish to have additional filesystems, for example /home or /var, you can create them and set their mountpoints before the rsync, but this is beyond the scope of this wiki.

Continuing in the terminal:

# zfs create alexandria/ROOT
# zfs create alexandria/ROOT/ubuntu-1
# rsync -avPX /target/. /alexandria/ROOT/ubuntu-1/.

Prepare your ZFS filesystem copy of Ubuntu to be ZFS aware

Your ZFS filesystem needs to have ZFS support added so it can understand itself after reboot. We connect the active /proc, /dev, and /sys mounts to the ZFS filesystem copy and chroot into it. We give it a nameserver, update the repositories, and install zfs binaries. Next, we remove the root filesystem and /swapfile from fstab. ZFS does this mounting for us and the swapfile does not work on a filesystem that "appears to have holes." If you wish to have swap, you can create a ZVOL for swap and reference that in the fstab, however that is beyond the scope of this wiki. Finally, we remove the unused "/swapfile".

# for d in proc sys dev; do mount --bind /$d /alexandria/ROOT/ubuntu-1/$d; done
# chroot /alexandria/ROOT/ubuntu-1
# echo "nameserver 8.8.8.8" | tee -a /etc/resolv.conf
# apt update
# apt install -y zfs-initramfs
# nano /etc/fstab         ## comment out the lines for the mountpoint "/" and "/swapfile" and exit
# rm /swapfile

Create a BIOS Grub partition and install Grub

ZFS whole disk formatting uses GPT partitioning. In order to boot a GPT disk, you need to EFI boot with an EFI partition present, or legacy (MBR) boot with a GRUB BIOS partition present. The structure automatically created by ZFS whole disk formatting will only allow for the latter to be done. In this section, we create a tiny GRUB BIOS partition in an unused section at the beginning of the drive, then update and install grub to the disk. If you created a multi-disk pool, this should be repeat the "sgdisk" commands for all the disks in the pool, then "update-grub", followed by "grub-install" against all your disks, so they are all capable of being the boot drive.

# sgdisk -a1 -n2:512:2047 -t2:EF02 /dev/disk/by-id/ata-ST9999999999_10000000
# update-grub
# grub-install /dev/disk/by-id/ata-ST9999999999_10000000

Set Mountpoint and reboot

We now exit the chroot, unmount the /dev, /sys, and /proc from /alexandria/ROOT/ubuntu-1, as well as /alexandria/ROOT/ubuntu-1 itself. We set our ZFS filesystem's mountpoint variable to /, snapshot our filesystem (optional), unmount our Zvol, then export our pool, then finally reboot.

# exit
# umount -R /alexandria/ROOT/ubuntu-1
# zfs set mountpoint=/ alexandria/ROOT/ubuntu-1
# zfs snapshot alexandria/ROOT/ubuntu-1@pre-reboot
# umount /target   (This is not working, ignoring error is fine)
# zpool export alexandria   (This is not working, ignoring error is fine)
# shutdown -r 0

Finish installation

Congratulations, you should have successfully booted Ubuntu 18.04 using ZFS as a root filesystem. The remaining steps are all optional. We will do a post install snapshot, destroy the ZVOL used during the installation, and run ubuntu updates.

Open Terminal (Ctrl+Alt+T) 
$ sudo zfs snapshot alexandria/ROOT/ubuntu-1@post-reboot
$ sudo zfs destroy alexandria/ubuntu-temp
$ sudo apt update
$ sudo apt dist-upgrade -y
$ sudo zfs snapshot alexandria/ROOT/ubuntu-1@post-reboot-updates