How to get shared folders working with Vagrant and Hyper-V?
Asked Answered
B

2

7

After:

  1. Enabling Microsoft Hyper-V, as explained here:

https://learn.microsoft.com/en-us/virtualization/hyper-v-on-windows/quick-start/enable-hyper-v

  1. Temporarily disabling my Anti-Virus software (Avast)

  2. Starting my command line program in Admin mode (eg. "Run as Administrator"),

  3. Starting up Vagrant (2.2.3) with a Hyper-V instance:

$ vagrant up

using the following sample Vagrantfile:

Vagrant.configure("2") do |config|
  config.vm.box = "bento/ubuntu-16.04"
  config.vm.provider "hyperv"
  config.vm.network "public_network"
  config.vm.synced_folder ".", "/vagrant", type: "smb"
  config.vm.provider "hyperv" do |h|
    h.enable_virtualization_extensions = true
    h.linked_clone = true
  end
end
  1. Selecting External Virtual Switch for the switch to attach to the Hyper-V instance,

  2. Entering my Windows (Admin) user's username and password when prompted by Vagrant during the startup of the Hyper-V instance

I got the following error:

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t cifs -o uid=1000,gid=1000,sec=ntlm,credentials=/etc/smb_creds_e706...e431 //10.124.157.30/e706...e431 /vagrant

The error output from the last command was:

mount error(112): Host is down
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

How to fix?

Budbudapest answered 19/1, 2019 at 5:48 Comment(1)
You may want to get rid of config.vm.network "public_network" as "networking configurations in the Vagrantfile are completely ignored with Hyper-V" vagrantup.com/docs/hyperv/limitations.htmlRonironica
B
12

Only after I went into:

Settings > Apps & Features > Programs and Features > Turn Windows features on or off

and enabled:

SMB Direct (Remote Direct Memory Access (RDMA) support for the SMB 3.x file sharing protocol)

did Vagrant start up the Hyper-V instance, with my shared folders, successfully.

I haven't gone back to try skipping some of the actions that I did (eg. temporarily disabling Anti-Virus software), but was successful doing all of the above.

After not being able to find this clearly documented ANYWHERE (not on Vagrant's site, Hyper-V site, Stackoverflow, tons of Google searches) and struggling with this issue for countless hours, I just wanted to share this to save others the pain that I went through. Hope this helps!

Budbudapest answered 19/1, 2019 at 5:48 Comment(0)
W
1

I finally found something that worked for me and wanted to share. I'm on a domain joined computer with Windows 10 Pro 1909. I have this in my Vagrant file:

config.vm.synced_folder "C:/projects", "/projects", type: "smb", mount_options: ["domain=mydomain", "user=myusername", "vers=3.0"]

During "vagrant up" it still prompts for credentials so that it can create/prune the file shares. At this prompt I enter the user name in this format: mydomain\myusername

It now successfully mounts my local drive in the VM.

Wallah answered 8/1, 2021 at 18:33 Comment(1)
I had been using that method, but it fails on additional synced folders if you're using the Chef provisioner, as they do not inherit the mount_options values. Setting smb_username to myusername@mydomain (rather than the more traditional Windows format of [email protected]) works perfectly fine.Furman

© 2022 - 2024 — McMap. All rights reserved.