Homestead with HyperV unable to create SMB folders - mount error(2): No such file or directory - vagrant

After running vagrant up I get the following error message.
Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
==> homestead: Setting hostname...
==> homestead: Mounting SMB shared folders...
homestead: C:/Code => /home/*****/code
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 vers=3.02,credentials=/etc/smb_creds_vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727,uid=1000,gid=1000,mfsymlinks,_netdev,nofail //169.254.x.x/vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727 /home/*****/code
The error output from the last command was:
mount error(2): No such file or directory
I am able to ssh into the HyperV instance and when I run the command it returns the same. If I look at the properties of C:/Code folder I can see the network path is \\PCNAME\vgt-07cc5c30ef2cc20d12e837c88c36370a-66f0bd5cbca4d218f5f0b8a5f1712727 so the same as the mount command other than the PCNAME is now an IP. I can ping the IP from within the instance and seems to work ok.
Homestead file:
folders:
- map: C:/Code
to: /home/vagrant/code
type: smb
smb_username: vagrant
smb_password: vagrant
The vagrant user has full permissions to the local code folder.
I am running Windows 11, Vagrant 2.3.1, HyperV 10. The External Switch is set-up via my Wi-Fi - could that cause an issue?

Related

Vangrant on Windows 10 with Hyper-V cannot mount SMB shared folder

Problem
I'm struggling to have vagrant mounting shared folders via SMB.
Environment
Windows 10 Pro with Hyper-V and SMB features enabled
Vagrant 2.2.6 with vagrant-vbguest (0.21.0, global) plugin
Homestead.yaml file
ip: "192.168.10.10"
memory: 2048
cpus: 2
provider: hyperv
authorize: c:/Users/sgrat/.ssh/id_rsa.pub
keys:
- c:/Users/sgrat/.ssh/id_rsa
folders:
- map: Sites/mysite
to: /home/vagrant/mysite
php: '7.3'
type: "smb"
smb_host: 127.0.0.1
smb_username: vagrant
smb_password: vagrant
sites:
- map: mysite.test
to: /home/vagrant/mysite
databases:
- mysitedb
features:
- mariadb: true
- ohmyzsh: false
- webdriver: false
Error
Vagrant requires administrator access to create SMB shares and
may request access to complete setup of configured shares.
==> homestead: Setting hostname...
==> homestead: Mounting SMB shared folders...
homestead: C:/Users/sgrat/Desktop/Sites/Homestead => /vagrant
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 vers=2.0,credentials=/etc/smb_creds_vgt-4a666e6cffbb30e1d0bc7bb643cb3aee-6ad5fdbcbf2eaa93bd62f92333a2e6e5,uid=1000,gid=1000 //192.168.1.14/vgt-4a666e6cffbb30e1d0bc7bb643cb3aee-6ad5fdbcbf2eaa93bd62f92333a2e6e5 /vagrant
The error output from the last command was:
mount error(13): Permission denied
Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Additional attempts
I also installed vboxsf fs on guest machine after vagrant ssh with sudo apt-get install virtualbox-guest-x11 and even checked for last cifs-utils version.
I even created a local/admin user with name/password vagrant and granted all privilages on both "Sites" folder and "Sites" shared folder.
Update #1
Shared "Sites" folder on Windows host, so updated homestead shared folder path to start from that instead from C: drive.
Is it correct?

copy file from host to vagrant virtual machine

I am new with virtual machine. I want to copy a file from host (Mac) to vagrant virtual machine. I could not share a folder, so I want to use command line. How can I copy a file from host to vagrant virtual machine with command line?
To copy a file from the host to vagrant:
scp -P 2222 /path/to/file vagrant#127.0.0.1:.
By default The vagrant instance uses port 2222 and ip 127.0.0.1. The password for vagrant is 'vagrant'.
The file will be copied to the home of vagrant.
To copy a file from vagrant to host machine:
scp -P 2222 vagrant#127.0.0.1:/path/to/file
one easy way is to let vagrant handles the copy through the File Provisioner :
config.vm.provision "file", source: "~/.gitconfig", destination: ".gitconfig"
If you really want to use a command line, it might be dependant on your VM, assuming you have linux based VM, you could use scp and copy the file through ssh. see https://unix.stackexchange.com/a/106482
There is an officially supported command vagrant upload:
vagrant upload source [destination] [name|id]

