Mounting a symlinked folder in vagrant & virtualbox - windows

Okay, so here is my problem:
I use vagrant with VirtualBox. The host is Windows 8.1, the guest is Ubuntu (64bit). I am trying to use a symlinked windows folder created by
mklink /j somefolder someotherfolder
as synced folder in Vagrant. In my Vagrantfile I have
# disable the default synced folder
config.vm.synced_folder ".", "/vagrant", disabled: true
# sync my desired folder
config.vm.synced_folder "./somefolder", "/vagrant"
Unfortunately this does not work, but gives 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 vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3`
vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
The error output from the last command was:
stdin: is not a tty
/sbin/mount.vboxsf: mounting failed with the error: Invalid argument
Before you ask: Guest additions are installed, and mounting regular folders works flawlessly.
Is there a way to use symlinked directories as synced folders in vagrant with vbox?
Thanks for your help!

I was having a similar issue. I couldn't get Symlinks working with vagrant but a Hardlink Clone did. I was trying to have my Dev folder in sync with Google Drive but did not want to relocate the folder.
My Solution: Hardlink Clone
Download and install Linkshell for windows (and the listed prerequisite package) [ direct Link to actual file I downloaded | direct link to prerequisite package I downloaded ] Direct link good for Windows XP64,
Windows Vista64,
Windows Server ,
2003/2008/20012 64bit,
Windows 7/8/10 64bit
Right click on source folder (in my case the one I copied to Google drive) and select pick link source
In location where you want your "symlink", right click and select Drop as -> Hardlink Clone
Thats what it took for me to get it working with vagrant. I originally tried as symbolic link without success.

Cut the folder to where you need it from the VM, after that create the junction (or symlink) at the original location.

Related

how to get files from host machine to vagrant VM (MAC OS)

I haven't used vagrant for a while so I am racking my brains out on this one.
I know for a fact that one way to "exchange files" between the host machine and the vagrant VM is to copy any file you need into the host machine's vagrant folder that holds the Vagrantfile - the SAME folder where you run 'vagrant up' and 'vagrant ssh' to get connected to the /home/vagrant folder (indicating that you have entered the vagrant vm). However, when I get into the vagrant vm folder /home/vagrant I do not the files that I added in the host machine's vagrant folder.
I tried another approach by going in the vagrant vm's default folder /home/vagrant and run 'touch hello.txt'. Then I checked the host machine's vagrant folder using Finder and nope, I don't see hello.txt file either.
Appreciate any helpful inputs.
I finally found it...
Inside the Vagrantfile file, look for the following config setting:
config.vm.synced_folder
And mine's actually set as:
config.vm.synced_folder ".", "/vagrant"
When I gone back to check the /vagrant (NOT /home/vagrant) folder in my vagrant vm, there i found the files that I placed in my host machine's vagrant folder.
Although I wonder what the "." means - but in the meantime, I'm happy I found what I needed :)

ln: failed to create symbolic link: Protocol error (in Vagrant)

I'm using Laravel Homestead (Vagrant, Ubuntu). My host computer is Windows 10 running VirtualBox.
As admin (since I've already seen tons of answers that say lack of permissions is usually why people have problems with symlinks), I open Git Bash and run this:
vagrant#vboxHomestead:~/Code/myproject$ ls -lah /home/vagrant/foo/blah
total 0
drwxrwxrwx 1 vagrant vagrant 0 Mar 17 23:09 .
drwxrwxrwx 1 vagrant vagrant 0 Mar 17 22:36 ..
-rwxrwxrwx 1 vagrant vagrant 0 Mar 17 23:09 asdf.txt
vagrant#vboxHomestead:~/Code/myproject$ sudo ln -s /home/vagrant/foo/blah /home/vagrant/Code/myproject/storage/app/public/blah
ln: failed to create symbolic link '/home/vagrant/Code/myproject/storage/app/public/blah': Protocol error
What is the problem? Does it have something to do with the folder mappings of Homestead? How can I achieve my goal?
(My /home/vagrant/Code/ and /home/vagrant/foo/ map to separate drives on my Windows machine.)
P.S. And before trying the steps above, I even deleted the Homestead standard public symlink just to avoid other possible complications.
P.P.S. I've also tried adding this near the bottom (above the final end) of my Homestead Vagrantfile before spinning up the box:
config.vm.provider "virtualbox" do |v|
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
end
I noticed that php artisan storage:link was now causing a "Protocol error" too.
So to narrow down the problem I created a totally fresh Homestead project and box and tried creating symlinks (including php artisan storage:link) in there but got the "Protocol error" too.
And I was very careful to be using Git Bash (my terminal / command line client) as Administrator, so I was already following the advice of most answers on StackExchange.
I also decided to move one of my Windows folders (the one that I'd had Homestead map to /home/vagrant/foo/) to be within the Windows folder that Homestead mapped to /home/vagrant/Code/.*
I decided to restart Windows 10 completely. Now after spinning up new vagrant boxes, php artisan storage:link and creating my other symlink worked.
*I'm not sure moving the Windows folder was even necessary. Maybe I could have left the folders on separate Windows drives. But at the time, I wanted to minimize possible complications.
When using Homestead, making a symlink in your public directory in Windows will also create a symlink on vagrant. The other way round may (!) create this error and will leave a not working symlink in your Windows directory.
The error sometimes return after you shutdown the VM and restart or still persists. Basically you need to again tell VirtualBox to enable symlinks. Here's the complete solution
Obviously have this in your vagrant file, as suggested above
config.vm.provider "virtualbox" do |v|
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name", "1"]
end
I recommended comment out any sync folder and let default ./(at host) synced at /vagrant(at guest). This will make sure your shared folder(Folder_Name) name is always vagrant as mentioned here https://www.vagrantup.com/docs/synced-folders/. Also, you won't face issues with ssh
If the symlink protocol error returns after restart or still persists run
VBoxManage setextradata "VM_Name" VBoxInternal2/SharedFoldersEnableSymlinksCreate/Folder_Name 1
vagrant halt
vagrant up
vagrant ssh
Usually, VBoxManagee is located at C:\Program Files\Oracle\VirtualBox\
Verify working of symlink by going to /vagrant and running
touch test.txt && ln -s test.txt test1.txt
PS: I have tried this on Windows Home which has limited accessibility to security settings
Protocol error means that the language of communication between the folders is different. You musst have the same version of PHP. So you have to bring the PHP in the VM and on your Windows OS on the same version state.
Go like this:
update your PHP on you computer (i.e. download from php.org)
then open cmd as admin
cd homestead -> vagrant up -> cd code -> cd "your-APP"
sudo apt update -> sudo apt upgrade
ln -sr storage/app/public public/storage
and now there is no error and the folder puplic/storage has been created.
Good luck...

Issues mounting a shared folder in virtualbox

I'm trying to create a shared folder between MacOS (Host) and Debian (Guest) in virtualbox. I've completed the steps of installing guest additions, creating a shared folder called "share" and a folder in debian called "sf", but when I try to run
sudo mount -t vboxsf share ~/sf
I get the error
mount: realpath /Users/USERNAME/sf: No such file or directory
I'm under the impression the second path is meant to be the directory in Debian. This also happens when I remove the ~/.
Looks like you are trying to run this command from your OSX shell. Is that possibly the case?
If yes, switch to your shell on the Debian guest. Also make sure the directory ~/sf actually does exist before you run the mount command.
Hope this helps.

vagrant - constantly syncing folder setup

I am trying build a centos7 vm at my windows10 using virtualbox. I am using cento/7 box.
it by default using rsync for syncing folder and I don't really like it as I would have to open an extra cmd just to run vagrant rsync-auto for constant syncing.
I tried to use nfs but not successful.
Here is my vagrantfile.
Vagrant.configure(2) do |config|
config.vm.box = "centos/7"
config.vm.synced_folder ".", "/home/vagrant/sync", type: "nfs"
end
and when I tried to run it. It gave me this.
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 vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` home_vagrant_sync /home/vagrant/sync
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` home_vagrant_sync /home/vagrant/sync
The error output from the last command was:
mount: unknown filesystem type 'vboxsf'
I noticed that changes made by host will be synced to guest but not the other way round. I want to make the folder like a shared folder both guest and host can apply changes to it. Any best approaches to do it?
Thanks.
The reply you got is telling you to install Virtual Box guest additions. This is a separate installation action you have to perform on top of installing Virtual Box. Did you install Virtual Box Guest Additions?

vagrant ash: sudo: not found

When starting my vagrant box with a small 15MB Busybox image, the first time I get an error during the phase
Mounting shared folders...
It seems vagrant is trying something with sudo, which isn't istalled. I get this error:
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
mkdir -p /vagrant
Stdout from the command:
Stderr from the command:
ash: sudo: not found
It works so far, I can login as root with the password vagrant, but I guess this is not perfect?
This is my setup: https://github.com/rubo77/ffnord-example/blob/pyddhcpd/Vagrantfile
config.ssh.username = 'root'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
config.ssh.shell = 'ash'
(0..9).each do |i|
config.vm.define "gc-node0#{i}" do |node|
end
end
By default vagrant share/sync the directory /vagrant (guest) with the current project directory, the one containing the Vagrantfile (host), more directories can be shared using config.vm.synced_folder, I don't know if the default /vagrant can be disabled.
If you aren't using the shared directories feature then the missing sudo isn't a problem.
If your filesystem is writeable you can create the /vagrant directory once, so on next up vagrant shouldn't try to sudo mkdir again;
but assuming you're using VirtualBox (I don't know about others emulator behavior/architecture) you'll face another problem, shared directories require the kernel modules vboxsf and vboxguest (from VirtualBox Guest Additions) to be built (against the running kernel sources) and loaded (insmod), and the command mount.vboxsf to be built and installed in /sbin, plus your busybox require the option mount helpers enabled because vagrant use mount -t vboxsf and not mount.vboxsf directly, when vagrant try to mount the shared directories and those requirements aren't matched there is a long timeout before failing with error (a minute/two or more).
Notice that busybox (current stable) support sudo, is just disabled by default.
If you're building the buildroot yourself from sources I can tell that the shared feature works (I managed to get an image with busybox to work as vagrant expect), if you're using some pre-built kernel/busybox... may be a problem, you have to find matching binaries for vboxsf, vboxguest, mount.vboxsf and if the mount helpers option is disabled in your busybox you need to find a workaround (perhaps modifying vagrant to use mount.vboxsf).

Resources