» Creating a Base Box
As with every Vagrant provider, theVagrant Hyper-V provider has a custom box format that affects how base boxes are made.
Prior to reading this, you should read thegeneral guide to creating base boxes. Actually,it would probably be most useful to keep this open in a separate tabas you may be referencing it frequently while creating a base box. Thatpage contains important information about common software to installon the box.
Additionally, it is helpful to understand thebasics of the box file format.
Advanced topic! This is a reasonably advanced topic thata beginning user of Vagrant does not need to understand. If you arejust getting started with Vagrant, skip this and use an availablebox. If you are an experienced user of Vagrant and want to createyour own custom boxes, this is for you.
» Additional Software
In addition to the software that should be installed based on thegeneral guide to creating base boxes,Hyper-V base boxes require some additional software.
» Hyper-V Kernel Modules
You will need to install Hyper-V kernel modules. While this improves performance,it also enables necessary features such as reporting its IP address so thatVagrant can access it.
You can verify Hyper-V kernel modules are properly installed byrunning lsmod
on Linux machines and looking for modules prefixed withhv_
. Additionally, you will need to verify that the "Network" tab for yourvirtual machine in the Hyper-V manager is reporting an IP address. If itis not reporting an IP address, Vagrant will not be able to access it.
For most newer Linux distributions, the Hyper-V modules will be availableout of the box.
Ubuntu 12.04 requires some special steps to make networking work. Theseare reproduced here in case similar steps are needed with other distributions.Without these commands, Ubuntu 12.04 will not report an IP address toHyper-V:
$ sudo apt-get install linux-tools-3.11.0-15-generic
$ sudo apt-get install hv-kvp-daemon-init
$ sudo cp /usr/lib/linux-tools/3.11.0-15/hv_* /usr/sbin/
» Packaging the Box
To package a Hyper-V box, export the virtual machine from theHyper-V Manager using the "Export" feature. This will create a directorywith a structure similar to the following:
.
|-- Snapshots
|-- Virtual Hard drives
|-- Virtual Machines
Delete the "Snapshots" folder. It is of no use to the Vagrant Hyper-Vprovider and can only add to the size of the box if there are snapshotsin that folder.
Then, create the "metadata.json" file necessary for the box, as documentedin basics of the box file format. The properprovider value to use for the metadata is "hyperv".
Finally, create an archive of those contents (but not the parent folder)using a tool such as tar
:
$ tar cvzf ~/custom.box ./*
A common mistake is to also package the parent folder by accident. Vagrantwill not work in this case. To verify you've packaged it properly, add thebox to Vagrant and try to bring up the machine.
» Additional Help
There is also some less structured help available from the experience ofother users. These are not official documentation but if you are runninginto trouble they may help you: