Mac – How to share/access files in CentOS running in VirtualBox from the Macbook Pro

centosmacbook promountvirtualbox

I have setup a VirtualBox running on my MacBook Pro (OS X 10.9). This VirtualBox is running CentOS 6.5. I can successfully SSH from the Macbook to the CentOS VM by doing ssh saqib@127.0.0.1 -p 3005

Now I want to be able to access and edit the files on the CentOS VM (under the /var/www directory) using the nice editors and tools I have installed natively on my MacBook. But I'm having trouble doing so.

I successfully followed the instructions here. Now I have a directory on the CentOS VM called /mnt/my_share_name in which I can access files on the MacBook's file system. Great. . but what I really need is the opposite. I want to be able to access files in the CentOS VM's /var/www directory from the MacBook. How Can I do that?? I tried inserting a link in /mnt/my_share_name as shown below. But it didn't work.

# From the CentOS VirtualBox
% cd /mnt/my_share_name
% sudo touch me
% ls
me
% sudo ln -s /var/www www
ln: creating symbolic link `eso': Read-only file system

Just in case anyone is interested, here is a screenshot of the VirtualBox Manager application:
Screenshot of my VirtualBox Manager

Best Answer

As your provided link says:

In your Guest Linux Box, open a terminal and enter the following commands:

>sudo mkdir /mnt/share 

>sudo mount -t vboxsf shared_folder /mnt/share     [shared_folder is the name of your shared folder]

This will make /mnt/share/ your shared folder (meaning if you put files in the shared folder from the host(OS X in your case) it will be visible in /mnt/share/)

You can change this around however you wish, like:

>mkdir /home/user/shared 

>sudo mount -t vboxsf shared_folder /home/user/shared     [shared_folder is the name of your shared folder]

This would place the shared folder in user's home directory. Don't forget to place the mount options in fstab as your link suggests to mount the shared folder on boot.

I would personally suggest placing it under the /media/ folder somewhere as most file managers will automatically pick that up as if it were external media (like a usb flash drive or external HDD, these would be auto mounted in /media/ as well)

To access the folder on your host, when you create the machine folder you select a "Folder Path" that path is to where it is located on your host and where you can access it from.

Update: I do not know why that symlink creation fails, but you should investigate that. As a (fairly ugly) workaround you can do something like:

cp -r /var/www/* /mnt/my_share_name
sudo nano /etc/fstab

and change your existing shared directory from /mnt/my_share_name to /var/www after this run

rm -rf /var/www

and then reboot. This should basically move all your files from /var/www to the shared folder, and make the shared folder be /var/www.

Related Question