By Garth Jones
This blog post has been a long time coming. It started with an open letter to Ben Armstrong. Ben’s one of the Lead Program Managers on the Microsoft Hyper-V Team. I asked Ben to consider adding a feature that would allow for Virtual Machines (VMs) to be started in a pre-defined order with delays between each VM. I would love to see this in Hyper-V!
I can hear what you’re thinking, “This is a great idea, but doesn’t it already exist in Hyper-V?” No, not what I’m looking for.
You might ask, “What about the delayed start option?”
Yes, that kind of works, but there are several major drawbacks with the delayed start option. Mainly having to:
· Set this option manually for EACH VM (see Row #1 in my example below).
· Track what you have set for each VM.
· Manually create a delay before starting each VM by adjusting each VM’s start-up delay.
· Edit each affected VM to change the start-up order of VMs.
· And, for VMs that were not on when the server shutdown (VM2 in my example below), using the delay start option will result in VM2 not starting at all (see Row #2 below) and therefore leaving a 30 second gap. Ideally, what you see in Row #3 is what should happen.
I think my suggestion for this new Hyper-V feature would be very helpful because it would help solve the following problems:
1. When a Hyper-V server shuts down, by default all VMs go into saved state simultaneously, so by delaying the shutdown of all VMs, they won’t be competing for resources.
2. When starting up the Hyper-V server, all VMs start at the same time (by default), so by delaying the start-up of all VMs, they won’t be competing for resources.
3. Since disk subsystems are the number one performance issue, any delay of disk IO, will help prevent overloading disk subsystems.
With added benefits of:
1. Allowing the most important VMs to start-up first (if they were on when the server shutdown).
2. Allowing the most important VMs to be shut down last before shutting down the server.
3. Allowing VMs to be shut down manually instead of using the default saved state (this is my preference).
Not only did I write a letter to Ben, but I also wrote a pseudo code for this feature. I spoke to Sean Kearney @energizedtech who is a PowerShell MVP and a long-time friend. During one of our discussions I told him about my idea for this new feature. Sean said that everything could be done with PowerShell, so to help me get started, he sent me several lines of PowerShell code.
Between Sean’s code and my pseudo code, I now had a starting point to create this feature within PowerShell until the Hyper-V team can add it in.
My script is only in its first version and I definitely plan to upgrade it later. What does it do?
· Creates a list comma-separated values (CSV) file of running VMs.
· Shuts down each VM one at a time with a 5-second delay.
· Reboots the server.
· Reads the CSV file and starts each VM one at a time.
· There’s a 20-second delay between each startup.
· Deletes the CSV file.
For a first version it does the basics, so what’s next? Here’s my list, in no particular order:
· Create a priority list of VMs to shut-down last and to startup first.
· Determine the process to have this script run automatically at server boot-up.
· Determine the process to have this script run automatically on server shutdown.
· Create a better log.
I’m sure there are more features to add, but I haven’t thought of them yet. If you have any ideas to help upgrade my code, let me know by tweeting me @GarthMJ. You can download my PowerShell script via the Enhansoft website.