Failing to create SMB shared folder using Vagrant on Windows host with linux guest - vagrant

I'm using Vagrant to create an Ubuntu 14.04 guest on my Windows 7 SP 1 PC. This has been working ok, but the performance of the guest is poor when accessing files that have been synchronized from the host. After doing some reading, I'm trying to make the synchronized folder an SMB share, however this is failing when I run 'vagrant up'
Note that I've upgraded to powershell 3.0, as documented in https://docs.vagrantup.com/v2/synced-folders/smb.html. I've also ensured that my guest has cifs-util installed as pointed out in https://github.com/mitchellh/vagrant/issues/4642. I'm using Vagrant 1.7.4 and VirtualBox 4.3.28
My Vagrantfile looks like this:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "npt"
config.vm.provider "virtualbox" do |v|
v.customize ["modifyvm", :id, "--cpuexecutioncap", "90"]
v.customize ["modifyvm", :id, "--memory", "4096"]
v.customize ["modifyvm", :id, "--cpus", 2]
end
config.vm.synced_folder "\\", "/npt_root", type: "smb"
config.vm.provision :shell do |shell|
shell.inline = "puppet module install puppetlabs/vcsrepo --force"
end
config.vm.provision "puppet" do |puppet|
puppet.manifests_path = "puppet"
puppet.manifest_file = "basic_build_reqs.pp"
end
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
end
And the output I am seeing is:
Z:\npt\vagrant>vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'npt'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: vagrant_default_1442502969737_66801
==> default: Preparing SMB shared folders...
default: You will be asked for the username and password to use for the SMB
default: folders shortly. Please use the proper username/password of your
default: Windows account.
default:
default: Username: tdj#DCL
default: Password (will be hidden):
Exporting an SMB share failed! Details about the failure are shown
below. Please inspect the error message and correct any problems.
Host path: Z:/
Stderr: System error 123 has occurred.
The filename, directory name, or volume label syntax is incorrect.
Error:
Stdout:
It looks like Vagrant has interpreted the relative path "\" I've given it and is coming up with "Z:/", with unix style slashes, which Windows is then failing to parse.
Note that I've tried replacing the relative path with the absolute path "Z:\", but I still see the same output on the "Host path" line

I suspect "\\" is the problem in the following line:
config.vm.synced_folder "\\", "/npt_root", type: "smb"
Could you try to put in a concrete foldername that you would like to share with your VM and test if it works?

Related

Can I force provisioning to happen before mounting shared folders in Vagrant?

