Ubuntu ZFS Root

From Mark Furneaux's Wiki
Jump to: navigation, search

Ubuntu and its derivatives do not support installing to a ZFS root filesystem as of 18.04. This guide serves as a workaround. This guide is for Ubuntu/Kubuntu Desktop 18.04. For 16.04 instructions, look at the page history.

Installation

  1. Boot a live USB
  2. Create a GPT partition table on the disk by running:
    sgdisk -o /dev/disk/by-id/ata-DISK
  3. Add the GRUB BIOS partition by running:
    sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/ata-DISK
  4. Use parted/sgdisk to create the rest of the partition table
  5. Run:
    apt update
    apt install zfsutils-linux
    zpool create -f -o ashift=12 -O compression=lz4 -O xattr=sa -O mountpoint=none rootpool /dev/disk/by-id/ata-DISK-partN
    zfs create -V 10G rootpool/tempdisk
    zfs create -o mountpoint=none rootpool/ROOT
    zfs create -o mountpoint=/ rootpool/ROOT/hostname
    zpool export rootpool
    zpool import rootpool -R /mnt
    zfs create rootpool/ROOT/hostname/boot
    zfs create rootpool/ROOT/hostname/etc
    zfs create rootpool/ROOT/hostname/home
    zfs create rootpool/ROOT/hostname/tmp
    zfs create rootpool/ROOT/hostname/usr
    zfs create rootpool/ROOT/hostname/var
    zpool set bootfs=rootpool/ROOT/hostname rootpool
    
  6. If installing Ubuntu, run the installer, selecting /dev/zd0 as the install drive with an ext4 partiton. The bootloader should be set for installation on /dev/zd0. The bootloader install will fail. Continue without a bootloader. Do not reboot once the install is finished.
  7. If installing Kubuntu, you will need a temporary disk. This can be a USB flash drive or old hard drive. Run the installer, selecting /dev/<temp disk> as the install drive with an ext4 partiton. The bootloader should be set for installation on /dev/<temp disk>. Do not reboot once the install is finished.
  8. On Ubuntu, run:
    mkdir /media/temp
    mount /dev/zd0p1 /media/temp
    rsync -aAXvH /media/temp/* /mnt --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
    
  9. On Kubuntu, run:
    rsync -aAXvH /target/* /mnt --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
    
  10. Run:
    for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
    chroot /mnt
    apt install zfs-initramfs
    grub-install /dev/disk/by-id/ata-DISK
    
  11. Remove any entries in /etc/fstab referencing the previous temporary root filesystem
  12. Add "boot=zfs" to /etc/default/grub in GRUB_CMDLINE_LINUX
  13. Run:
    update-grub
    exit
    for i in /dev/pts /dev /proc /sys /run; do umount /mnt$i; done
    
  14. On Ubuntu, run:
    umount /media/temp
    
  15. Run:
    zfs destroy rootpool/tempdisk
    zfs snapshot -r rootpool@factory
    zpool export rootpool
    
  16. Reboot