How to share (config.vm.synced_folder), directories between Windows 10 and CentOS7 Virtual Machine created using Vagrant and VirtualBox

I'm trying to create a VM CentOS7 using Vagrant (2.2.3) and Virtual Box (6.0.4), on Windows 10 using the following Vagrant file

Vagrant.configure("2") do |config| config.vm.box = "bento/centos-7" config.vm.network "private_network", ip: "192.168.56.3" config.vm.synced_folder "D://SharedWithVM//CentOS7-Work", "/media/sf_CentOS7-Work", type: "virtualbox" config.vm.provider "virtualbox" do |vb| vb.name = "Test" end config.vm.provision "shell", path: "./scripts/InstallGuestAdditions.sh"
end

and the InstallGuestAdditions.sh shell script is the follow ..

#!/bin/bash
curl -C - -O
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_6.0.4.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm VBoxGuestAdditions_6.0.4.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions

All works fine and the CentOS7 VM is created.

If I check the machine properties about shared directories I can see this

enter image description here

So I'm quite surprised about this path \\?\D:\SharedWithVM\CentOS7-Work.

How should I change my Vagrantfile to obtain a right path?

I've tried to connect at my CentOS 7 VM using vagrant ssh command and all works. Also the command cd /media/sf_CentOS7-Work works fine but no file or directory can be listed or shared between the two systems.

Here you're a snapshot on my VM CentOS7

enter image description here

I've tried to create files or directories in Windows 10 and also in CentOS7 VM.

Any suggestion or example will be appreciated.

2

2 Answers

I was able to successfully do this in my Virtualbox image earlier; hopefully it will work for you too.

Directions: Inside of your virtual machine:

  1. Create a directory (e.g. mkdir -p /mnt/share)
  2. Mount the shared folder to the directory you just created, where "shared_folder" is the name of the shared folder you set up from Settings earlier (e.g. mount -t vboxsf shared_folder /mnt/share)

You should now be able to access files from your equivalent /mnt/share directory

This worked for me

config.vm.synced_folder "C:\Users\syed\Pvagrant2\data\testplay", "/vagrant", type: 'rsync'

vagant up --provison

==> default: Rsyncing folder: /cygdrive/c/Users/syed/Pvagrant2/data/testplay/ => /vagrant ==> default: Running provisioner: ansible_local... default: Running ansible-playbook...

PLAY [all] *********************************************************************

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like