Some notes for ZOL on ROOT

Disk replacement

In case of hdd replacement needed, valid only for this install method:

First get the disk out of the pools:

zpool detach bpool ata-HGST_HUS726020ALE610_K5HRNGMA-part2
zpool detach rpool ata-HGST_HUS726020ALE610_K5HRNGMA-part3

At this point, provider will replace the HDD and boot into rescue.

Then recreate the partitions on the new disk:

wipefs --all --force "$selected_disk"
sgdisk -a1 -n1:24K:+1000K            -t1:EF02 "$selected_disk"
sgdisk -n2:0:+2G                   -t2:BF01 "$selected_disk" # Boot pool
sgdisk -n3:0:"$tail_space_parameter" -t3:BF01 "$selected_disk" # Root pool

Install ZFS on rescue:

echo "zfs-dkms zfs-dkms/note-incompatible-licenses note true" | debconf-set-selections
apt-get install --yes software-properties-common
apt-key adv --keyserver --recv-keys 8CF63AD3F06FC659
add-apt-repository 'deb focal main'
apt update
apt install --yes zfs-dkms zfsutils-linux
add-apt-repository -r 'deb focal main'
apt update
find /usr/local/sbin/ -type l -exec rm {} +
zfs --version

Import pools (can take a while):

zpool import -f -R /mnt rpool
zpool import -f -R /mnt bpool

Pools status:

zpool status

Reintegrate the disks to the pools in mirror, XX_XXX_XXX being the new disk:

zpool attach bpool ata-EXISTING_DISK_WITHDATAS-part2 ata-XXX_XXX_XXX-part2
zpool attach rpool ata-EXISTING_DISK_WITHDATAS-part3 ata-XXX_XXX_XXX-part3

Reinstall grub:

zfs mount rpool/ROOT/ubuntu
mount -t zfs bpool/BOOT/ubuntu /mnt/boot
for virtual_fs_dir in proc sys dev; do
  mount --rbind "/$virtual_fs_dir" "/mnt/$virtual_fs_dir"
chroot /mnt/
# in chroot:
grub-install /dev/sda
grub-install /dev/sdb

Export pools:

# unmount virtual fs dirs
for virtual_fs_dir in dev sys proc; do
    umount --recursive --force --lazy "/mnt/$virtual_fs_dir"
# umount boot and root
umount /mnt/boot
umount /mnt
# export pools (can take some time)
zpool export bpool
zpool export rpool
zpool export nvme
zpool export -a
# just be sure they are all exported, order might matter

After reboot, and server rebooted correctly:

Probably now wait until pools are resilvered:

zpool status