Wednesday, December 3, 2014

Sharing Folders Between a Mac OS X Host and a VirtualBox Linux Guest

This is going to be a straightforward guide to sharing folders with your local virtual machines. Knowing how to do this will make it easier to open up your VirtualBox instance to your host machine and save time in the process. Say you need to pull repos into your VM, rather than set up git and your SSH keys, just share a folder that has pulled down the repository between the host and the virtual machine and you're good to go.

Prerequisites: You'll want to be familiar with setting up VirtualBox with Vagrant. This guide was written for Mac OS X users.

With your powered off virtual machine selected, click the "Settings" icon and the "Shared Folders" tab.

Indicate your “Folder Path” and "Folder Name". Make sure to remember the folder name. You'll be referencing this from within your host VM. Make sure you select Auto-mount. Click “OK” to boot up the virtual machine.

# SSH into your host VM
ssh vagrant@localhost -p2222

# Make a folder for mounting
sudo mkdir /vbnfs

# Mount the folder with the following command:
# sudo mount -t vboxsf folder_name folder_to_mount
sudo mount -t vboxsf vbnfs /vbnfs/

# This is an alternative way to automount on startup...
# ...if VirtualBox doesn't do it for you
sudo vi /etc/rc.local
sudo mount -t vboxsf vbnfs /vbnfs/ # add this line

There you go. Hopefully, this saves you time in the future.

No comments:

Post a Comment