Windows – Hyper V – Read Only VM

hyper-vvirtual-machineswindows

We have a couple of test VMs which we use to test software on. We would like to have a virtual machine revert back to a saved state everytime the VM restarts.

I believe virtualbox calls this feature "Read-Only Mode". I know I can manually revert to a snapshot each time however I would like to automate this process.

Does anyone have any ideas?

Thanks

Best Answer

Yes, you can make your reference .vhd read-only and attach a Differencing Disk:

Differencing - Differencing is a concept which involves a parent disk and a child disk. The parent disk contains a baseline hard disk image with the operating system and perhaps a range of applications and data installed. Once this baseline parent disk is configured, a differencing disk is assigned as a child. When the virtual machine to which the disk is assigned runs, any changes made the baseline parent image are actually stored on the child differencing disk, leaving the parent disk unaltered. Multiple child disks may be assigned to a parent disk allowing multiple virtual machines to share the same parent disk. Differencing disks may also be chained together. The changes contained in a differencing disk may be merged into the parent disk. Alternatively, a new virtual hard disk may be created containing the merger of the parent disk and the child disk, thereby leaving the parent disk unaltered. When creating a differencing disk, the parent disk will need to be specified. The size of the differencing disk increases as space is required. Differencing disks may also be compacted to free up unused space (see the section below entitled Modifying Existing Hyper-V Virtual Hard Disks).

Link.

This has a performance penalty though, like running off many parent snapshots, but it most probably will not be noticeable unless your server is very busy.

I cannot remember if you can set the VM to always start from the parent image, but I think you can. Someone must have made a PowerShell script to do it at worst.

Related Topic