Thursday, January 3, 2008

Using Shared folders feature of VirtualBox

The VirtualBox has a neat feature of "shared folders" between host and guest. Here is description of how to do it on Ubuntu 7.10

The shared folders are folders on the host that can be shared by the guest. First, you need to create shared folders via the GUI by adding the folders on the host and give names for them. I created a shared folder of /home/$myaccount/work and give it a name of work.

The other things to be done is on the guest side.
I created a directory of /home/$myaccount/work on the guest os.
To mount the directory, the following command can be run
sudo mount.vboxsf work /home/$myaccount/work
or
sudo mount.vboxsf work ~/work

It is interesting that the following commands will not work
sudo mount -t vboxsf work /home/$myaccount/work
/sbin/mount.vboxsf: mounting failed with the error: Protocol error
This maybe is because sudo mount -t vboxsf is different from sudo mount .vboxsf.
It is found that after you ran sudo -i to get a shell, the command of
mount -t vboxsf work /home/$myaccount/work will work.

To mount the shared folder easier and writable by the my account, the following line was added to /etc/fstab.
"work /home/$myaccount/work vboxsf rw,gid=$mygid,uid=$myuid,auto 0 0"

In addition, I appended the following in the .bashrc
mount | grep work 1>/dev/null 2>&1
if [ ! $? ]; then
sudo mount.vboxsf work ~/work
fi

This way whenever I logged in the shared folder is accessible.

No comments: