I have recently switched from MacBook Pro to Mac Mini for my development machine and I have also switched from VMWare to VirtualBox simply for the sake of OpenSource. Because the new Mac Mini gives me 16GB of DDR3 RAM, which gives me the power to run my own virtual server machine as my sandbox to develop on. To make my life a bit easier, I want to share my coding folder on Mac Mini with the server in the virtual machine, so that I don’t need to keep syncing files manually. Luckily VirtualBox supports this, but need a bit of work to get it going.
In this article I will be creating a shared folder within VirtualBox that will link my /Users/ericlin/Projects directory with one on the CentOS box under /mnt/projects.
Firstly, within VirtualBox, select the guest machine you wish to contain the shared folder.
Press the Settings button and choose the folder that you want to share on your host machine, and give appropriate access level:
Start your guest machine and login as normal.
Select Devices -> Install Guest Additions, this will insert an iso image into the CDROM, but we need to mount it manually:
sudo mkdir /media/cdrom
sudo mount /dev/cdrom /media/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only
Now if you do “ls” on /media/cdrom, you will see the following contents:
Run file “VBoxLinuxAdditions.run” to install the addition:
sudo /media/cdrom/VBoxLinuxAdditions.run
Running it the first time I got the following error:
To fix it, simply do what it asks you to do:
yum install kernel-devel-2.6.32-279.el6.x86_64
Wait for it to finish and try again with previous command:
sudo /media/cdrom/VBoxLinuxAdditions.run
Don’t worry about the FAILED message in the last line, we are running the server version, not the desktop version, so no Window System is required. Once everything is finished, reboot the virtual machine:
sudo reboot
Lastly, you just need to mount the folder. I created the directory that is going to be mounted to: /mnt/projects
sudo mkdir /mnt/projects
Now you just need to mount the shared folder to the newly created directory using the following command.
sudo mount –t vboxsf /Users/ericlin/Projects /mnt/projects
Then you should be able to
cd /mnt/projects
ls -sh
If you want the foler to be mounted automatically on start up, add the following line to your /etc/fstab file: