Convert vhd to vagrant box? - vagrant

I have a number of windows VMs running on my hyper-v instance I want to turn into vagrant boxes. Its there a tool out there that can do this for me or a clear guide on what needs to be enabled on the machine and how to create the config files that go into the box?
The documentation for windows VMs coming from hyper-v seem to be lacking with most guides focusing on virtual box.
TIA

There is no direct approach to achieve what you want.
NOTE: remove the hyper-v integration tools (agent, PV drivers etc...).
First, you need to convert VHD to VMDK or VDI format using VBoxManage, for example from VHD to VDI -> VBoxManage clonehd source.vhd target.vdi --format VDI
Once done, create a VM in VirtualBox with a proper spec (# of vCPUs, Memory, etc.), use the existing converted .vdi file as its virtual disk.
Try to boot the VM and see if everything works as expected. Install the VirtualBox Guest Additions (recommended).
Configure the VM as per Vagrant Documentation (e.g. NAT port forwarding rules, disabling UAC etc., refer to Creating a Base Box)
Package it as Vagrant box vagrant package --base vbox_vm_name --output /file/to/name.box

Related

Is it possible to enable WinRM in a Modern.ie VM or Vagrant Box by repackaging it with Packer?

There are these free like free beer virtual machines (VM) from Microsoft which one can download from modern.ie and use for testing or whatever. And there is this nice Gist on Github which explains how to enable WinRM support on that VMs. Unfortunately this requires manual interaction with the VM after initial boot up (step 2. in Gist). Is it possible to let Packer do this job using it´s builder type virtualbox-ovf (VIRTUALBOX BUILDER (FROM AN OVF/OVA))? If it is possible can you provide some example code, please.
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
What you asked is described in Step 4
Package
Since there's a lot of Windows specific configuration, you can include
the Vagrantfile in the package command so winrm and virtualbox
configuration get's default values when the repackaged is used for
other purposes. Remember to run the command in the same directory the
Vagrantfile resides:
$ vagrant package --output "yourboxname" --Vagrantfile Vagrantfile
After that you're all set!
once you complete step2 and 3, you will run step4 which recreate a vagrant box from the updated VM and you can re-use this box
Or asked another way: How to create a Vagrant Box from an existing VirtualBox image (.ova file) or from an existing Vagrant Box (.ovffile) with Packer?
This is not possible, shortly speaking, packer creates Vagrant box from OS ISO distribution, not from existing VM
You can connect to Windows modern.ie VM with ssh (Openssh service runs at startup). You'll have a very limited shell, but enough to call cmd.exe or powershell, and activate WinRM. On Windows 10 VM, you just have to change the network type to something not public. That's it.

Conifgure VBoxManage commands that require VM be running from Vagrantfile

There are several commands under the VBoxManage umbrella that require the guest machine already be running (e.g. controlvm, guestcontrol) but all the vbox configuration I see in the Vagrantfile happens before the machine has started.
Is there a way in the Vagrantfile to configure the machine after it has started?
The goal of vagrant is to abstract the creation of VM for multiple provider (including VirtualBox) it is not really to provide all manipulation of the VM afterwards and replace the VBoxManage -
If you need to run command after the VM has started and run it from Vagrantfile, I would suggest to look at the vagrant-triggers plugin which :
Allow the definition of arbitrary scripts that will run on the host before and/or after Vagrant commands.

Vagrant creating another VM instead of boot up the default VM

I'm using Vagrant on Windows to create my dev environment. But today when I start it with the command vagrant up, it created another VM instead of using the one I always used it.
Looking in the folder C:/Users/My_User/VirtualBox VMs I found the default VM files.
How to proced to make Vagrant recognize this default VM?
PS: Sorry for my bad english!

cannot use the box created with packer post-processor vagrant

I followed the tutorial on packer.io to create a vagrant box from an amazon-ebs backed instance : https://www.packer.io/intro.
Only issue, the created .box file only contains a Vagrantfile and metadata.json, but I cannot find out how to use this in vagrant with virtualbox since all other boxes I have seen (among them hashcorp/precise32) have a .vmdk and .ovf file and mine doesn't !! Anyone has followed the tutorial and can advise me ? Thanks,
I think I found out : the vagrant box created for post-processing is meant to be used with the vagrant-aws plugin, not with virtualbox.
The provider is then "aws" and not "virtualbox", hence why I do not get the .vmdk and .ovf files. The aws-plugin is only to boot and provision EC2 instances, where as what I wanted to do was to "capture" the Amazon minimal linux interface in order to test it locally (cannot find a bloody iso file for it).
I must then surrender, packer.io was my last hope : I cannot find a way to set-up a VM with the minimal amazon linux image running...

Vagrant taking up too much space

I switch between four projects on my local machine and I use vagrant for each on of them.
$ vagrant global-status
id name provider state directory
-------------------------------------------------------------------------
3e1f21e default virtualbox running d:/www/project1/source
9080cd0 default virtualbox poweroff d:/www/project2/source
c4e0461 default virtualbox poweroff d:/www/project3/source
b75805d default virtualbox running d:/www/project4/source
However, my C drive (I'm on a windows 7 machine) is showing that I'm using 16.4GB on the \User\VirtualBox VMs
It seems a little excessive for just 4 VMs. So I opened VirtualBox and saw that I had 7 VMs on there.
I'm thinking these are boxes that I previously destroyed but I could very well be wrong.
I couldn't find anything about it on the web. But could I just delete these items or are they important to vagrant? If so, how can I set up vagrant without having to use up too much space on my laptop?
If you destroyed the boxes with vagrant destroy and it finished without errors, the box should be gone from Virtualbox as well. If this didn't happen, you can remove the box manually from Virtualbox. Just make sure to also delete the local files (Virtualbox will ask you if you wanna keep the HD, which you don't)!
If you are unsure which boxes to remove from Virtualbox because they are all named he same, you can either destroy all boxes from vagrant and then remove all boxes left to Virtualbox. Or you can start all vagrant boxes using vagrant up and then delete the ones from Virtualbox which don't run.

Resources