Getting Ubuntu 16.04 on a ZFS root on a Hetzner dedicated server

hetznerubuntu-16.04zfsonlinux

By now, it's well possible to get Ubuntu 16.04 running on a ZFS root-fs. Ubuntu 16.04 has ZFS in the default package manager, and with guides like this, it's not hard to get started.

However, all guides I've seen require being able to boot from a Ubuntu installation image. For a Hetzner dedicated server, this is an uncommon installation procedure, as it requires engineers to visit the server and plug-in a remote KVM.

By default, the dedicated servers boot into a rescue system, which allows to install a variety of Linux distributions through their 'installiamge' script. However, this script does not support ZFS yet.

How to get a Hetzner dedicated server running on a ZFS root?

Best Answer

The basic idea is to get Ubuntu installed on a small partition on the harddrive, partition the hard-drive to use the remainder of the space for ZFS, and then copy the installation over. I'm mainly using this guide on instructions how to do that.

Lazy, and experience with Ansible? I wrote a little stack of scripts to automate these steps. They are available on: https://github.com/tijszwinkels/hetzner-ubuntu-16.04-zfs-root-ansible/blob/master/hetzner-ubuntu-16.04.yml Be careful, these scripts assume that the host is booted into the Hetzner rescue system, and they will wipe your drives as a very first step. Use at your own risk!

# SSH into the host.

# Wipe the drives. Assuming SSDs on 'sda' and 'sdb'.
/sbin/blkdiscard /dev/sda
/sbin/blkdiscard /dev/sdb

# Install Ubuntu 16.04 on a 4G partition using the Hetzner 'installimage' script
/root/.oldroot/nfs/install/installimage -a -n my-hostname -r yes -l 1 -p /:ext4:4G -K /root/.ssh/robot_user_keys -i /root/.oldroot/nfs/install/../images/Ubuntu-1604-xenial-64-minimal.tar.gz

# Reboot the system.
/sbin/shutdown -r now

# Wait for the host to come back up, and SSH in.

# Install the 'parted' parition editor
apt-get update && apt-get install -y parted

# Run parted on the first drive, create a partition in all remaining space. (UNTESTED!)
sudo parted /dev/sda
(parted) mkpart primary 4097MB -1s
(parted) quit

# Run parted on the second drive, create a partition in all remaining space. (UNTESTED!)
sudo parted /dev/sdb
(parted) mkpart primary 4097MB -1s
(parted) quit

# Install required ZFS packages
apt-get install -y zfs-dkms zfs-initramfs

# Create a ZFS pool named 'tank'
# Please note that I'm using the /dev/disk/by-id interface. This is more resilient than /dev/sda and /dev/sdb
zpool create -f -o ashift=13 -O atime=off -O dedup=off -O compression=lz4  tank mirror `ls /dev/disk/by-id/ata-*-part2` 

# Create OS partiton
zfs create tank/os

# Rsync the current system to the new partition.
rsync -a --one-file-system / /tank/os/

# Chroot into the system
cd /tank/os
mount --bind /dev dev
mount --bind /proc proc
mount --bind /sys sys
mount --bind /run run
chroot .

# Install GRUB into the drives
export ZPOOL_VDEV_NAME_PATH=YES
update-grub
grub-install /dev/sda
grub-install /dev/sdb

Now, you should have a Hetzner dedicated server that happily boots into Ubuntu 16.04 with a ZFS root fs. Good luck!

Related Topic