Date

In my case, the motherboard battery had also died and so I needed to install a new battery and reset the bios to boot in EFI mode

Ubuntu ZFS Recovery Guide

Consolidated from a successful recovery session following a CMOS battery failure.

This guide outlines the exact process used to recover an Ubuntu system with a ZFS layout (bpool for /boot and rpool for /) after a motherboard battery failure wiped the BIOS settings and corrupted the boot configuration flags.


Prerequisites & Hardware Fixes

Before repairing the software, the underlying hardware clock and motherboard configurations must be stabilized to ensure the settings stick permanently.

  1. Replace the CMOS Battery: Install a new CR2032 battery on the motherboard.
  2. Set the Hardware Clock: Enter the BIOS, update the system date, and correct the time.
  3. Configure Storage Mode: Ensure the SATA/Storage mode is explicitly set to AHCI (do not leave it on RAID or Intel RST).
  4. Configure Boot Mode: Set the motherboard to boot exclusively in UEFI Mode (Disable CSM / Legacy boot configuration options).

Phase 1: Boot the Live USB in UEFI Mode

  1. Insert an Ubuntu Live USB matching your installed system version as closely as possible.
  2. Open your motherboard's boot selection menu (usually F12, F11, F8, or F2).
  3. Select the option that explicitly begins with UEFI: next to your flash drive's name.
  4. Choose "Try Ubuntu" and launch a terminal.

Phase 2: Install ZFS Tools & Force Import Pools

Because the machine suffered an ungraceful power loss from the dead battery, the ZFS datasets must be forcefully imported to clear lingering "dirty" flags.

  1. Gain root privileges: bash sudo -i
  2. Install the ZFS utilities into your Live environment: bash apt update && apt install -y zfsutils-linux
  3. Force import the root pool (rpool) onto the alternate mount path: bash zpool import -f -R /mnt rpool (Note: If using native ZFS encryption, add the -l flag: zpool import -f -l -R /mnt rpool and type your passphrase).
  4. Force import the boot pool (bpool): bash zpool import -f -R /mnt bpool

Phase 3: Mount Your EFI Partition & System Trees

Note: During recovery, the Live USB may register as /dev/sda, shifting your primary operating system drive to /dev/sdb.

  1. Mount your actual system EFI partition (which is partition 1 on your true OS drive, e.g., /dev/sdb1): bash mount /dev/sdb1 /mnt/boot/efi
  2. Bridge the critical virtual filesystems and API links from the Live environment into your target path: bash mount --bind /dev /mnt/dev mount --bind /proc /mnt/proc mount --bind /sys /mnt/sys mount --bind /sys/firmware/efi/efivars /mnt/sys/firmware/efi/efivars
  3. Chroot straight into your native Ubuntu operating system environment: bash chroot /mnt

Phase 4: Rebuild the Bootloader

Now that you are safely executing commands inside your own system, synchronize your modules and rewrite the EFI boot registers.

  1. Re-generate and update your kernel modules and ZFS drivers: bash update-initramfs -u -k all
  2. Reinstall GRUB directly to the EFI directory to re-register Ubuntu with your newly-reset motherboard NVRAM: bash grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=ubuntu --recheck
  3. Refresh the GRUB bootloader configuration menu: bash update-grub

Phase 5: Clean Exit & Safe Unmounting

To prevent dataset errors or stuck locks on the next hardware boot, you must break background system hooks cleanly.

  1. Exit the chroot session: bash exit
  2. Force-unmount stuck hooks or busy errors on the boot structures using a lazy unmount: bash umount -l /mnt/boot
  3. Unmount remaining system elements and the EFI path: bash umount /mnt/sys/firmware/efi/efivars umount /mnt/sys /mnt/proc /mnt/dev umount /mnt/boot/efi
  4. Export both ZFS pools to cleanly close their file access flags: bash zpool export -f bpool zpool export -f rpool
  5. Restart your machine and remove the flash drive: bash reboot