VM Snapshots
VM snapshots capture the complete state of a virtual machine at a point in time: disk contents, memory state, and CPU registers. This makes them ideal for before-and-after testing: take a snapshot, make a change, test it, then either commit or revert. Snapshots in KVM/libvirt are stored as QCOW2 backing chain entries — each snapshot records only what changes relative to the previous state, making them space-efficient.
Snapshot types in KVM
| Type | VM state | Memory included | Use case |
|---|---|---|---|
| Internal (QCOW2) | Can be running or stopped | Optional | Pre-change backup, test rollback |
| External disk | Running | No | Live backup without downtime |
| Disk + memory | Running | Yes | Full checkpoint, resume exactly |
Creating snapshots
# Create a snapshot of a running VM (disk state only):
virsh snapshot-create-as ubuntu-test --name "pre-upgrade-$(date +%Y%m%d)" --description "Before apt upgrade"
# Create snapshot including memory state (freezes VM briefly):
virsh snapshot-create-as ubuntu-test --name "pre-upgrade-with-mem" --memspec snapshot=external --atomic
# List all snapshots for a VM:
virsh snapshot-list ubuntu-test
virsh snapshot-list output
Name Creation Time State
------------------------------------------------------------
pre-upgrade-20250609 2025-06-09 14:30:00 +0000 running
post-install 2025-06-09 15:00:00 +0000 shutoff
# Show snapshot details:
virsh snapshot-info ubuntu-test pre-upgrade-20250609
virsh snapshot-dumpxml ubuntu-test pre-upgrade-20250609
Reverting and deleting
# Revert VM to a snapshot (rolls back all changes since snapshot):
virsh snapshot-revert ubuntu-test pre-upgrade-20250609
⚠️ WARNING: Reverting a snapshot is destructive — all changes made after the snapshot was taken are permanently lost. Verify you have the right snapshot name before reverting. If the VM is running, it will be stopped and reset to the snapshot state.
# Delete a snapshot (removes snapshot but keeps the VM):
virsh snapshot-delete ubuntu-test pre-upgrade-20250609
# Delete all snapshots for a VM:
for snap in $(virsh snapshot-list ubuntu-test --name); do
virsh snapshot-delete ubuntu-test $snap
done
Conclusion
VM snapshots are most useful for risky operations on test environments: database migrations, major package upgrades, or configuration changes where you want an instant rollback. For production VMs, prefer backup-based recovery (disk image copy + database dump) over snapshots — a snapshot chain that grows large can significantly slow VM I/O as QCOW2 must traverse the backing chain for every read. Delete snapshots after you've confirmed the operation succeeded.
FAQ
Is VM Snapshots important for Ubuntu administrators?+
Yes. It supports practical Ubuntu administration because it connects directly to server reliability, security, troubleshooting, or daily operations.
Should I practice this on a live server?+
Use a lab VM first. After you understand the command output and rollback path, apply the workflow carefully on real systems.
What should I do after reading this article?+
Run the practice commands, write down what each one shows, and continue to the next article in the Ubuntu roadmap.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support