Skip to content

Instantly share code, notes, and snippets.

@vadimstasiev
Last active January 2, 2024 18:10
Show Gist options
  • Save vadimstasiev/cdf01788fc840d6b1bf6ea4bf3e167a4 to your computer and use it in GitHub Desktop.
Save vadimstasiev/cdf01788fc840d6b1bf6ea4bf3e167a4 to your computer and use it in GitHub Desktop.
ZFS Recovery Cheatsheet

Recovering your system using a ZFS snapshot involves rolling back to the state of the system when the snapshot was taken. This process can vary depending on what exactly has "fucked up" in your system. Here's a general guide on how to recover:

  1. Accessing the System: If your system is still bootable, log in as usual. If it's not bootable, you might need to boot from a live CD/USB that supports ZFS. If using a live environment, you may need to manually import your ZFS pool with zpool import.
  2. Identifying the Snapshot: List available snapshots with zfs list -t snapshot. Find the snapshot you want to roll back to. It will be named something like rpool@snapshot1 if you followed standard naming conventions.
  3. Rolling Back to the Snapshot: Use the zfs rollback command. Be aware that this will destroy all data written to the pool after the snapshot was taken. The command is zfs rollback rpool@snapshot1. If you have datasets that depend on newer snapshots, you cannot roll back to an older snapshot. In that case, you might need to clone the snapshot and boot from the clone.
  4. Booting from a Snapshot (if needed): If your system is non-bootable and you need to use a snapshot: Clone the snapshot: zfs clone rpool@snapshot1 rpool/ROOT/cloned. Set the cloned filesystem to be bootable: zpool set bootfs=rpool/ROOT/cloned rpool. Reboot the system.
  5. Verifying the System: After rollback or booting from a clone, check that the system is in the desired state. You may need to reinstall or reconfigure software that was added after the snapshot was taken.
  6. Additional Steps: If the rollback solved the issue, great! If not, you might have to try a different snapshot or investigate other recovery methods. If you booted from a clone and everything works fine, you might want to consider making this clone your new primary dataset. Precautions and Tips: Always have backups: Snapshots are great, but they are not substitutes for backups. Always have off-site or external backups for critical data. Document your system configuration: This can be invaluable in recovery scenarios. Practice recovery: It's a good idea to practice this process in a non-critical environment to ensure you're prepared. Remember, the exact steps may vary depending on your system configuration, the nature of the problem, and how your ZFS pool and datasets are set up. It's always a good idea to consult the ZFS documentation and Proxmox guides for specific scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment