ZFS Replicate the system pool from a snapshot sent to backup

I'd like to be able to recover from a scenario where / filesystem is corrupted. Like if I inadvertently delete some or all configuration files in /etc or the procedures in /boot for instance and may not be able to boot anymore.

What I've done so far in a VM to learn how to do that kind of recovery using ZFS and the snapshot feature

1. make a snapshot of zroot/ROOT/default which is mounted on /
Code:
zfs snapshot zroot/ROOT/default@snapshot1
2. send the snapshot and the associated dataset to another pool backup located on another drive's partition setup with ZFS.
Code:
zfs send zroot/ROOT/default@snapshot1 | zfs receive backup/zroot-default

In a live environment, where zroot would not be mounted on /
3. import zroot and mount it on /mnt
Code:
zpool import -R /mnt zroot
4. import backup
Code:
zpool import backup
5. send back the snapshot and the associated dataset from backup to zroot
Code:
zfs send backup/zroot-default@snapshot1 | zfs receive zroot/backuped-zroot
6. rename dataset coming from backup to zroot/ROOT/default to become the official one
6.a rename original dataset to whatever name in order to delete it later.
6.b remove mountpoint from original dataset
6.c set mountpoint to / to the new zroot/ROOT/default dataset

Code:
zfs rename zroot/ROOT/default zroot/old-default
zfs rename zroot/backuped-zroot zroot/ROOT/default
zfs set -u mountpoint=none zroot/old-default
zfs set -u mountpoint=/ zroot/ROOT/default #which was to none

After that, I rebooted the system but I'mt only able to boot in single-user mode. In multi-user mode, I get a message telling it can't start devd or find the swap (I think).

Code:
devd: Can't open devctl device /dev/devctl: No such file or directory
/etc/rc: WARNING: failed to start devd
Waiting 30s for the default route....
[...]
Updating /var/run/os-release done.
[...]
dmounting late filestystems:.
swapon: /dev/gpt/swapfs: No such file or directy
....
Wed Jan 8 ...

And then I'm left in a state where I got a solid cursor but can't do anything.

In single user mode however, I'm able to boot, to login and to make change to zroot

What am I missing?
 
I see a few things that are not correct, but start by doing incremental snapshots of your pool, and therefore your commit has to be as well. You are only exporting the root, but if you have the default schema, you are leaving out /tmp, /usr etc...

zfs snap -r zroot@snapshot1

What you are doing is correct, if you only want to query the root data, but not to build a new pool.
 
I'd like to be able to recover from a scenario where / filesystem is corrupted. Like if I inadvertently delete some or all configuration files in /etc or the procedures in /boot for instance and may not be able to boot anymore.

What you want to achieve is best done with ZFS boot environments. They are a very useful feature and you should learn about them.

After that, I rebooted the system but I'mt only able to boot in single-user mode. In multi-user mode, I get a message telling it can't start devd or find the swap (I think).

Code:
devd: Can't open devctl device /dev/devctl: No such file or directory
/etc/rc: WARNING: failed to start devd
Waiting 30s for the default route....
[...]
Updating /var/run/os-release done.
[...]
dmounting late filestystems:.
swapon: /dev/gpt/swapfs: No such file or directy
....
Wed Jan 8 ...
The error messages suggest that the /dev filesystem is not mounted.

One important aspect of booting from ZFS is the bootfs zpool property. You should read about it.The name of the filesystem from which you are booting doesn't have to be zpool/ROOT/default. It can be any name as long as the bootfs property specifies the name.
 
JordanG said:
What you want to achieve is best done with ZFS boot environments. They are a very useful feature and you should learn about them.

Thanks for pointing that out!

JordanG said:
It can be any name as long as the bootfs property specifies the name.

Very clear thank you. I'll do my research.
 
Back
Top