Configuring host-VM folder path sync (mount) in VirtualBox and Vagrant
First published: Saturday, April 19, 2025 | Last updated: Saturday, April 19, 2025It is crucial to configure host-VM shared folder path sync (mount) in VirtualBox and Vagrant to enable easy software development using a code editor or an IDE.
Prerequisites
To set up shared folder synchronization (mounting) between the host and the VM, you need to have VirtualBox and Vagrant installed on your Windows, Mac, or Linux operating system. Additionally, ensure that you have a Linux VM running on your host.
- How to install and configure VirtualBox on Windows, Mac, and Linux?
- How to install and configure Git on Windows, Mac, and Linux?
- How to install Vagrant on Windows, Mac, and Linux?
- How to automate and deploy Linux VMs on Windows, Mac, and Linux?
Configure shared folder path sync (mount)
Configuring shared folder synchronization (mounting) between the host and the VM is essential for integrated software source code development using a code editor or IDE. The procedure to enable shared folder synchronization (mounting) varies by operating system, such as Windows, Mac, or Linux. For more comprehensive instructions and in-depth information, make sure to refer to the official VirtualBox documentation and Vagrant documentation.
Windows
- Open the Git Bash terminal in administrator mode.
- Execute the below commands in the Git Bash terminal to create the required source path inside the host machine.
# Create directories in host machine.
$ mkdir -p /opt/source/Devel/SLST
- Open the VirtualBox UI console in administrator mode.
- Choose the specific VM and navigate to the Shared Folders section under Settings view.
- Create a new shared folder.
Folder Path: C:\Program Files\Git\opt\source\Devel\SLST
Folder Name: opt_source_Devel_SLST
Mount point: /opt/source/Devel/SLST
Auto-mount: true
Make Permanent: true
Mac
- Open the terminal.
- Execute the below commands in the terminal to create the required source path inside the host machine.
# Create directories in host machine.
$ sudo mkdir -p /opt/source/Devel/SLST
$ sudo chown -R $USER /opt/source
-
Go to the System Preferences app and navigate to the Settings & Privacy section to enable Full Disk Access for VirtualBox.
-
Open the VirtualBox UI console from the terminal.
# Open VirtualBox as root user.
$ sudo virtualbox
- Choose the specific VM and navigate to the Shared Folders section under Settings view.
- Create a new shared folder.
Folder Path: /opt/source/Devel/SLST
Folder Name: opt_source_Devel_SLST
Mount point: /opt/source/Devel/SLST
Auto-mount: true
Make Permanent: true
Linux
- Open the terminal.
- Execute the below commands in the terminal to create the required source path inside the host machine.
# Create directories in host machine.
$ sudo mkdir -p /opt/source/Devel/SLST
$ sudo chown -R $USER:$USER /opt/source
- Open the VirtualBox UI console from the terminal.
# Open VirtualBox as root user.
$ sudo virtualbox
- Choose the specific VM and navigate to the Shared Folders section under Settings view.
- Create a new shared folder.
Folder Path: /opt/source/Devel/SLST
Folder Name: opt_source_Devel_SLST
Mount point: /opt/source/Devel/SLST
Auto-mount: true
Make Permanent: true
Windows, Mac, and Linux
- Connect to the VM via SSH.
- Execute the below commands to create the required destination path inside the VM.
# Create directories in VM.
$ sudo mkdir -p /opt/source/Devel/SLST
$ sudo chown -R vagrant:vagrant /opt/source
- Execute the below commands to sync (mount) the source path from the host machine inside the VM.
The below command must be executed after each reboot (restart) of the VM.
# Sync (mount) source path to VM.
$ sudo mount.vboxsf -o uid=1000,gid=1000 opt_source_Devel_SLST /opt/source/Devel/SLST