HOWTO install Ubuntu 18.04 to a Whole Disk Native ZFS Root Filesystem using Ubiquity GUI installer
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.
- 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
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 your device names in the following commands. 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.
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, 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 install -y zfsutils # 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.
- Select 'Erase disk and install Ubuntu' and click 'Continue'.
- Change the 'Select drive:' dropdown to '/dev/zd0 - 10.7 GB Unknown' and click 'Install Now'.
- A popup summarizes your choices and asks 'Write the changes to disks?". Click 'Continue'.
- At this point continue through the installer normally.
- Finally, a message comes up 'Installation Complete'. Click the 'Continue Testing'.
Copy your Ubuntu image to the ZFS filesystem
In 18.04, Ubiquity does not unmount the ZVOL after it completes because it also uses it for swap space. We'll take advantage of this and 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 entries 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 220.127.116.11" | 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 a 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), turn off swapfile (holds the /target mountpoint open), unmount the zvol, 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 # swapoff -a # umount /target # zpool export alexandria # shutdown -r 0
Congratulations, you should have successfully booted Ubuntu 18.04 using ZFS as a root filesystem. Sometimes the system hangs at the Ubuntu logo screen on first boot, but it boots the second time. 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