Vagrant hyper v windows

Vagrant + Hyper-V (Windows 10 anniversary)

17 Aug 2016 in Technology, Hyper-v

Making Vagrant play nicely with Hyper-V; that can be a bit of a ballache

Well, my personal laptop has been upgraded to Windows 10 Anniversary; it’s a dual SSD + HD affair, an Asus NX501-JW which hasn’t been affected by the other “SSD+HD” bricking issues that have been in the tech news. Anyway, either I, or Microsoft during the upgrade, uninstalled Virtualbox, which I had been using to run an HPCC Systems environment amongst other things. In the end, the chance to run Docker natively, and Linux shell natively via Hyper-V persuaded me that I should try and get Vagrant to play nice to Hyper-V; this then is an afternoon of fun and games.

VirtualBox has long been the default provider for Vagrant and if you search for boxes on Atlas, they’re the ones that are most popular. Hyper-V is supported, but there aren’t as many boxes around. This then is a distilled how-to for getting a box up and running with NAT on Hyper-V. For brevity, I’ve just distilled the raw commands with no explanation as to why I’m doing things as I’ve done them; they just worked for me.

Create a NAT switch

Once you have the Hyper-V role enabled; then you need to add a virtual switch, so use powershell to do that (run as Administrator naturally) rather than the Hyper-V manager UI.

It does some stuff, but eventually you have a switch that is NAT enabled, and your IP Address is 172.21.21.1 for the network card associated with the switch. The source was http://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/.

Vagrant UP and Down

Our production machines are all CentOS or variants of, so I like to stick with what I know. There aren’t that many CentOS 7 boxes available, so I used serveit/centos-7 which works well enough.

Once you run vagrant up , it’s up, and you can vagrant ssh to it; but it may well have defaulted to IPV6; which probably isn’t all the useful for you.

Fiddling the network card.

So, now we need to fix up the network card (easy enough to do) with a fixed IP Address.

After that, a vagrant halt followed by a vagrant up will fix up the IP addresses nicely.

Huh, can’t mount my shared folders

If you’re using the serveit/centos-7 image then it may fail to mount whatever shared folders you’ve specified with some error or other. To cut a long story short, because it’s a minimal image, it doesn’t come with cifs-utils; Get that via yum (because you have NAT right) and you’ll be able to mount whatever shares you need in your vagrant file, and voila you have a provisioned CentOS-7 machine.

  • Using WSL and Windows Git Bash interchangeably04 Sep 2019
  • Migrating to MacOS for work13 Feb 2019
  • HPCC 6.4.2: dfuplus fails to spray files18 Oct 2017
Читайте также:  Относительный абсолютный путь linux

©. All rights reserved.

Powered by Hydejack v 6.6.1

Specialising Generalist

Integration isn’t always easy but it’s never hard

savishy / Vagrant and Hyper-V Networking Configuration.md

Vagrant and Hyper-V: Working with Virtual Network Interfaces

These notes will help to:

  • configure an internal virtual network interface ( vEthernet ) in Hyper-V
  • set it up so it can access the internet from your laptop’s WiFi connection
  • use it in Vagrant so that your Vagrant box will be provisioned successfully with hyperv provider.

1. Create Virtual Network Interface

  1. Open Hyper-V Manager. Look at the References section if you cannot find Hyper-V Manager.
  2. Click your machine name on left panel. On the right-most panel you will find the option Virtual Switch Manager . Click that.
  3. Create an Internal interface. Name it «InternalSwitch».

2a. Setup Network Sharing between WiFi and InternalSwitch

  1. Now you need to configure your WiFi’s network adapter.
  2. In the Run Dialog, type control netconnections . This opens the Network Adapter window.
  3. Right-click your WiFi network adapter, open Properties > Sharing tab.
  4. Configure sharing between WiFi adapter and the InternalSwitch virtual interface created above.

3. Configure IPV4 Settings for InternalSwitch

❗ *If your VM is running while you configure network, please restart the VM ( vagrant reload ) !