Laravel 5.3 Homestead Installation on Win 10

Following >> https://laravel.com/docs/5.3/homestead
bash init.sh
cp: overwrite '/c/Users/myuser/.homestead/Homestead.yaml'? y
cp: overwrite '/c/Users/myuser/.homestead/after.sh'?
cp: overwrite '/c/Users/myuser/.homestead/aliases'?
Homestead initialized!
I don't know if these needs to be overwritten ?
Also , I configure homestead.yaml
folders:
- map: ~/Homestead
to: /home/vagrant/Code
It is showing error[The host path of the shared folder is missing: ~/Homestead]
My homestead installation is
$ pwd
/Homestead
I am sure some steps are missing can someone help
Installation method - Per Project Installation
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'laravel/homestead' is up to date...
==> default: Running provisioner: shell...
SSH authentication failed! This is typically caused by the public/private
keypair for the SSH user not being properly set on the guest VM. Please
verify that the guest VM is setup with the proper public key, and that
the private key path for Vagrant is setup properly as well.
It is a fresh installation !
vagrant destroy && up
default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default: Warning: Remote connection disconnect. Retrying...
default: Warning: Authentication failure. Retrying...
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.
Yes, you should overwrite these files so as to have a clean installation of Homestead (just in case). Now, the reason you are getting this error is because your YAML configuration is wrong. Assuming you have your Laravel code in a Code folder in your Documents folder, your YAML should look like this (NB: this is Windows specific!):
folders:
- map: "C:/Users/Username/Documents/Code"
to: "/home/vagrant/Code"
You need to map the folder containing your local code to a folder in your virtual machine. This will then be set up using shared folders. This way, any code changes in your Code folder will be mirrored to your VM.
Personally, I prefer the Per Project Installation because I can have multiple projects running on different VMs mapped to different domains, at the same time. Check it out here: https://laravel.com/docs/5.3/homestead#per-project-installation

How to setup Laravel Homestead server to run locally without being on a network/internet?

