Insufficient data from Andrew Fryer

The place where I page to when my brain is full up of stuff about the Microsoft platform

June, 2012

  • Hyper-V Snapshots in Production

    It’s sometimes quite difficult to talk and think at the same time, and at our camps last week I think we may have caused some confusion around snapshots for virtual machines (VM) that are in production so I wanted to write this up from first principles so that I have somewhere to refer to in future.

    All server virtualisation vendors have a way of creating a file that represents a physical hard disk – a virtual hard disk.  In Hyper-V in Windows Server this is referred to as a “VHD” and currently has a .VHD extension limited to 2Tb in size.  In Hyper-V in Windows Server 2012 you can use this version of VHD so your existing VMs will work, but there is also the newer VHDX format which goes up to 64TB.

    VHDs come in three flavours:

    Fixed. You declare their size and this space is reserved at creation time. This is the fastest VHD as there is no overhead in growing the disk and if the VHD is created on a well optimised physical disk it will reside on contiguous blocks as well. You can expand these disks later if needed, but remember you will also need to go into the VHD and extend the volumes on it to get the operating system to use it as well

    Dynamic.  As the name suggests these expand as required, and in fact they are tiny to begin with no matter what size you declare.  There is a background process to expand them as needed so the guest operating system is never aware that the specified maximum size isn’t really there yet.  However there may come a moment when the physical disk may run out of space in which case your VMN will stop gracefully until this is resolved.

    Differencing.  In this scenario you have a parent VHD from which you create a new child VHD into which any changed data goes. For example my parent VHD might have a sysprepped Windows Server installation on and then as the VM comes up for the first time all the changes get written in to the child VHD, the parent never changes.  This is important as you can then create another child form the same parent to create another windows server VM.  This saves me loads of disk space on my demo rig, but the performance is not as high as it would be for a fixed disk and the savings in disk decline over time as each child VM would need to patched and service packed, as the parent cannot be changed.  Differencing disk really come into their own for Virtual Desktop infrastructure where you have lots of windows 7 VMs that are little different form each other.Note also the at a differencing disks themselves can

    I mention this because taking a checkpoint/ snapshot of a VM is like using a parent disk -  all the changes to a VM after a snapshot is taken are written to a new VHD (You’ll see this on your physical disks with a .AVHD extension where you specified to save your snaphots).  If I create a subsequent snapshot then another AVHD is created and changes are then written to this newer AVHD file.  If I delete a snapshot on a VM running in Hyper-V in Windows Server 2008 R2 nothing really happens until the VM is stopped and restarted. At that time the data in the AVHD is merged into the parent be that an earlier AVHD representing a snapshot or the actual VHD itself.  In other words you wont get the disk space back from a snapshot until reboot and moreover Hyper-V needs some additional disk space to do this merging.  This changes in Windows Server 2012 in that merging will occur as soon as you delete the snapshot i.e. whether the VM is running or not.

    So having understood all of that what about snapshots in production?  Yes definitely as a fall back for applying changes to production but NOT as a backup or your only DR  solution for mission critical services, which was the point Simon and I were trying to make at the IT Camp.  For one thing you may have a multi-tier service that will respond well to rolling back one of its constituent VMs or there might be time sensitive code in there that will be confused when you revert to a snapshot.  Also having a disk with snapshots in is slower than a fixed disk so there might be performance considerations until you can restart the VM and remove the snapshot.  As I say this last problem goes away in Windows Server 2012 as snapshots get deleted while the VM is running, so you only have to retain a snapshot until you are sure the change you have made is working as expected.

    The definitive Q&A on Snapshots is here on TechNet, and you can find out more about what’s new in Windows Server 2012 here as well as download the Release Candidate.

  • PowerShell convert

    Back in the day I worked with this amazing guy James O’Neill (@jamesoneill)  who really got into PowerShell and had it doing all sorts of clever things like geo tagging his dive photos based on data form his watch and camera.  On the serious side he developed a PowerShell Configurator (which is still on Codeplex)with which you could manage a server core installation spin VM and change their properties.  Sadly James is no longer at Microsoft, but hopefully he likes where PowerShell 3 in Windows Server 2012 is going, indeed some of the commands bear a striking similarity to his configurator.

    My point here is that in Windows Server 2012 PowerShell is now embedded even more deeply in the operating system,  so you can do far more, far more easily. My three simple examples are:

    New simple commands:

    Where James or you had to get deep into wmi calls to get stuff done with Hyper-V for example, there are now simple commands e.g.

    get-vm

    Which returns a list of virtual machines

    Simple syntax

    If you look at any serious Powershell 2 script you’ll see $_. cropping up somewhere. Essentially that is just a self reference to the object you are working on.  For example if I then pipe the output of get-vm into a query to find out which VMs are enabled for Replica in Windows Server 2012 I would type ..

    get-vm | where {$_.ReplicationState –eq ‘disabled’}

    However this can be simplified In Powershell 3 to

    get-vm | where ReplicationState –eq ‘disabled’

    Simple testing

    I like the new –whatif switch as in

    checkpoint-vm –name “DC01” –whatif

    will tell me what the command will do.

    Then there’s the new version scripting tool PowerShell ISE in Windows Server 2012

    powershell

    and as you can see it has :

    • Intellisense
    • cmdlet lookup (top right)
    • help on parameter completion which you can then copy onto the script window (bottom right).

    So I am now officially a PowerShell convert, though it will be some time before I would claim I am an expert.

    To try this stuff I used  Windows Server 2012 Release Candidate with the Hyper-V role enabled