1

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:

  1. Copy the template to a new directory, ie D:\Hyper-V\Machine_XXX\Virtual Hard Disks\Template_CentOS.vhdx
  2. Rename the file Machine_XXX.vhdx
  3. Run Hyper-V Manager to create the new machine via, New->Virtual Machine.
  4. 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"?

Benjamin Peikes
  • 1,094
  • 3
  • 16
  • 26
  • 3
    It seems to me that you'd want to merge the checkpoints with the parent VHD(X). A new way to do this in Windows Server 2012 R2 is with the live virtual disk merge feature. - http://mikefrobbins.com/2012/08/14/hyper-v-live-merge-snapshot-feature-in-windows-server-2012 – joeqwerty Dec 05 '14 at 00:36
  • I doubt that you can use a disk with a checkpoint on it as a template easily. You will probably find it a lot easier to just make a fully copy your template vhdx files. – Zoredache Dec 05 '14 at 00:52
  • @joeqwerty, is there a way to merge the checkpoint files, but keep the check points? For example let's say I have 3 or 4 check points, but I want to create a vhdx which contains all of the cumulative changes but keep the check points as well? – Benjamin Peikes Dec 05 '14 at 19:24

2 Answers2

1

The answer depends on what you mean by "use this new template." There are two possible interpretations:

  • Deploy new VMs based on the changes that I made to the template.
  • See the changes to the template in already deployed, older VMs.

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.

Jake Oshins
  • 5,146
  • 18
  • 15
0

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.

joeqwerty
  • 109,901
  • 6
  • 81
  • 172
  • Wow, that's pretty involved and not easily scriptable. I guess you really aren't supposed to use Hyper-V without System Control Center, or don't use snapshots for any long term versioning. – Benjamin Peikes Dec 08 '14 at 14:58
  • Hyper-V snapshots aren't meant to be a versioning control system and they're not meant to be used as some sort of backup either. Hyper-V snapshots are mean to give you a way to test changes while maintaining the ability to get back to where you were. Best practice also suggests that snapshots not be used in production, except very sparingly. If you've got a snapshot tree longer than one or two snapshots then I'd suggest that you're doing it wrong. Nothing personal and no offense intended. – joeqwerty Dec 08 '14 at 16:55