Difference between revisions of "Ubuntu ZFS Root"

From Mark Furneaux's Wiki
Jump to: navigation, search
 
Line 1: Line 1:
Ubuntu does not support installing to a ZFS root filesystem as of 16.04. This guide serves as a workaround.
+
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==
 
==Installation==
 
#Boot a live USB
 
#Boot a live USB
 +
#Create a GPT partition table on the disk by running:<br><code>sgdisk -o /dev/disk/by-id/ata-DISK</code>
 
#Add the GRUB BIOS partition by running:<br><code>sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/ata-DISK</code>
 
#Add the GRUB BIOS partition by running:<br><code>sgdisk -a1 -n2:34:2047 -t2:EF02 /dev/disk/by-id/ata-DISK</code>
#Use parted/gparted to create the rest of the partition table
+
#Use parted/sgdisk to create the rest of the partition table
 
#Run:
 
#Run:
 
#:<syntaxhighlight lang="bash">
 
#:<syntaxhighlight lang="bash">
Line 23: Line 24:
 
zpool set bootfs=rootpool/ROOT/hostname rootpool
 
zpool set bootfs=rootpool/ROOT/hostname rootpool
 
</syntaxhighlight>
 
</syntaxhighlight>
#Run the installer, selecting <code>/dev/zd0</code> as the install drive with an ext4 partiton. The bootloader should be set for installation on <code>/dev/zd0</code>. The bootloader install will fail. Continue without a bootloader. Do not reboot once the install is finished.
+
#If installing Ubuntu, run the installer, selecting <code>/dev/zd0</code> as the install drive with an ext4 partiton. The bootloader should be set for installation on <code>/dev/zd0</code>. The bootloader install will fail. Continue without a bootloader. Do not reboot once the install is finished.
#Run:
+
#If installing Kubuntu, you will need a temporary disk. This can be a USB flash drive or old hard drive. Run the installer, selecting <code>/dev/<temp disk></code> as the install drive with an ext4 partiton. The bootloader should be set for installation on <code>/dev/<temp disk></code>. Do not reboot once the install is finished.
 +
#On Ubuntu, run:
 
#:<syntaxhighlight lang="bash">
 
#:<syntaxhighlight lang="bash">
 
mkdir /media/temp
 
mkdir /media/temp
 
mount /dev/zd0p1 /media/temp
 
mount /dev/zd0p1 /media/temp
 
rsync -aAXvH /media/temp/* /mnt --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
 
rsync -aAXvH /media/temp/* /mnt --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
 +
</syntaxhighlight>
 +
#On Kubuntu, run:
 +
#:<syntaxhighlight lang="bash">
 +
rsync -aAXvH /target/* /mnt --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found}
 +
</syntaxhighlight>
 +
#Run:
 +
#:<syntaxhighlight lang="bash">
 
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
 
for i in /dev /dev/pts /proc /sys /run; do mount -B $i /mnt$i; done
 
chroot /mnt
 
chroot /mnt
 
apt install zfs-initramfs
 
apt install zfs-initramfs
ln -s /dev/disk/by-id/ata-DISK-partN /dev/ata-DISK-partN
 
 
grub-install /dev/disk/by-id/ata-DISK
 
grub-install /dev/disk/by-id/ata-DISK
 
</syntaxhighlight>
 
</syntaxhighlight>
 
#Remove any entries in <code>/etc/fstab</code> referencing the previous temporary root filesystem
 
#Remove any entries in <code>/etc/fstab</code> referencing the previous temporary root filesystem
 
#Add <code>"boot=zfs"</code> to <code>/etc/default/grub</code> in <code>GRUB_CMDLINE_LINUX</code>
 
#Add <code>"boot=zfs"</code> to <code>/etc/default/grub</code> in <code>GRUB_CMDLINE_LINUX</code>
#Install your custom kernel and ZFS modules at this point. It appears that the Ubuntu stock modules will not boot properly since the nested datasets aren't mounted fast enough. Add your custom repository and key, then do something along the lines of:
 
#:<syntaxhighlight lang="bash">
 
apt install linux-image-4.9* linux-headers-4.9* linux-firmware-image-4.9* kmod-spl-4.9* kmod-zfs-4.9* zfs zfs-initramfs
 
depmod -a
 
</syntaxhighlight>
 
#:You may need to run the apt command twice since it is in a chroot.
 
 
#Run:
 
#Run:
 
#:<syntaxhighlight lang="bash">
 
#:<syntaxhighlight lang="bash">
Line 48: Line 50:
 
exit
 
exit
 
for i in /dev/pts /dev /proc /sys /run; do umount /mnt$i; done
 
for i in /dev/pts /dev /proc /sys /run; do umount /mnt$i; done
 +
</syntaxhighlight>
 +
#On Ubuntu, run:
 +
#:<syntaxhighlight lang="bash">
 
umount /media/temp
 
umount /media/temp
 +
</syntaxhighlight>
 +
#Run:
 +
#:<syntaxhighlight lang="bash">
 
zfs destroy rootpool/tempdisk
 
zfs destroy rootpool/tempdisk
 
zfs snapshot -r rootpool@factory
 
zfs snapshot -r rootpool@factory
Line 54: Line 62:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
#Reboot
 
#Reboot
#Setup the apt mirror, run updates, etc. Note that everytime the bootloader is updated, the symlink in <code>/dev</code> will need to be created beforehand.
 
#Set zfs-auto-snapshot user parameters as appropriate:
 
#:<syntaxhighlight lang="bash">
 
zfs set com.sun:auto-snapshot=true rootpool
 
for i in daily weekly monthly frequent hourly; do zfs set com.sun:auto-snapshot:$i=true rootpool; done
 
apt install zfs-auto-snapshot
 
</syntaxhighlight>
 

Latest revision as of 08:49, 9 July 2018

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