Vagrant over Hyper-V slow shared folder SMB - vagrant

I have a vagrant box that is running on top of hyper-v. All seems to work fine except shared folder. It just incredible slow. Its like stuck on something. I run yarn install and it dint finish even after like a 18 hours of work.. ( it was working and adding new files with with incredible slow speed). I know there a lot of small files ( ~80k was created during yarn install until i cancelled it), but no way it should take 18 hours to create such amount of files, and i have a fast ssd. I tried to copy this files over smb inside windows itself and all copied withing few minutes.
I checked process load when its running, everything near zero. No cpu usage, a lot of free mem.
Host system : windows 10
Guest system : ubuntu 16.04
Here is my vagrant file:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "kmm/ubuntu-xenial64"
config.vm.provider "hyperv"
config.vm.network "public_network"
config.vm.synced_folder 'C:/Dev/PycharmProjects/scrapers', '/opt/scrapers', disabled: false, type: "smb", smb_username: "xxx", smb_password: "xxx", mount_options: ['vers=2.1']
config.vm.synced_folder '.', '/vagrant', disabled: false, type: "smb", smb_username: "xxx", smb_password: "xxx", mount_options: ['vers=2.1']
config.vm.provider "hyperv" do |h|
h.enable_virtualization_extensions = true
h.differencing_disk = true
h.ip_address_timeout = 240
h.memory = 1024
h.cpus = 4
h.vm_integration_services = {
key_value_pair_exchange: true,
}
end
end
I tried mounting with vers=3.0 with the same result.
I even tried to copy that folder on guest machine to another one and it just stuck, it copies like 20 files and then nothing happens after it for few hours.

I have noticed that SMB / CIFS shares into Vagrant Linux guests are extremely slow and unreliable using the "Default Switch" provided with the Windows 10 upgrade to "Fall Creator's Edition" 1709 (Version 10.0.16299 Build 16299.)
If you just upgraded to the latest build of Windows, then you could try using an External Switch instead of the "Default Switch" NAT network. I changed my Vagrant Files back to using an External Switch and it solved* my CIFS performance problems.
* Even with an External Switch, the maximum file transfer speeds I see using
local-to-local rsync from a Linux guest internal filesystem to a CIFS mount from the host is around 10MB/s and typically much slower, so it is still terrible. Just not completely unusable like it is with "Default Switch".

Related

How to use Windows shared folder to be a vagrant synced_folder?

There are 3 machines:
1."desktop"
Windows 10 desktop
(Has the windows shared folder in its hard disk).
NOTE: This is my colleague's machine.
2."laptop"
Windows 10 laptop
(In the same local area network of "desktop", and can read and write the shared folder).
NOTE: This is my machine.
3."vagrant-centos7"
vagrant virtual machine centos7
(a guest machine hosted at "laptop" use vagrant virtualbox provider).
Now my question is like this:
I use "laptop", need make a "desktop" windows shared folder to be a synced folder to "vagrant-centos7".
I tried this vagrantfile setting, but faild.
"z://" is windows map network drive of the "desktop" share folder.
192.168.0.108 is the ip of "desktop"
config.vm.synced_folder "Z://", "/vagrant_data2",
type: "smb",
smb_host: "192.168.0.108",
smb_username: "abc",
smb_password: "123456"
The error message is:
Host path: Z:
Stderr: dev or path not exists.
thanks for any helps :)

Check if NFS is available from within Vagrantfile

I have a Vagrantfile and the default option for mounting on non windows machines is NFS.
if Vagrant::Util::Platform.windows? == false
config.vm.synced_folder ".", "/vagrant", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
end
However we have a developer that didn't have NFS installed on his 'nix box and it took awhile to figure out that was the problem.
Is there a way to check if the host machine has NFS installed in a similar approach from within the vagrantfile?
You can read this https://www.vagrantup.com/docs/plugins/host-capabilities.html The definition and implementation of host capabilities is identical to guest capabilities.

Default shared folder in vagrant not visible

