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.
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:
Enable Hyper V
Download your server OS image (Ubuntu 18.04 for me) and create a virtual machine with it.
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.
Set ip in the Hyper-V manager to static right click the virtual machine -> Settings -> Network Adapter -> Advanced Features. Reboot everything
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
This problem may happen because by default, the Hyper-V switches are treated as Public network; the Windows firewall blocks access to virtual machines.
One easy but dangerous workaround is to simply turn off the Windows firewall. You can do that to test whether this is your problem, but of course do not leave the firewall off.
A better solution is to disable the firewall only for the network switch (or switches). This cannot be done in the GUI; you need an elevated PowerShell for that.
set-NetFirewallProfile -DisabledInterfaceAliases NewInternalVirtualSwitch,DockerNAT,Default
Note that if you want to disable the firewall for multiple switches, you must specify all of them in a single call to Set-NetFirewallProfile.
An even better solution would be to change the switches to private network, but I am not aware of any way to do that.
Had similar issues here (on Windows 10 Home) trying to run Docker along side Homestead. I can't say for sure what did the trick but I ended up with this:
In Windows features turn on:
Virtual Machine Platform
Windows Hypervisor Platform
Windows Subsystem for Linux
Used HyperVSwitch to turn on even more Hyper-V (just turning it on as a "Windows feature" is not enough!) https://unclassified.software/en/apps/hypervswitch
Restart Windows
In the VirtualBox manager disabled "Adapter 2" for the Homestead machine (Settings > Network > Adapter 2 > uncheck Enable Network Adapter)
Run the Homestead machine as normally.
Adapter 2 will be turned on again once you restart the Homestead machine But it seams that it now works fine in combination with all the Hyper-V settings.
Since it was a lot of trail, error and restarting of servers I'm not sure what exactly did the trick but I hope it helps some people in their quest to run Docker and Homestead together.
I know now at least that it's possible :)
Related
I have been using Vagrant for few months. Also I have started using Virtual box without Vagrant with sharing folders from host OS and it works well so far.
My question is why is Vagrant needed if Virtual Box can share folders without Vagrant?
Maybe I don't use Vagrant's other features so I don't need them so far.
Just a few things, but will probably not be exhaustive:
Vagrant operates multiple provider, not only Virtualbox, you can run vagrant with Virtualbox, VMWare, HyperV ... (docker as well even if there are different pros and cons) so vagrant abstracts this for you
vagrant can setup shared folders as you experienced, but can easily set different shared folder types (nfs, rsync ..) depending your setup
vagrant will manage all the networking of the VM, if you need a static IP, it will associate hostname and static IP and setup all the routes for you.
vagrant works well with many provisioning tools (puppet, chef, ansible ...) so you can easily create and re-created multiple times the same environment
On top of all this, why is vagrant good to use ? In team. If you work in team, you share a vagrant file (just a ruby script file) and "magically" all your team members share the same environment to work.
Hadoop & Vagrant: If I set up a new VM using these two packages, is the VM available for starting with VirtualBox or do I always have to use vagrant up?
When you first create the VM, you will need to use vagrant up since VirtualBox has no ability to read a Vagrantfile. Once your VM is up and running, you could stop and start it using VirtualBox. However, Vagrant can perform the same operations as VirtualBox and has a lot of advantages on top of that.
First let's discuss how Vagrant can do what VirtualBox can do. You can use vagrant suspend to put the VM in a saved state, vagrant resume to start it again, vagrant halt to power it off, and vagrant destroy to delete it. You can also use settings in Vagrant's VirtualBox provider to modify your VM's memory, CPUs, and more. You can also change the network settings and synced folders. And this gives you the advantage of defining all of these settings in code which can be checked into a revision control system such as Git.
On top of all this, Vagrant has support for provisioners. These range from something as simple as shell scripts to full blown configuration management tools such as Puppet, Chef, Ansible, and Salt. Just like you can define your VM's VirtualBox settings in code, you can define the entire creation process including installing packages, managing services, and customizing files. And you can make changes at any time and apply them using vagrant provision.
So getting back to your question... yes, you can control your VM directly with VirtualBox, but you'd be missing out on the rich feature set of Vagrant.
Imaging I am running a Virtual Machine guest (VM) managed by Vagrant and hosted by VirtualBox on Windows. What happens if the HOST is abruptly powered off? Is whatever data that has been added/updated to the VM lost? If this is the case, must I run vagrant halt to insure nothing is lost? Perhaps vagrant suspend would be sufficient?
Thank you for any insights or recommendations.
If the host crashes, the VirtualBox VMs will end to aborted state, but in many cases vagrant up should be enough to get them running again.
If you're unlucky and the VM got corrupted it might be that only destroying and creating it again helps. But that's why you make all modifications via provisioners, don't you? =)
vagrant halt or vagrant suspend won't do nothing in this case, as the VM is not running.
And if the host is just shut down normally, the running VMs should be suspended by recent VirtualBox versions.
If the host suffers from a power loss, the same happens to all the running guests as if they were suddenly powered off.
Data loss can happen, but it depends on the file system mount options, results can vary.
For Linux VMs using ext4 as its main file system, I'd recommend using data=journal instead of the default data=ordered and turn write barriers on by using barrier=1. The above can be done in /etc/fstab. This will help to minimize the possibility of data loss but it is NOT 100% guaranteed.
HTH
I like how through vagrant I can spin up my machine, configure it and get to coding. However when I do vagrant halt, and then do a vagrant up again, it rebuilds my machine from the base box. All the new stuff I installed, my project repository is gone.
I can see that the virtual machine still exists in virtual box and I can use it from there, but I want to use vagrant to manage it and access it while keep the persistence of the disk as I would accessing it directly from virtual box. My host is windows, my guest is precise64.
Thoughts?
Stephen
Maybe you want to use vagrant suspend? (via)
I have MAMP server and several test sites installed on my OSX 10.6.3. I just installed Windows 7 on a VirtualBox virtual machine. I have managed to successfully share folders to the Windows installation, but I am wondering if I can run my MAMP sites in Windows without installing a different Localhost there.
Does anyone know if this is possible? It would be very convenient if I could test my sites in both operating systems all hosted from a single location.
Although this is probably too late for the OP, posting here for others.
If you're just trying to access your Mac localhost, then all you need to type into
the guest os is 10.0.2.2.
If you're trying to access named virtual hosts such as 0.dev or dev.local, then you need to modify the guest os host file to map the domain names to the host os.
In the case of Windows 7, you simply navigate to C:\Windows\System32\drivers\etc then modify the hosts file with admin privs.
Inside you will you will see the following line commented out
# 127.0.0.1 localhost
Below it, add entries for each of the virtual hosts you wish to use
10.0.2.2 maclocalhost
10.0.2.2 0.dev
10.0.2.2 dev.local
I just setup three VirtualBox VMs today specifically for connecting to MAMP on an OS X host. Thought I’d share my method of doing this since it works well for me.
While accessing the localhost via 10.0.2.2 I find using a host only network to be a much more flexible & reliable way to handle scenarios. You get a another IP address so debugging network issues on a VM can work as well.
First, go to VirtualBox -> Preferences…. Then choose Host-only Networks. You should have a vboxnet0 adapter in place. If not, add one.
Once you are set with that, select the vboxnet0 adapter & click the small yellow screwdriver icon on the right side of that window to edit the options. Under the Adapter pane, set the IPv4 address to 192.168.56.1 & the network mask to 255.255.255.0. Leave the IPv6 area blank. The IPv6 network mask length should be 0.
The DHCP server stuff should be blank, like so.
Okay? Got that set. Now choose your VM. In my example it’s the IE8 - Win7 image for web development testing. And click the Settings gear. Then click the Network icon. And now choose Adapter 2. And choose Host-only Adapter from the pull down menu for Attached to:. And then choose vboxnet0 under Name:. The rest of the options should just be the standard options.
Now, when you startup your Windows VM, launch Internet Explorer. And go to the address:
http://192.168.56.1
With that, you should be set! But if you are used to using Macs, be 100% sure you have the http:// in front of the address. I got embarrassingly stuck when I just entered the straight 192.168.56.1.
And as Jon Jaques says in his answer you can edit the hosts file in Windows to point to the IP address of 192.168.56.1. It will make your life easier & if you know how to setup named virtual hosts in MAMP (not hard) you can setup a few different sites to test via VirtualBox.
Oh, also, if you are used to using your machine name in OS X to connect to MAMP—like with the name LogicArtist.local if that is your machine’s name—you are not in any luck. The VirtualBox built in software router claims to pass multicast data, but it doesn’t. Check out this post which explains it in more detail.
In the environment created by VirtualBox there are multiple NICs that
claim to be multicast capable. However, they are lying. Furthermore,
because of the way VirtualBox assigns metrics, your outgoing socket
will get assigned to a liar who will happily gobble up your multicast
messages and not send them on.
Annoying, but you can work around stuff like that by at least editing your hosts file to have an entry for LogicArtist.local like this:
192.168.56.1 LogicArtist.local
Definitely not as elegant as a true multicast address being passed, but at least the brief amount of time you will be spending in Windows to debug things will be made easier but adding that entry.
MAMP Pro lets you specify the port for each host. Choose a unique port for your desired host. In your virtual machine simply type http://10.0.2.2:PORTNUMBER and your site will appear. Example: I created a host called localuproar and assigned it port number 9000. In VirtualBox I opened up Internet Explorer and typed http://10.0.2.2:9000, and my site appeared.
You can mess around with hosts files as described in previous posts, but I think it is easier to simply type in a port number.
On a related note, there is a very easy way to create virtual machines for all versions of Internet Explorer (http://osxdaily.com/2011/09/04/internet-explorer-for-mac-ie7-ie8-ie-9-free/):
Launch Terminal
Type this in your terminal window
curl -s https://raw.githubusercontent.com/xdissent/ievms/master/ievms.sh | bash