Skip to content

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

Garrett Fields edited this page Apr 25, 2017 · 1 revision

Currently, the Ubiquity installer in 17.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.

System Requirements

  • 64-bit Ubuntu 17.04 boot/install CD/USB/DVD, full desktop installer (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 17.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".

The Process

Install ZFS packages to the install environment

Initially, Ubuntu 17.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 or raidz(x) configurations if you wish. Doing so is beyond the scope of this wiki. Following the pool creation, we create 10G zvol within the pool. This creates 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 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 17.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 filesystem, then rsync your Ubuntu install from the ZVOL to the zfs filesystem. This example shows how to make a single filesystem for your system. If you wish to have additional filesystems, for example /home or /var, you can create them also before the rsync. Creation and setting mountpoints are 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. Finally, we remove the root filesystem from fstab, since zfs does this mounting for us.

# 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 line for mountpoint "/"

Create a BIOS Grub partion 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 boot with a GRUB BIOS partition present. The structure 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 17.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-get dist-upgrade -y
$ sudo zfs snapshot alexandria/ROOT/ubuntu-1@post-reboot-updates