hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.16k stars 4.43k forks source link

Enabling Symbolic inside the Shared Folder on Virtual Machine #13198

Open Utatistics opened 1 year ago

Utatistics commented 1 year ago

Issue Description:

I'm encountering an issue with Vagrant where I'm unable to create symbolic links within the virtual machine. I've followed the recommended steps, including enabling symlink creation in the VirtualBox provider settings and running a command on the host machine, but I'm still facing difficulties. This issue prevents me from setting up the required symbolic links for my project.

Environment:

Steps to Reproduce:

  1. Start the Vagrant virtual machine.
  2. Navigate to the desired directory within the virtual machine.
  3. Attempt to create a symbolic link using the ln -s command.

Expected Behavior:

I expect the symbolic link to be created successfully without any errors.

Actual Behavior:

Instead, I receive the following error message: "ln: failed to create symbolic link: Protocol error".

Additional Information:

Screenshots:

(Optional: Include relevant screenshots if applicable)

Logs:

(Optional: Include relevant log files or error messages if available)

Please let me know if any further information is required. I appreciate your assistance in resolving this issue.

chrisroberts commented 1 year ago

Hi there,

Some clarification on the issue you are encountering would be helpful:

Thanks!

Utatistics commented 1 year ago

Hi, thanks for your response!

My guest OS is Ubuntu 20.04.4 LTS, and I'm trying to create the symlink inside the synced folder (see below), which VirtualBox doesn't allow you to by default for security reasons.

config.vm.synced_folder "./", "/home/vagrant/base"

The synced folder is mounted to my host at c:\Users\username\Onedrive\Desktop... Now that you mentioned, could this be something to do with Onedrive? I moved the folder to c:\Users\username\ or outside of the Onedrive and tried to create the symlink in the guest machine again. It didn't work.

chrisroberts commented 1 year ago

By default, Vagrant enables symlinks within synced folders using the VirtualBox provider. For example, this is a local ubuntu guest I created to test this:

➜ vagrant up --provider virtualbox
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'hashicorp/bionic64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/bionic64' version '1.0.282' is up to date...
==> default: Setting the name of the VM: vagrant-symlink_default_1687826201495_6004
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> 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: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default:
    default: Guest Additions Version: 6.0.10
    default: VirtualBox Version: 7.0
==> default: Mounting shared folders...
    default: /vagrant => /home/spox/workspace/vagrant-symlink
➜ vagrant ssh
vagrant@vagrant:~$ mount | grep "/vagrant "
vagrant on /vagrant type vboxsf (rw,nodev,relatime,iocharset=utf8,uid=1000,gid=1000,_netdev)
vagrant@vagrant:~$ echo "this is a test" > testfile.txt
vagrant@vagrant:~$ pwd
/home/vagrant
vagrant@vagrant:~$ ls
testfile.txt
vagrant@vagrant:~$ ln -s /home/vagrant/testfile.txt /vagrant/testfile.txt
vagrant@vagrant:~$ ls /vagrant
Gemfile  Gemfile.lock  testfile.txt  Vagrantfile
vagrant@vagrant:~$ ls -l /vagrant
total 4
lrwxrwxrwx 1 vagrant vagrant   26 Jun 27 00:40 testfile.txt -> /home/vagrant/testfile.txt
-rw-rw-r-- 1 vagrant vagrant  120 Jun 27 00:36 Vagrantfile
vagrant@vagrant:~$ cat /vagrant/testfile.txt
this is a test
vagrant@vagrant:~$

Use of Onedrive can definitely cause problems which have been encountered before. You state that you moved the folder outside of Onedrive, after doing that did you destroy and create the guest again?