Previously, I manually setup my own VM on VirtualBox and configured it so it would also work when I'm coding offline (no internet/not connected to a router). I did this using settings in the VirtualBox GUI and also in Apache on the VM.
Now I'm interested in learning nginx and I've decided to try and use Laravel's Homestead. The tutorials I'm looking at seem to have the assumption I will be accessing the Homestead VM across the network (even though of course it's on the same PC). What do I need to do to ensure the VM will be accessible when I'm offline (like when I'm coding on a plane or train)? I'd like to still be able to have access to the internet from the VM whenever I do get back on WiFi (ie. for apt-get, etc.).
(note: My host machine is running Windows 7 64-bit)
Download and install fresh copies of Vagrant and Virtualbox.
https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
http://dlc-cdn.sun.com/virtualbox/4.3.22/VirtualBox-4.3.22-98236-Win.exe
Also download laravel/homestead manually
https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.2/providers/virtualbox.box
to my downloads folder C:\Downloads\homestead-0-2-2.box
After Installing Virtualbox and Vagrant. Installed laravel/homestead by running the following command in git bash (you can download git bash here: http://git-scm.com/downloads).
vagrant box add laravel/homestead /c/downloads/homestead-0-2-2.box
Run this command inside C:\users\yourusername
git clone https://github.com/laravel/homestead.git Homestead
NB: This will create this folder: C:\Users\yourusername\Homestead
With some files.
Still in Git bash, cd into C:\Users\yourusername\Homestead and run this command:
bash init.sh
NB: this will create a folder C:\Users\yourusername\.homestead that contains Homestead.yaml and some other files
Then Generate an SSH key which you will need when you want to login to your VM by running this command:
ssh-keygen -t rsa -C "youremailaddress#youremail.com"
NB: This will ask some question simply hit enter or type yes and hit enter.
This will create your ssh key inside C:\Users\yourusername\.ssh
Then you need to configure homestead by editing for Nginx
C:\Users\digitlimit\Homestead\Homestead.yaml
You can right-click Homestead.yaml file then click open then choose to open with wordpad.
My Homestead.yaml looks this after editing:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /wamp/www
to: /home/vagrant/Code
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
NB: To understand the mapping which is a process of sharing a folder between the host and the VM:
My laravel project is located at C:\wamp\www\laravel
This directory /home/vagrant/Code will be inside the VM after installation.
So what am telling VM is, whenever you see /home/vagrant/Code reference this folder C:\wamp\www\laravel
Also in this:
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
What we are saying here is when i go to my browser and type http://laravel.dev display the content of /home/vagrant/Code/laravel/public which is actually pointing to C:\www\wamp\laravel\public
After editing Homestead.yaml file save your chnages
NB: Before we can use http://laravel.dev in the host web browser to view our laravel project, we need to add this the following to the hosts file located in
C:\Windows\System32\drivers\etc\hosts
Add this ip address under the list of other ip address listed if any:
192.168.10.10 laravel.dev
Finally, go back to your Git bash, ensure you are in
/c/Users/yourusername/homestead and type:
vagrant up
Wait for vagrant to complete its processes. Click yes when you see any dialog box asking for permission to create network adapter on your system
Any VM running on your development machine will be accessible when you're offline. Just make sure you setup your development machine's host file to have the VM's location set.
If you're following the Laravel Homestead Setup:
In scripts/homestead.rb, you'll have a line that has the IP Address of the VM.
# in scripts/homestead.rb
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
Add this IP address into to your hosts file. This is located usually in C:\Windows\System32\drivers\etc\hosts
#in hosts file
192.168.10.10 yourwebsite.dev

Use nfs to for default folder with vagrant

I want to migrate a big project (5000 files) to vagrant with virtualbox.
Virtualbox shared folders is known to be slow for big project, so I want to use NFS.
But, I don't find the right way to use NFS instead of the default shared folder issue. It works when I put code in another folder, and share it. But I want to integrate Vagrant in the current one.
config.vm.synced_folder '.', '/vagrant', nfs: true
doesn't work:
exportfs: duplicated export entries:
exportfs: 10.11.12.13:/home/vincent/workspace/gp
exportfs: 10.11.12.13:/home/vincent/workspace/gp
Any idea to solve this strange issue?
Thank you.
Update 1
Same error with these parameters
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.synced_folder ".", "/home/vagrant/gp", nfs: true
Here is the full error stack:
nfsd running
exportfs: duplicated export entries:
exportfs: 10.11.12.13:/home/vincent/workspace/gp
exportfs: 10.11.12.13:/home/vincent/workspace/gp
==> default: Mounting NFS shared folders...
Vagrant::Errors::LinuxNFSMountFailed: The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mount -o 'vers=3,udp' 10.11.12.1:'/home/vincent/workspace/gp' /home/vagrant/gp
Stdout from the command:
Stderr from the command:
stdin: is not a tty
mount.nfs: access denied by server while mounting 10.11.12.1:/home/vincent/workspace/gp
You may need to explicitly disable the default synced folder by adding the following line in your Vagrantfile so as to mount the NFS share to /vagrant
config.vm.synced_folder ".", "/vagrant", disabled: true
After than do a vagrant reload and see if it works.
In addition, consider using rsync type synced folder for your use case, I think it works even better. See https://docs.vagrantup.com/v2/synced-folders/rsync.html
You can also get this error message if you are trying to create a vm in a directory above another previously created vm. You will need to destroy the the vm's in each sub-directory.

Resources