9

I have an Ubuntu 17 VM on Virtual Box, and my host OS is windows 8.1. I created a shared folder between host and guest OS.

Now, because windows doesn't support symlinks, this prevents me from putting any symlinks in the shared folder. Unfortunately, I need to put a react project in the shared folder and the project contains symlinks in the sub-folder. How can I solve the problem ? can I put symlinks and tell windows somehow to ignore them or prevent ubuntu from sharing them?

Ahmed Hussein
  • 715
  • 1
  • 15
  • 38
  • 1
    I think this should help you out http://perrymitchell.net/article/npm-symlinks-through-vagrant-windows/. Key is not to use `nfs` and use `smb` in your Vagrantfile for the shared folder and also few more changes – Tarun Lalwani Apr 29 '18 at 05:41
  • 1
    Also see https://stackoverflow.com/questions/21425980/npm-install-without-symlinks-option-not-working – kichik May 04 '18 at 23:34

2 Answers2

17

In fact, Windows file system supports symlinks but with 2 restrictions:

  1. Is disabled by default.
  2. Is available only if you have administrative privileges

I use it with Vagrant on Windows 7 and Windows 10.

First you must enable symlinks feature in your VM like this:

VBoxManage setextradata MACHINE_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME 1

Where MACHINE_NAME is the virtual box guest machine name and SHARE_NAME is the share name inside the box config. If you use Vagrant you can add this to Vagrantfile:

config.vm.provider :virtualbox do |vm|
    vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARE_NAME", "1"]
end

Next, you need to enable symlinks in Windows host machine:

  1. Open Start > Windows Administrative Tools > Local Security Policy
  2. Go to Local Policies/User Rights Assignment in tree view.
  3. Add user name or user groups you belongs to, to entry Create symbolic links.
  4. Restart.
Gebezs
  • 696
  • 3
  • 9
Łukasz Jakubek
  • 995
  • 5
  • 12
  • What would be SHARE_NAME in Vagrant config? Guest path? Host path? Or some other alias? – Davor Oct 06 '18 at 09:30
  • 1
    Verified: Guest path. – Łukasz Jakubek Oct 30 '18 at 13:01
  • 2
    The most important part is SHARE_NAME. For example, in my macOS installation it is `/Users/ivan/Projects`, so I must set the variable as `VBoxManage setextradata MACHINE_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate//Users/ivan/Projects 1` It's very important to write the whole path including the first slash. – Ivan Pomortsev Feb 25 '19 at 21:02
  • Thank you for explaining about `SHARE_NAME`. I copied/pasted this code from other examples and nobody explained that it may need to be changed based on the setup. After hours of frustration I finally got symlink to work on my Windows based vagrant project – Quasi635 Nov 11 '19 at 22:14
0

Symlink for the shared folder from the guest machine is disabled by default, you can enable it with the following command from the host. My OS on the host computer is windows, so it would be like:

C:\Program Files\Oracle\VirtualBox\VBoxManage.exe setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARED_FOLDER_NAME 1

Where 'C:\Program Files\Oracle\VirtualBox' is the installation location of VirtualBox, 'VM_NAME' is my virtual machine name, and 'SHARED_FOLDER_NAME' is the name of the shared folder in the host machine.

If you are using Linux on your host, you can use the same command as below:

VBoxManage setextradata VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/SHARED_FOLDER_NAME 1

Remember it is required to shut down all running virtual machines and close the VirtualBox before execution of the commands. After that windows users run it as an administrator privilege (right click on Virtualbox and run as admin). Now you can create a symlink in a regular way:

ln -sv /to/source/directory /to/destination/directory
Shrm
  • 426
  • 4
  • 8