Linux – Can KVM roll back changes to Virtual Disks automatically

kvm-virtualizationlinuxvirtualboxvirtualization

I'm currently using VirtualBox on my Linux server to run a small Windows guest OS. I've configured its main virtual hard drive as what VBox calls "Immutable" – meaning that any changes to it are written into a differencing image that is discarded when the system reboots.

Can KVM do something similar?

I've read about snapshots via "savevm", "loadvm" but I believe that's saved states, not differencing images.

What I ultimately want is a VM with two drives: one reverts on each reboot, one keeps its changes. Ideally, the unchangeable drive image should be stored with only read access granted to the user running KVM.

Best Answer

KVM does have this functionality through the use its supporting tools. The name of the tool is qemu-img and you can either create snapshots at will or you can specify at disk creation time that it should use a (different) backing disk which will not be altered by any changes you make (the changes will persist in the, let's call it the fronting disk, and you can merge them too).

It sounds as if you are trying to create something like an appliance, like a set-top box or a router. In that case you are making this perhaps too complicated. Simply make your boot disk immutable (mount it read-only) and have all the mutable data on the second disk. It's done all the time. Indeed, some machines I've seen booted off a CD but still had hard disks to store data. No need for COW disks. Or maybe not.