ZFS ZFS: backup and restore of zroot (my way)

  • Thread starter Deleted member 67440
  • Start date
D

Deleted member 67440

Guest
I've seen a number of threads about zroot backup-restore, but no "step-by-step" guides for those who are not particularly experienced.
Personally I often use a dirty trick to get a very fast copy (resilvering a dummy mirror disk), but I try to put it as I usually do, maybe it is useful and someone can give better suggestions.
I apologize if there are 1000 other identical, and better, threads on the forum.

In my example I will have a single source disk with zroot, say da0, which I want to clone to another machine.
In my case I will use, to support the copy, a second disk da1.
Obviously you can use keys etc.
 
First: I use, instead of the BSD boot disk, this one
It's way smaller (<100MB), therefore easier to upload with sftp on ESXi server or whatever it is, plus it also has ssh server active.
Beware that the root password is mfsroot

The first step is get the backup, with the send of a snapshot.
Usually I prefer pigz (for compressing) and pv (monitoring)
In this example I take an entire da1 disk (!) for a mybak pool
Very quick, and very dirty.

It is actually possible to use ssh as well, but I don't use it often (internet backup and restore are generally very slow).
However, if anyone is interested I can put the relative guide

Code:
pkg install -y pv pigz
zpool create mybak da1
zfs snapshot -r zroot@mybackup
zfs send -R zroot@mybackup |pigz|pv >/mybak/c.zfs.gz
You can now export the mybak pool, destroy the mybackup snapshot etc.
Spring cleaning

Now, on the "destination", this example will erase the
da0 (!!! BE CAREFUL !!!),
making a small boot partition, a 16GB swap, and the rest for zfs.

Obviously if you have a more complex situation (gpart show) you will have to create it manually.
This is what (I believe) is the simplest working example for a standard-FreeBSD 12.2 installation
- boot from .ISO or stick -
Code:
gpart destroy -F da0
gpart create -s gpt da0
gpart add -a 4k -t freebsd-boot -s 512k -l boot da0
gpart add -a 4k -t freebsd-swap -s 16g -l swap0 da0
gpart add -a 4k -t freebsd-zfs -l zfs0 da0
Make the new disk bootable
Code:
gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0

And now a little trick with gnop
Code:
gnop create -S 4096 /dev/gpt/zfs0
zpool create -f -o altroot=/mnt -O canmount=off -m none zroot /dev/gpt/zfs0.nop

OK, now get the restore.
In my quick-and-dirty from "something" (the mybak pool), decompressed by gzcat

Code:
zpool import -o altroot=/mnt -f mybak
gzcat /mnt/mybak/c.zfs.gz | zfs receive -vF zroot
shutdown -r now
The last shutdown it saved me a lot of trouble over time. You could probably bypass it too, but in the end I threw in the towel and just do it.

Now fix the boot (maybe!)
- boot from .ISO or stick -

Code:
zpool import -o altroot=/mnt -f zroot
zpool set bootfs=zroot/ROOT/default zroot
shutdown -r now

The system should boot with the zpool restored from
the hard disk.

Finally the cleaning (detach mybak and so on)
 
Back
Top