CentOS8 on ZFS is not an easy one also not a pretty one as there is no simple direct route for it. You’ll need to have a CentOS8 default install + the zfs bits on a disk which we will later on copy the files from to our zfs filesystems.
You can now attach a second disk to your machine (/dev/vda in my case) which we’ll setup to be used for zfs.
parted /dev/vda –script mklabel msdos
parted -s -a optimal /dev/vda mkpart primary 1M 1024M
parted -s /dev/vda name 1 boot
parted -s /dev/vda set 1 BOOT on
parted -s -a optimal /dev/vda mkpart primary 1024M 3072M
parted -s /dev/vda name 2 swap
parted -s -a optimal /dev/vda mkpart primary 3072M — -1M
parted -s /dev/vda name 3 root
Now we get the zpool and the zfs mountpoints sorted
zpool create -d -o feature@async_destroy=enabled -o feature@empty_bpobj=enabled -o feature@lz4_compress=enabled -o ashift=9 -O atime=off -O canmount=off -O mountpoint=/ -R /media -O compression=lz4 zroot /dev/vda3
zfs create -o canmount=off -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ zroot/zroot/centos
zfs create -o setuid=off zroot/home
zfs create -o mountpoint=/root zroot/home/root
zfs create -o canmount=off -o setuid=off -o exec=off zroot/var
zfs create zroot/var/cache
zfs create zroot/var/log
zfs create zroot/var/spool
zfs create -o exec=on zroot/var/tmp
zfs create zroot/var/mail
zfs mount -a
chmod 1777 /mnt/centos/var/tmp
This is where we bind mount our running OS so that we can copy the relevant files. Folder /mnt will be folder where we copy from (original fs) and folder /media will be where we have mounted the zfs filesystems (-R /media when mounting the zfs filesystems)
mount –bind / /mnt/
rsync -avPX /mnt/ /media/
Next two steps only if you have /boot and /home on a different partition
rsync -avPX /boot/. /media/boot/
rsync -avPX /home/. /media/home/.
umount /mnt/tmp/
Prepping to chroot
mount –rbind /dev /media/dev/
mount –rbind /sys /media/sys/
mount –rbind /proc /media/proc/
chroot /media
vi /etc/fstab
GRUB_CMDLINE_LINUX=”nofb splash=quiet crashkernel=auto rhgb quiet boot=zfs rpool=zroot bootfs=zroot/ROOT/centos”
GRUB_PRELOAD_MODULES=”part_msdos zfs”
pushd /dev
ln -s /dev/disk/by-path/* . # Use right directory for your zpool device names
popd
grub2-mkconfig -o /boot/grub2/grub.cfg
systemctl enable zfs-mount.service
/etc/dracut.conf
add_dracutmodules+=”zfs”
This should regen the initramfs with the zfs bits
dracut -f -v /boot/initramfs-$(uname -r).img $(uname -r)
Might want to disable selinux initially then later on feel free to autorelabel and enable as it will work with zfs just as well as with the normal filesystems that come with C8.
One thing to remember is that every time you upgrade the kernel or zfs , you’ll need to make sure that the initramfs contains then relevant zfs bits AND on boot you might need to
zpool import -f zroot
otherwise the OS will not boot because zfs did not want to import the pool automatically … stupid … right ? 🙂
Enjoy! … oh and think twice before considering this as an option for your prod environment … ZFS is not supported officially by the CentOS8 ppl so you’re on your own!