Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

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.
share|improve this answer
add comment

I actually wrote a script which will provision machines by renaming and joining them to an AD Domain using Samba and Winbind.

What you need to do though is first generate a Virtual Floppy drive and write a Microsoft unattend.xml file to it. My provisioning scripts use this file and parse for the computer name, NetBIOS and FQDN domain names, as well as the user/pass to join to the AD Domain. You could just write a text file to the machine with a list of computer names though and PING for a non-responding host then use that information.

I depend on DHCP for IP addresses but if you had a name/IP pairing in a text file on the Template machine that would work as well. Start with DHCP but then convert to static IPs.

You could also look at hosting the config file on an FTP server and change your dhclient config to grab a newly created DHCP option which will point to said file then use it for the VM configuration.

There are a lot of ways you could figure out how to do this but it will definitely take quite a bit of scripting and setting up your template properly each time.

It will also depend on the Linux distribution you are looking at using. Currently, my provisioning works in conjunction with Dell vWorkspace and Hyper-V or VMware ESX using Red Hat/CentOS 5.8, 5.8, 6.x and currently finalizing Debian 7 and Ubuntu 12.04/12.10.

-Stephen Yorke www.dezignnet.com

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.