Next, configure the IPV4 Settings for the InternalSwitch adapter.

  1. Open properties for the InternalSwitch adapter.
  2. Click «Internet Protocol Version 4» and click «Properties».

And then configure its properties as follows (only the DNS address may be missing usually):

4. Make sure Docker for Windows is turned off

At this point, if you have Docker for Windows running, your virtual interface will show «No Internet Access». See the references section; there is documentation that says only one such internal interface can be used at a time.

The network interface will now show an internet connection.

5. Execute vagrant up

Its assumed you have a Vagrantfile with a hyperv box and configuration — example this Vagrantfile .

Run vagrant up —provider=hyperv .

❗️ Make sure to from an elevated terminal. ❗️ Vagrant does not allow auto-configuring the interface. It will ask you to choose the interface, select the appropriate number:

Troubleshooting: Error during vagrant up : failed to get IP address

The root cause is that it runs a script C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.9.7\plugins\providers\hyperv\scripts\get_network_config.ps1 which ultimately calls Get-VMNetworkAdapter .

And this cmdlet returns empty IP addresses, which trips up vagrant.

Cause #1: the Vagrant Box itself

There is very little documentation on this online. Some references:

I tried switching different Vagrant hyperv boxes:

  • generic/ubuntu1604 : 👎
  • kmm/ubuntu-xenial64 : 👍 This worked and went past the timeout!

Cause #2: IPV6

On one occasion, I had to make sure that IPV6 was disabled on the network properties for the InternalSwitch virtual interface.

Cause #3: hv_kvp_daemon service on Ubuntu

On another occasion, I had to install a set of packages inside my Ubuntu Hyper-V VM to ensure it connects properly. The package was called linux-cloud-tools or something ( link )

Troubleshooting: IPV6 Address shows up during vagrant up and also

Symptom #1: IPV6 address shows up during vagrant up —provider=hyperv

Symptom #2: InternalSwitch Virtual Adapter shows «No Internet Access» when you right-click it (from control netconnections window) and select «Status».

Possible Cause and Solution

  • I had created the InternalSwitch switch (as described above) many months ago. Since then my Windows had updated to Windows 10 build 1607.
  • There are known issues with Internet Connection Sharing not working after that update. link.
  • I deleted Hyper-V vagrant boxes that were using the switch.
  • I deleted the InternalSwitch Virtual Adapter from Hyper-V Manager.
  • I disabled all existing Hyper-V Virtual Ethernet Adapters from control netconnections Window.
  • I re-created the Adapter again using above documentation. This time it showed «Internet Access» in the Properties. 👍
  • I did a vagrant up —provider=hyperv again. This time the box got an IPV4 address! 👍
Читайте также:  Windows не видит встроенную видеокарту

Vagrant + Hyper-V (Windows 10 anniversary)

17 Aug 2016 in Technology, Hyper-v

Making Vagrant play nicely with Hyper-V; that can be a bit of a ballache

Well, my personal laptop has been upgraded to Windows 10 Anniversary; it’s a dual SSD + HD affair, an Asus NX501-JW which hasn’t been affected by the other “SSD+HD” bricking issues that have been in the tech news. Anyway, either I, or Microsoft during the upgrade, uninstalled Virtualbox, which I had been using to run an HPCC Systems environment amongst other things. In the end, the chance to run Docker natively, and Linux shell natively via Hyper-V persuaded me that I should try and get Vagrant to play nice to Hyper-V; this then is an afternoon of fun and games.

VirtualBox has long been the default provider for Vagrant and if you search for boxes on Atlas, they’re the ones that are most popular. Hyper-V is supported, but there aren’t as many boxes around. This then is a distilled how-to for getting a box up and running with NAT on Hyper-V. For brevity, I’ve just distilled the raw commands with no explanation as to why I’m doing things as I’ve done them; they just worked for me.

Create a NAT switch

Once you have the Hyper-V role enabled; then you need to add a virtual switch, so use powershell to do that (run as Administrator naturally) rather than the Hyper-V manager UI.

It does some stuff, but eventually you have a switch that is NAT enabled, and your IP Address is 172.21.21.1 for the network card associated with the switch. The source was http://www.thomasmaurer.ch/2016/05/set-up-a-hyper-v-virtual-switch-using-a-nat-network/.

Vagrant UP and Down

Our production machines are all CentOS or variants of, so I like to stick with what I know. There aren’t that many CentOS 7 boxes available, so I used serveit/centos-7 which works well enough.

Once you run vagrant up , it’s up, and you can vagrant ssh to it; but it may well have defaulted to IPV6; which probably isn’t all the useful for you.

Fiddling the network card.

So, now we need to fix up the network card (easy enough to do) with a fixed IP Address.

After that, a vagrant halt followed by a vagrant up will fix up the IP addresses nicely.

Huh, can’t mount my shared folders

If you’re using the serveit/centos-7 image then it may fail to mount whatever shared folders you’ve specified with some error or other. To cut a long story short, because it’s a minimal image, it doesn’t come with cifs-utils; Get that via yum (because you have NAT right) and you’ll be able to mount whatever shares you need in your vagrant file, and voila you have a provisioned CentOS-7 machine.

Читайте также:  Total war warhammer не запускается windows
  • Using WSL and Windows Git Bash interchangeably04 Sep 2019
  • Migrating to MacOS for work13 Feb 2019
  • HPCC 6.4.2: dfuplus fails to spray files18 Oct 2017

©. All rights reserved.

Powered by Hydejack v 6.6.1

Specialising Generalist

Integration isn’t always easy but it’s never hard

» Usage

Warning! This feature is experimental and may break or change in between releases. Use at your own risk. It currently is not officially supported.

This feature currently requires the experimental flag to be used. To explicitly enable this feature, you can set the experimental flag to:

Please note that VAGRANT_EXPERIMENTAL is an environment variable. For more information about this flag visit the Experimental docs page for more info. Without this flag enabled, any disks defined will not be configured.

For examples of how to use the disk feature with Hyper-V, please refer to the general disk usage guide for more examples.

» provider_config options

Most options are used for either creating or attaching a hard disk to your guest. Vagrant supports most options for these operations. You should be able to define the powershell specific argument to a given Hyper-V command in the provider_config hash, and Vagrant should properly pass it along to the command.

To define a provider specific option, please refer to the Disk Options documentation page for more info.

» Note about options defined below

It is possible these options could be out of date or stale. If you happen to see an option that has changed or is missing from this page, please open an issue or pull request on Vagrants GitHub page to correct this.

» New-VHD Supported Options

For more information about each option, please visit the New-VHD Hyper-V documentation.

Note: By default, all Hyper-V disks are defined as a Dynamic virtual hard disk. If you wish to make the disk a fixed size, you can set the Fixed option below when creating a new disk.

  • BlockSizeBytes (string) — Optional argument, i.e. «128MB»
  • Differencing (bool) — If set, the disk will be used to store differencing changes from parent disk (must set ParentPath )
  • Fixed (bool) — If set, the disk will be a fixed size, not dynamically allocated.
  • LogicalSectorSizeBytes (int) — Optional argument, must be either 512 or 4096
  • ParentPath (string) — The parent disk path used if a Differencing disk is defined
  • PhysicalSectorSizeBytes (string) — Optional argument, must be either 512 or 4096
  • SourceDisk (int) — Existing disk to use as a source for the new disk

» Add-VMHardDiskDrive Supported Options

For more information about each option, please visit the Add-VMHardDiskDrive Hyper-V documentation

Generally, these options do not need to be set or handled by most users. Only use these options if you are sure you know what you are doing. Vagrant will be able to attach disks for you without these options, but they are available if it is required that you specificy a specific location for a disk.

  • ControllerLocation (int) — The location that the disk should be attached to on the controller
  • ControllerNumber (int) — The controller to use for attaching the disk
  • ControllerType (string) — The kind of controller to use when attaching the a disk. Only «IDE» and «SCSI» are valid.
Оцените статью