I'm using Hyper-V without System Center and trying to create "templates" for linux servers that I can then reuse as base installs. The way we have done it is by creating a machine, let's call it "Template_CentOS7", we run install set up what we need etc. Then I shutdown the machine and copy the vhdx file to our template directory. D:\Templates\Template_CentOS7.vhdx
When I need a new instance for a machine Machine_XXX
, I do the following:
- Copy the template to a new directory, ie
D:\Hyper-V\Machine_XXX\Virtual Hard Disks\Template_CentOS.vhdx
- Rename the file
Machine_XXX.vhdx
- Run Hyper-V Manager to create the new machine via, New->Virtual Machine.
- When prompted to create a new drive, I point it to the the new file.
Now here is the question, we've now made some changes to the base template, and we run a Checkpoint after the change. Now I shut down the Template_CentOS7
machine so I can copy the vhdx file into our templates directory, but now there are several files, Template_CentOS7.vhdx, and a bunch of Template_CentOS7GUID.avhdx files. I'm not sure what I should do next. The Template_CentOS7.vhdx file has a fairly old modify time, so I don't think it includes the changes I've made.
What do I need to do to use this new "template"?
The answer depends on what you mean by "use this new template." There are two possible interpretations:
The answer to the first question is that you need to merge the last .avhdx file from the VM where you applied the changes into a new template .vhdx. I'd suggest the merge-vhd PowerShell cmdlet for that, using the -DestinationPath parameter to specify a new template VHDX.
The answer to the second question is that you can't. Virtual disk snapshots aren't file system snapshots. Since file system structures are also in the snapshots, any changes to a parent VHD represent file system corruption.
If you want to merge the snapshots and retain the snapshot tree, one way to do it would be to export the virtual machine, delete the snapshot subtree, and then import the exported virtual machine as a new virtual machine. Now the original virtual machine will have all of the snapshots merged into the parent VHD(X) and the exported/imported virtual machine will retain all of the snapshots of the original virtual machine.