I have the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "centos/6"
config.vm.provision :shell, :path => "bootstrap.sh"
config.vm.network :forwarded_port, host: 8080, guest: 80
config.vm.network :forwarded_port, host: 3306, guest: 3306
config.vm.synced_folder "../../applications", "/var/www/html", :owner=>"apache", :group=>"apache"
config.vm.provider :virtualbox do |vb|
vb.customize ["modifyvm", :id, "--memory", 2048]
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
vb.name = "appserver"
end
end
Each time I run vagrant up (for first time, let's say that first I ran vagrant destroy -f) I end up with the following error:
==> default: Mounting shared folders...
default: /vagrant => E:/Development/vagrant/centos6
default: /var/www/html => E:/Development/applications/arx
Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
id -u apache
The error output from the command was:
id: apache: No such user
The error is pretty clear "apache user does not exists". As I am seeing this there is two or "three" ways to fix this:
By removing the :owner=>"apache", :group=>"apache" portion from the synced_folder. This is a BIG no, at least for me because if I remove them then the folder will be owned by vagrant which will/could cause issues while apache tries to read something from /var/www/html.
By commenting the line config.vm.synced_folder, getting up the box so everything gets installed and setup, then shutting down the box and getting up again with the line uncommented: it works but still an ugly solution
By forcing the provisioning to happen before anything gets mounted: the ideal solution.
Does any know if this is possible and if so how? I wasn't able to found anything regarding the 3rd solution :( if you have a better solution you're more than welcome to post here it might help me and others probably.
I have found this and this but is not helpful.
one potential solution would be to run apache as vagrant user.
In your /etc/httpd/conf you can replace the User and Group value as
User vagrant
Group vagrant
so you can continue sharing your folder with vagrant user and httpd will be run as vagrant user.
You can use numeric ids and then create an user
config.vm.synced_folder '${HOSTDIR}', '${EXPORTDIR}', type: "virtualbox", owner: '123', group: '456'
config.vm.provision :shell, inline: "useradd --system -g '456' -u '123' -d '${EXPORTDIR}' --shell /bin/false apache"

Vagrant Vagrantfile config

I have this vagranfile for box "centos/7"
Vagrant.configure("2") do |config|
config.vm.box = "centos/7"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.synced_folder ".", "/home/vagrant"
config.vm.provision "shell", path: "./conf/bitrix-env.sh"
config.vm.boot_timeout = 100
config.vm.provider :virtualbox do |vb|
vb.gui = true
vb.memory = "1024"
end
end
vagrant up - command works clear, but scripts in provision don't install
after i tried to start vagrant provision, but had an error:
SSH is getting permission denied errors when attempting to connect
to the IP for SSH. This is usually caused by network rules and not being
able to connect to the specified IP. Please try changing the IP on
which the guest machine binds to for SSH.
How can i fix this and install all provisions?
The problem is due to the below line in your vagrantfile
config.vm.synced_folder '.', '/home/vagrant'
The authorized_keys file for the vagrant user is located in /home/vagrant/.ssh inside the vagrant machine, which enables to ssh into the vagrant box.
As you are mounting your current directory to /home/vagrant, all the contents of /home/vagrant are over-written and there is no authorized key file.
Change the mount path to anything except /home/vagrant, and you will able to ssh into the machine. As example
config.vm.synced_folder '.', '/home/vagrant/somepath'

Setting vagrant home directory during provisioning

I have a VM that I'm pulling down with vagrant and using a VERY basic vagrant file
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://atlas.hashicorp.com/search.
config.vm.box = "vagrant-rhel-devel"
config.vm.network :private_network, ip: "192.168.33.101"
config.vm.synced_folder ".", "/vagrant"
config.ssh.username = "vagrant"
config.ssh.password = "vagrant"
config.vm.provider "virtualbox" do |vb|
# Display the VirtualBox GUI when booting the machine
# vb.gui = true
# Enable 3d Rendering
vb.customize ["modifyvm", :id, "--accelerate3d", "on"]
# Sets 32megs video ram, higher number here = more POWERS
vb.customize ["modifyvm", :id, "--vram", "32"]
# # Customize the amount of memory on the VM:
# vb.memory = "1024"
vb.name = "RedHat 3D"
end
end
My issue is that the vagrant user gets a home directory of /localhome/vagrant and I'd like him to have /home/vagrant as the home directory.
Is this something I'm able to change with provisioning or is it something that is set in the VM itself? I'm rather unskilled at the provisioning step at the moment so an example would be great.
The HOME directory has been set when the user has been created so this was done before the VM was packaged as vagrant box.
From there, you should be able to change that with
usermod -m -d /path/to/new/home/dir userNameHere
so in your case it would be
usermod -m -d /home/vagrant vagrant
check if you have existing files under the /localhome directory that would need to be copied into the new one (bash preferences file)
if you do not plan to destroy/create a bunch of new VM from this box, its not needed to add as provisioning; if you do plan to use this box and create lot of new VM, then it could make sense, you would just need to add an inline shell provision

How do I provision a Windows guest using the Vagrant shell/path provisioner?

I am trying to use Powershell to provision a Windows Vagrant machine. I've verified that my script works on my local machine if I launch Powershell as an Administrator. During the Vagrant provisioning process, the vagrant user cannot elevate and run the script.
I know powershell scripts are supported with Vagrant, so what needs to happen to use them for provisioning? My initial thought is try to have the script to launch an new Administrator Powershell, but I feel there must be a better way.
I'm trying to just download a file using System.Net.WebClient and using msiexec to install.
Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
PROVISION_WIN7_SCRIPT = "provision_win7.ps1"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define "win7", primary: false do |win7|
config.vm.provision "shell", :path => "#{PROVISION_WIN7_SCRIPT}"
config.vm.box = "win7"
config.vm.hostname = "win7"
config.vm.communicator = "winrm"
config.vm.network :private_network, ip: "10.10.10.10"
config.vm.box_url = "https://atlas.hashicorp.com/designerror/boxes/windows-7/versions/1.0/providers/virtualbox.box"
config.vm.provider :virtualbox do |vb|
vb.gui = true
vb.customize ["modifyvm", :id, "--memory", 1024]
vb.customize ["modifyvm", :id, "--cpus", 1]
vb.customize ["modifyvm", :id, "--vram", "32"]
vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]
vb.customize ["setextradata", "global", "GUI/SuppressMessages", "all" ]
end
end
end
Edit:
I tried this again today using what I was running at the time: Vagrant 1.6.3, Virtualbox 4.3.30. When I bring up my vagrant box, I do not see any error output:
Bringing machine 'win7' up with 'virtualbox' provider...
==> win7: Importing base box 'designerror/windows-7'...
==> win7: Matching MAC address for NAT networking...
==> win7: Checking if box 'designerror/windows-7' is up to date...
==> win7: Setting the name of the VM: vagrant_win7_1453859492744_23074
==> win7: Clearing any previously set network interfaces...
==> win7: Preparing network interfaces based on configuration...
win7: Adapter 1: nat
win7: Adapter 2: hostonly
==> win7: Forwarding ports...
win7: 3389 => 3389 (adapter 1)
win7: 22 => 2222 (adapter 1)
win7: 5985 => 55985 (adapter 1)
==> win7: Running 'pre-boot' VM customizations...
==> win7: Booting VM...
==> win7: Waiting for machine to boot. This may take a few minutes...
==> win7: Machine booted and ready!
==> win7: Checking for guest additions in VM...
==> win7: Setting hostname...
==> win7: Configuring and enabling network interfaces...
==> win7: Mounting shared folders...
win7: /vagrant => /Users/dstark/Projects/itbestprac-pres/vagrant
==> win7: Running provisioner: shell...
win7: Running: c:\tmp\vagrant-shell.ps1
On my vagrant box under c:\tmp there's a vagrant-shell.ps1 and vagrant-elevated-shell.ps1 and if I manually execute the vagrant generated elevated shell ps script as the vagrant user it installs. So, I think my script is ok.
If I add the config.winrm.username and config.winrm.password I still am not able to elevate permissions necessary to run the script. There's also nothing telling in the Event Viewer.
Possibly you need to add the privileged flag to the provision line:
config.vm.provision "shell", path: "scripts/provision.ps1", privileged: true
Or in your case:
config.vm.provision "shell", :path => "#{PROVISION_WIN7_SCRIPT}", privileged: true

bosh-lite vagrant up fails with no error

I am trying to setup a local cloud foundry instance using bosh-lite on my mac osx laptop V 10.9.4.
sh-3.2# vagrant -v
Vagrant 1.7.1
sh-3.2#
I unzipped the contents of bosh-lite-master
ran the following command
see below
sh-3.2#vagrant up --provider=virtualbox
Error Message I got
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'cloudfoundry/bosh-lite' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: 2776
The box 'cloudfoundry/bosh-lite' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Atlas, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:
URL: ["https://atlas.hashicorp.com/cloudfoundry/bosh-lite"]
Error:
sh-3.2#
The error part is empty and I am completely clue less as this is the first time I am working with vagrant
Content of the vagrant file
Vagrant.configure('2') do |config|
config.vm.box = 'cloudfoundry/bosh-lite'
config.vm.box_version = '2776'
config.vm.provider :virtualbox do |v, override|
# To use a different IP address for the bosh-lite director, uncomment this line:
# override.vm.network :private_network, ip: '192.168.59.4', id: :local
end
[:vmware_fusion, :vmware_desktop, :vmware_workstation].each do |provider|
config.vm.provider provider do |v, override|
# To use a different IP address for the bosh-lite director, uncomment this line:
# override.vm.network :private_network, ip: '192.168.54.4', id: :local
override.vm.box_version = '388'
end
end
config.vm.provider :aws do |v, override|
# To turn off public IP echoing, uncomment this line:
# override.vm.provision :shell, id: "public_ip", run: "always", inline: "/bin/true"
# To turn off CF port forwarding, uncomment this line:
# override.vm.provision :shell, id: "port_forwarding", run: "always", inline: "/bin/true"
end
end
Please read https://github.com/mitchellh/vagrant/issues/3589
commenting out this block from /opt/vagrant/embedded/gems/gems/vagrant-1.7.1/lib/vagrant/util/subprocess.rb made it work like a charm
if #command[0].downcase.include?(installer_dir)
#logger.info("Command in the installer. Specifying DYLD_LIBRARY_PATH...")
process.environment["DYLD_LIBRARY_PATH"] =
"#{installer_dir}/lib:#{ENV["DYLD_LIBRARY_PATH"]}"
#logger.info("process.environment")
#logger.info(process.environment["DYLD_LIBRARY_PATH"])
#logger.info("end process.environment")
else
#logger.debug("Command not in installer, not touching env vars.")
end

Resources