I have a problem with synced folder in Vagrant. My config is really simple:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/xenial64"
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.synced_folder ".", "/vagrant"
end
Vagrant usually creates /vagrant folder automatically on start - this time it did not happen so I've done it manually.
But when I create a file in my host system - it's not visible in guest. Any ideas why?
I've succesfully created a similar configuration with:
config.vm.box = "hashicorp/precise64"
but it's a little bit outdated and I want to use Ubuntu 16.04.
Is it a problem with my config, vagrant box, or something else?
You could try: Make sure you have the latest version of Vagrant and VB. Restart your computer (I know, but it sometimes does help in these cases). Try again in a new directory (or vagrant destroy if you want to start fresh and don't need any old content), i.e., make sure the old .vagrant directory isn't there.
vagrant up or vagrant reload and check again.
Assuming you are using VirtualBox, make sure you don't have any "Guest Additions" issues. You could try https://github.com/dotless-de/vagrant-vbguest
If it still doesn't work, check the --debug output again as #frédéric-henri mentioned -- look for all mentions of your share name. Also "/vagrant" isn't always the default, it depends on the box. Sometimes it's "/vagrant_data" or others, but if you specify "/vagrant" in the config -- that should work.

Vagrantfile: Disabling synced folders for one provider, but not another

I have been using Vagrant with VirtualBox for local development. Now, I want to deploy to Azure (question would be same with AWS).
When working locally with VirtualBox, it's awesome to have the synced folder. But I definitely don't want a synced folder for the cloud VM. So, how can I have it enabled for the former but disabled for the latter?
A snippet of my vagrantfile is below; however this doesn't seem to have any effect. Appreciate any pointers.
Vagrant.configure('2') do |config|
config.vm.synced_folder ".", "/vagrant"
# …
config.vm.provider :azure do |azure, override|
override.vm.synced_folder ".", "/vagrant", disabled: true
# …
End
# …
end
I've also tried initially disabling the synced folder, and then enabling it only for VirtualBox - but Azure still prompts for username/password and attempts to create an SMB share.
Update: Even if I disable it in the main section, and don't touch it for Azure, it still tries to create a SMB share, and complains that it can't find my machine (my laptop is behind NAT).
It turns out that the default synced folder was indeed being disabled correctly.
However, the Chef provisioner was being used, and behind the scenes this also uses synced folders! The solution therefore is to use a Chef server, or as I chose - to do everything via a shell provisioner.
Hope this question helps someone encountering this problem in the future.
I had the same problem with SMB synced folders not staying disabled even though I hade the correct lines to disable.
My problem was also caused by chef enabling synced folders again. I solved my problem by adding the chef.synced_folder_type = "rsync" to the chef config block:
config.vm.provision :chef_solo do |chef|
chef.synced_folder_type = "rsync"
[...more chef config...]
end

How to use vagrant in development and how to use shared folders?

I (a struggling newbie in vagrant) have done setup a vagrant environment for development. i have been provided with vagrant file
Vagrant.configure("2") do |config|
config.vm.box = 'precise64'
config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
config.vm.network :forwarded_port, guest: 80, host: 8080
config.vm.provision :puppet do |puppet|
puppet.module_path = "config/puppet/modules"
puppet.manifests_path = "config/puppet/manifests"
puppet.manifest_file = "base.pp"
end
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
end
end
the config/puppet/manifests contains following base.pp file
Exec {
path => "/usr/bin:/bin:/usr/sbin:/sbin"
}
stage { 'first':
before => Stage['main']
}
class {
'system': stage => first;
'mysql': stage => main;
'apache': stage => main;
'php': stage=> main;
'git': stage=> main;
'cake': stage=> main;
}
and config/puppet/modules containing directories apache,cake,git,mysql,php and system.
What i did so far is
1) Installed VirtualBox
2) Installed Vagrant
3) Vagrant up (as specified everywhere in net)
What i got is
1) a virtualbox (having no GUI)
2) SSH connection to virtaul box
3) and a shared folder.
now i have some questions so that i can understand it well
1) Am i going in right direction in order to setup vagrant?
2) What is precise64.box(just console box), can't i add ubuntu as a box and everything set up(i.e. php, apache n other modules specified in puppet modules) in that ubuntu?
3) Where does puppet install all these modules? in Host(Windows) or in Guest(precise64)?
4) What config.vm.network :forwarded_port, guest: 80, host: 8080 do?
5) what does shared folder do? and where does the shared folder reside in virtual box(precise64) and what i could/should do with this shared folder?
6) where do i install Netbeans/Eclipse in order to develop my code?
7) Any references/blog that describe vagrant and its advantages in and out?
I am trying to understand but couldn't figure it out how to understand vagrant (as a developer) and develop something. Any help or explanation would be appreciable and i guess these could be most common points that is hard for any newbie to understand.
1) Yes, looks like you're doing everything right to me. There's really no right or wrong if it works, your config looks pretty standard. (Not sure about your puppet config...I've never used that)
2) .box files are basically install cds that are packaged specifically for vagrant. In this case, you're downloading and installing http://files.vagrantup.com/precise64.box, which is essentially a bare-bones off the shelf ubuntu 12.04 64 bit server. You can find other prepackaged boxes here. The point of vagrant is to be able to start with a barebones OS and built it up by use of provisioning files (chef, puppet, bash, etc.).
3) Everything in vagrant is very self contained within the VM its creating, I don't know much about puppet but I would assume it works much the same way that the bash provisioning files I use work. It boots the VM, then runs your provisioning scripts within the VM so that you have a reproducible VM creation process.
4) Port forwarding. guest: 80, host :8080 means that anything within the VM (guest) serving on port 80 will be available on the host (your pc) at http://localhost:8080.
5) Shared folders are AWESOME. Basically, your VM will have access to a folder from your host machine which is incredibly helpful for question number 6. Doing something like:
config.vm.synced_folder "src/", "/vagrant"
will make the src directory in your project (on the host) available to the vm at the mount point /vagrant. So you can have an IDE installed on your host, edit files in src and they'll automatically be available in your VM at /vagrant. More on that here.
6) On your host machine. See answer to number 5.
7) Perhaps google is your best friend for this one. The biggest advantage for me is that we can check our Vagrantfile into our git repo next to the rest of our application code and any new member of our team can have the application running locally within minutes by navigating to the directory and running vagrant up. Mess something up within the VM and need to start fresh? vagrant destroy -> vagrant up. Not having to install a bunch of packages specific to an application on your host machine is invaluable.

Resources