Shared folders

From Computer Science
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Guides> linux > shared folders


These instructions will cause a folder to be shared between guest and host. That is, if you share the "foo" folder on the host and mount it as "/mnt/foo" on the guest, any files in "foo" on the host will appear in "/mnt/foo" on the guest. Likewise, any modifications made to files in "/mnt/foo" on the guest will be reflected in the files in "foo" on the host.

VirtualBox setup

With your virtual machine halted (ie, not running)...

Select your virtual machine from the list on the left. Click Settings. Select Shared Folder. Click the folder on the right with the "+" on it. Set Folder Path to the folder on the host you want to share with the guest. Set Folder Name to an arbitrary name the guest will use to refer to the share. Remember this name. Click Ok. Click Ok again.

Start your virtual machine.

Linux setup

Once your virtual machine has booted...

First you need to make a place in the filesystem for the shared folder to be mounted (ie, made available). The name doesn't matter, but it'll be easier if you don't include spaces. This needs to be done with sudo because you're altering the filesystem outside your home directory.

$ sudo mkdir /mnt/shared_folder

Now mount the share on the newly-created mountpoint. (Replace "shared_folder_name" with whatever you put in the "Folder Name" box in the VirtualBox setup step.) Note that this assumes your uid and gid are both 1000---you can verify this by running `id`---if they're different, change the following command accordingly.

$ sudo mount -t vboxsf -o uid=1000,gid=1000 shared_folder_name /mnt/shared_folder

If this works, you're golden. If it doesn't, verify that you set up the share correctly in VirtualBox and that the shared folder name matches.

The only problem is it's a pain to have to run this `mount` command every time you boot. There's a better way (though when you're figuring this stuff out the first time, it's prudent to try manually mounting the share to make sure you've got all the parameters correct). The file `/etc/fstab` contains a list of all filesystems to be mounted. You can add the shared folder by appending this line to that file:

shared_folder_name /mnt/shared_folder vboxsf uid=1000,gid=1000 0 0

Because `/etc/fstab` is a systemwide configuration file, you'll need to use sudo to edit it. You can either invoke an editor directly with sudo (eg, `sudo vim /etc/fstab`) or you can run this command:

$ sudo sh -c "echo shared_folder_name /mnt/shared_folder vboxsf uid=1000,gid=1000 0 0 >> /etc/fstab"

Verify that you've done so correctly by examining `/etc/fstab`:

$ cat /etc/fstab

And then try rebooting to see if the share is mounted when the system comes back up.

$ sudo reboot