Linux – Automated Linux VMs on Hyper-V 2012

automationhyper-vkickstartlinux

I have a requirement to create a ton of linux VMs for our customers (we run managed infrastructure) on Hyper-V 2012 in the coming months and I have an issue with automating it.

Here is how I need it to work:

  1. User accesses their web page and creates a VM.
  2. VM is created with a unique IP and name
  3. User logs in over SSH

I know Hyper-V quite well and can work with powershell and am a C# programmer so the development side of things is taken care of. I also know enough about Linux to be at least competent: I have used it on and off for a number of years but not done anything Enterprise-level with it.

All this can be done easily by manual processes but I need to be able to script or program this to automate it as there could be hundreds of them being created but I don't know how.

My first thought is to have a database with random-generated names and IPs already created but I don't know how to get a Linux VM to boot up and grab one from the database… I suppose a Kickstart script would take care of it but I don't know what to do from there.

Here is what is bouncing around in my head:

  1. Create a std linux build. – Easy to do
  2. Someone clicks "Create VM" and I pull a name and IP from the database and write it to a kickstart script. – Easy to do
  3. I could then open the template VHDX file and copy in the script and then save it. – Not sure if possible
  4. User boots up new VM and the kickstart script gives it the name and IP I assigned it.

My problem is that I don't know how to open a VHDX file and insert a kickstart script into it… can't figure it out.

I am reaching here and this solution may be miles off… I am more used to creating Windows VMs with scripts and so on which i am more familiar with… any help would be appreciated.

Thanks

Mick

Best Answer

Windows can't mount an ext3/4 file system natively and most of the software packages out there to do so are (in my opinion) untrustworthy. So that is out.

A couple of ideas to get you started:

  • Set up a Linux VM that runs all the time for the purpose of configuring new VMs. When you create a customer VM, attach the VHDX to this configuration VM. Write a web service that performs the customization you need. You can be sure you are customizing the correct VHDX by mounting the partition using The SCSI ID, which you will know because PowerShell will tell you what ID was assigned when you attached the VHDX.
  • Initially boot the VM via PXE. The boot image can do the customization you need and then shut down the VM, which would be the signal to your PowerShell script to change the boot order to hard drive first and start the VM. If you go this route, I suggest creating a dedicated VLAN for the PXE customization for security reasons.
  • Create a FAT partition in your image that you can mount within Windows and copy your configuration file to it. Your Linux image should either be configured to look for the kick start file in that location or contain a script to copy it to the correct location during startup.
Related Topic