Technical Playground

Enable Auto-Start for Currently Running Virtual Machines in XenServer 6.2

After experiencing a power hit the other day, I noticed that none of our virtual machines on a XenServer 6.2 host auto-powered on. Looking in the XenCenter client was no help as the option to enable VM Start on Boot was not present.

A bit of quick Googling provided the following document that basically explains the Auto-Start functionality was removed due to conflict with some high-availability options in XenServer pools.

Given that the server in question is stand-alone, the HA options were useless to me so I proceeded to read how to enable the Auto-Start.

Making it easier

The document provides great instructions on how to enable Auto-Start, but it does so on a one-by-one basis. The XenServer host I was working with has approximately 40VMs, with 25 or so running at any given time. Feeling lazy, I first enabled the pool parameter (outlined in the above link) and verified all the VMs that needed to auto-start were currently running and ran the following bash one-liner

1
2
3
4
5
for f in `xe vm-list power-state=running |
grep uuid | cut -d ':' -f2 | cut -d ' ' -f2`;
do echo "Enabling Auto-Start on $f";
xe vm-param-set uuid=$f other-config:auto_poweron=true;
done

Splitting this up a little…

  • The typical for..in loop in bash gets a list of uuids from the content in backticks.
  • xe vm-list power-state=running gives a list of all the currently running VMs. Note you can use a different state to get a different list of VMs to suit your needs.
  • The next three piped commands, grep uuid | cut -d ':' -f2 | cut -d ' ' -f2 grab the line from the vm-list with the uuid and get the actual uuid from the text.
  • We then feed that through the loop and set the auto_poweron option to true for each of the uuids in question.

Enabling the option on 25+ VMs took about 5 seconds vs manually sorting through everything.