You can automate snapshotting and rolling back of the root dataset during the boot process using these kernel command line flags:
Snapshotting (bootfs.snapshot)
Enables zfs-snapshot-bootfs.service. This creates a snapshot of the root dataset after the pool is imported but before the rootfs is mounted.
- Usage:
bootfs.snapshot or bootfs.snapshot=snapshot-name. - Snapshot Name: If no name is provided, it uses
$root_dataset@$(uname -r). - Behavior: If snapshot creation fails, the error is noted, but the system continues to boot.
Rolling back (bootfs.rollback)
Enables zfs-rollback-bootfs.service. This performs a zfs rollback -Rf on the root dataset after pool import but before the rootfs is mounted.
- Usage:
bootfs.rollback or bootfs.rollback=snapshot-name. - Snapshot Name: If no name is provided, it uses
$root_dataset@$(uname -r). - Behavior: If the rollback fails, the system drops to a rescue shell.
- Warning: This can cause data loss. Ensure persistent data is not located below the rootfs and that you do not require intermediate snapshots.
Ordering: If both flags are provided, bootfs.rollback is executed after bootfs.snapshot.