Reinstalling Kubuntu 26.04 on Encrypted ZFS Root
Recently I wrote about installing Kubuntu on ZFS. However, what to do if you already have a working setup and you just want reinstall OS?
In my case, I want to preserve my ZFS pool. Additionally, I want to retain all my ZFS datasets, except for the dataset that holds my file system. And yes, system is a bit peculiar but it’s nothing too special.
As one would assume, procedure is quite similar to the original installation. In order to fully understand why certain steps are in, I would suggest reading the original post. If you have a different setup, steps will differ, but the gist of it will remain the same.
As before, we start with root terminal.
sudo -iStep to install the packages is also the same, as one would expect.
apt update
apt install -y gdisk zfsutils-linuxI setup the variables to help me to work.
DISK1=/dev/disk/by-id/<disk>
HOST=<host>
USERNAME=<user>Since we don’t want to repartition disk, we can immediately skip to the step of fetching partition UUIDs.
DISK1P1=`blkid -s PARTUUID -o value $DISK1-part1`
DISK1P2=`blkid -s PARTUUID -o value $DISK1-part2`
DISK1P3=`blkid -s PARTUUID -o value $DISK1-part3`
DISK1P4=`blkid -s PARTUUID -o value $DISK1-part4`As my setup is on top of LUKS, it is necessary to open the mapper.
cryptsetup luksOpen \
--persistent --allow-discards \
--perf-no_write_workqueue --perf-no_read_workqueue \
/dev/disk/by-partuuid/$DISK1P4 $DISK1P4And now we can import the pool. Note that we will load it at /mnt/install so that it will match the original setup.
zpool import -N -R /mnt/install -f ${HOST^}Now we can destroy our previous system. There is no coming back after this step.
zfs destroy ${HOST^}/SystemAlternatively, if you want to keep it for reference, you can just rename it.
zfs rename ${HOST^}/System ${HOST^}/System.Old
zfs set mountpoint=/oldsys ${HOST^}/System.OldWith this in place, we get to create a new system dataset.
zfs create \
-o devices=on \
-o canmount=noauto -o mountpoint=/ \
${HOST^}/System
zfs mount ${HOST^}/SystemImportantly, I also mount my home dataset so that my user stuff is there if I need it.
zfs mount ${HOST^}/HomeLastly, we clean boot and EFI partition.
dd if=/dev/zero of=/dev/disk/by-partuuid/$DISK1P1 bs=1M
dd if=/dev/zero of=/dev/disk/by-partuuid/$DISK1P2 bs=1MWith all this in place, you can simply continue with the original guide at the step of formatting boot partition (mkfs.ext4). And that’s it - your OS will be as new.