ZFS Bare Metal Restore

FreeBSD with ZFS

This article documents the procedure to do a full bare metal restore of a FreeBSD ZFS system that has been backed up with ZFS send.

I use ZFS on most of my FreeBSD systems. ZFS is a rock solid volume manager/file system. It has a number of feature (if you are not using it, check it out). I backup my ZFS volumes using ZFS send onto a NFS server.  This allows my an easy way to restore the system back in case of a full failure.  

This example assumes the original system was a ZFS mirror and that we will be restoring it onto the same hardware (same disk size and layout).

Get ready to Restore.

Boot from the FreeBSD install disk and select live CD.  Login as root (no password is required)

# dhclient em0
# mount 172.31.14.169:/volume1/Backups /mnt

Create the partition tables

# gpart restore -F -l da0 < /mnt/VM-Template/da0-mirror-30gb.gpart
# gpart restore -F -l da1 < /mnt/VM-Template/da1-mirror-30gb.gpart

Install the boot code onto both drives (they are a mirror).

# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da1

Load the ZFS module

# kldload zfs

Create the ZSF pool that you will restore the data into.

# zpool create -o altroot=/mnt/mnt -O compress=lz4 -O atime=off -m none -f zroot mirror /dev/da0p3 /dev/da1p3
# zfs set mountpoint=/ zroot

Restore the data from the backup on the NFS server

# cat /mnt/VM-Template/freebsd-11-template.zfs.gz | gunzip | zfs receive -Fd zroot

Fix up some ZFS mountpoints and re-install bootcode.  NOTE: I am not sure why I need ot reinstal lthe boot code at this time but it doesn’t always work if you don’t.

# zfs set mountpoint=/zroot zroot
# zpool set bootfs=zroot/ROOT/default zroot
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0
# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da1

Reboot and remove the CD.  It should now boot off the new drives.

Leave a Comment

Your email address will not be published. Required fields are marked *