Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vagrant with Hyper-V Provider to run Laravel Homestead

Using a new install of Laravel with Laravel Homestead I've been trying to get Vagrant to boot, but it keeps timing out. I tried using the Default virtual switch, as well as the DockerNAT and NewInternalVirtualSwitch which is a virtual switch I added using the Hyper-V Manager.

I know I can leave the provider as VirtualBox and turn off Hyper-V, but since we use Vagrant and Docker for different application doing this over the last couple days has become tedious since Docker for Windows on Windows 10 Pro requires Hyper-V to be on so each time you have to shut down and restart in either direction.

Has anyone gotten Laravel Homestead to work using the Hyper-V provider, and what steps did you have to take to get networking to work which appears to be the issue?

Homestead.yaml

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: hyperv
authorize: ~/.ssh/example/id_rsa.pub
keys:
    - ~/.ssh/example/id_rsa
folders:
    -
        map: 'D:\Projects\example\server'
        to: /home/vagrant/server
sites:
    -
        map: server.app
        to: /home/vagrant/server/public
databases:
    - example
name: example
hostname: example

Vagrant Up

Bringing machine 'example' up with 'hyperv' provider...
==> example: Verifying Hyper-V is enabled...
==> example: Importing a Hyper-V instance
    example: Please choose a switch to attach to your Hyper-V instance.
    example: If none of these are appropriate, please open the Hyper-V manager
    example: to create a new virtual switch.
    example:
    example: 1) DockerNAT
    example: 2) Default Switch
    example: 3) NewInternalVirtualSwitch
    example:
    example: What switch would you like to use? 3
    example: Cloning virtual hard drive...
    example: Creating and registering the VM...
    example: Setting VM Integration Services
    example: Successfully imported a VM with name: ubuntu-16.04-amd64_1
==> example: Starting the machine...
==> example: Waiting for the machine to report its IP address...
    example: Timeout: 120 seconds
    example: IP: fe80::215:5dff:fe38:107
==> example: Waiting for machine to boot. This may take a few minutes...
    example: SSH address: fe80::215:5dff:fe38:107:22
    example: SSH username: vagrant
    example: SSH auth method: private key <--- Stalls out for a couple minutes

Error

Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.

If you look above, you should be able to see the error(s) that
Vagrant had when attempting to connect to the machine. These errors
are usually good hints as to what may be wrong.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.vm.boot_timeout") value.

Update

Also tried tip 4 using an external virtual switch and it makes it further, but still fails with an error while trying to assign a hostname:

==> example: Machine booted and ready!
==> example: Setting hostname...
No host IP was given to the Vagrant core NFS helper. This is
an internal error that should be reported as a bug.
like image 929
mtpultz Avatar asked Dec 13 '17 05:12

mtpultz


People also ask

Does vagrant work with Hyper V?

Vagrant comes with support out of the box for Hyper-V, a native hypervisor written by Microsoft. Hyper-V is available by default for almost all Windows 8.1 and later installs. The Hyper-V provider is compatible with Windows 8.1 and later only.

What is Homestead vagrant?

Laravel Homestead is an official, pre-packaged Vagrant box that provides you a wonderful development environment without requiring you to install PHP, a web server, and any other server software on your local machine. Vagrant provides a simple, elegant way to manage and provision Virtual Machines.


1 Answers

Edit: After setting it all up and testing workflow, I went back to VirtualBox + Homestead and disabled Hyper V. The bottom line is that Windows and Linux are not very compatible with each other and while Hyper V is native to Windows, everything that follows won't be and even simple tasks like copying files and setting permissions require a lot of labor.

I will leave my answer below, maybe someone else or I will come back to it in the future.


I just spent a day trying to get it to work and I couldn't but I came up with a solution that works better for me at least so I'll share it here.

If your workstation runs Windows 10 Pro with Hyper V and you know how to set up your production server, then it might work for you.

The idea is to give up on Homestead and set up your local server just like you do the production server but on Hyper V:

  1. Enable Hyper V
  2. Download your server OS image (Ubuntu 18.04 for me) and create a virtual machine with it.
  3. Choose what you need from the list of software included in homestead and install those on the virtual machine (for me its Nginx, PHP, PostgreSQL, Git, Python, and Composer).

At this point you pretty much have your custom made Homestead on Hyper V. Log into the virtual machine, copy its ip (it should show it upon login but if not, here is a command to bring it up on Ubuntu ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'), enter it into the browser window and it should bring the default Nginx frontpage up.

It's pretty easy, but the problem is that this ip is dynamic and it will keep resetting. The toughest part is to make it static.

  1. Set ip in the Hyper-V manager to static right click the virtual machine -> Settings -> Network Adapter -> Advanced Features. Reboot everything

  2. Set ip to static in the OS in virtual machine (guide for Ubuntu 18.04). Note that ip address of the host Hyper V vEthernet adapter (ipconfig on Win 10 to bring it up) is the gateway address for the virtual machine OS.

So pros and cons from my perspective.

Pros:

  • Works faster and cleaner on Windows + Hyper V than on Windows + Oracle Virtual Box
  • Customizable and updatable. The only way to update Homestead seems to be delete it and download the new one.

Cons:

  • Hard to set up if you are not familiar with your production server setup
  • Setting up static IP is really a painful lot of hacking
  • Accessing files between Linux and Windows requires Samba dependency
  • Managing permissions of Linux files accessed through Windows is complicated
  • Linux guest doesn't seem to have access to GPU through Hyper V
like image 126
Arthur Tarasov Avatar answered Nov 15 '22 11:11

Arthur Tarasov