SSH timeout on vagrant up with Windows 10 + WLS2 (virtualbox_WSL2 plugin installed)

I’m getting an SSH timeout error running vagrant up

Here’s the output :

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/ubuntu-20.04' version '202112.19.0' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: hostonly
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 172.24.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
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.

I have installed the virtualbox_WSL2 plugin as recommended on other posts but I keep having the same timeout issue.

I don’t know if this is relevant but I have the Hyper-V checkbox disabled on Windows Features while Windows Hypervisor Platform is enabled.

Any suggestion?

Thanks in advance.

Hi Lefevre_Christophe,

did you mount the drive via DrvFS? (like /mnt/c/dev)? If so, did you updated your wsl.conf file?

Hi Dome,

my d: drive was mounted by default during WSL2 installation I guess.

This is my wsl.config :

[automount]
options = "metadata,umask=22,fmask=11"

Thanks for sharing.

Please replace the content by the following:

[automount]
enabled = true
options = "metadata,uid=1000,gid=1000,umask=0022,fmask=11,case=off"
mountFsTab = false
crossDistro = true

[filesystem]
umask = 0022

[network]
generateHosts = true
generateResolvConf = true

[interop]
enabled = true
appendWindowsPath = true

Got this from so and its mostly about the interop i think so.

I replaced my wsl.conf with your code and ran a vagrant up again with the same timeout error.

Hm, sad.

Some other questions:

  1. Do you run a Ubuntu VM?
  2. Did you installed vagrant inside VM?
  3. Did you installed Oracle VirtualBox in Windows Host?
  4. Did you modified your shell-rc file (like ~/.bashrc or ~/.zshrc) by entering the following:
# append those two lines into ~/.bashrc
echo 'export VAGRANT_WSL_ENABLE_WINDOWS_ACCESS="1"' >> ~/.bashrc
echo 'export PATH="$PATH:/mnt/c/Program Files/Oracle/VirtualBox"' >> ~/.bashrc

# now reload the ~/.bashrc file
source ~/.bashrc

Another experience I had was to open VirtualBox on Host while initial provision, until key exchange is done. But this is just an experience.

Thanks

  1. Yes I run a Ubuntu VM
  2. Yes I installed vagrant on Windows and inside WSL
  3. I opened the Windows Host file and could not find any reference to my VM. What should I add there?
  4. Yes the .bashrc file already contains those 2 lines.

The host file might be the culprit indeed but I’m not too sure about what to add there.

I don’t think its about the host file, since it’s modified in a later step. In Windows it will not be created by default, just FYI.

Since you’re working in another folder/drive than "c:\users{$USERHOME} you have to add another line to your .bashrc:

export VAGRANT_WSL_WINDOWS_ACCESS_USER_HOME_PATH="/mnt/d/DEV"

(Please replace the mounting home path to your dev folder)

PS:
After trellis run completely please look into /etc/hosts in Ubuntu about your vm’s IP, with those entries you’re able to update the Windows host file as well.

I added your line to my .bashrc, reloaded it and ran trellis but the /etc/hosts file does not contain any reference to the VM to which I’m trying to connect. This being said there are references to old VMs, they’re all using the same IP, so should I add manually my VM to the hosts?

Did you reprovisioned the VM? Just asking, since it reached a nearly final state in the view of vagrant. Did it went through the SSH login step?

I tried reprovisiong and ran into this error message

vagrant provision
==> default: Running provisioner: ansible_local...
An error occurred in the underlying SSH library that Vagrant uses.
The error message is shown below. In many cases, errors from this
library are caused by ssh-agent issues. Try disabling your SSH
agent or removing some keys and try again.

If the problem persists, please report a bug to the net-ssh project.

Net::SSH::ConnectionTimeout

My SSH problem was caused by Windows Defender firewall blocking connections to the protected network. I was able to solve the issue by removing vEthernet (WSL) for each of the Domain, Private, and Public profiles as described here : https://github.com/microsoft/WSL/issues/4139#issuecomment-732665787.

Now I’m having a missing mysql extension error but this is another story.

3 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.