HOWTO: Use Shared Folders

HOWTO: Use Shared Folders

Postby Sasquatch » 27. Mar 2009, 21:14

After installing the Guest Additions, you can use the Shared Folders Functionality. To access them, you have to define at least one in the VM settings. Open the VM Settings and go to Shared Folders. You can define them there. Click on the Add button and browse for a folder you want to share. Make sure that the name of the share doesn't contain any illegal characters like white spaces. Keep the name as simple as possible. In this howto, I will use the name share.

Now that you have defined a SF, it's time to mount it. Boot the Guest and open a terminal. Create a folder where you will mount it on. E.g. in your home folder. I will use ~/host for the mount point.
Now mount it with the following command:
Code: Select all   Expand viewCollapse view
sudo mount -t vboxsf share ~/host

Note that with this, the default mount options are used and all files are owned by root. This can be changed by adding some mount options. Options are passed on with the -o parameter. You can use multiple options with one parameter, seperate the values with a comma. See the man page of mount for more info on which options you can use. The User Manual also notes the options compatible with the Shared Folders. To mount the SF so that you are the owner of the files, use this command:
Code: Select all   Expand viewCollapse view
sudo mount -t vboxsf -o rw,uid=1000,gid=1000 share ~/host

If you want to have it mount automatically upon each boot, put the mount command in /etc/rc.local (Debian based distro's), or whatever script is run at the end of the boot process. The Shared Folders service should mount them automatically, but that doesn't always happen.
Using /etc/fstab has little effect, because that file is processed before the SF module is loaded and will fail to mount the share. Sometimes, the share does get mounted because the GA check for it when they are loaded upon boot, but it's very flaky, meaning it doesn't work most of the time. You're better of with the first option.
When you put the mount command in /etc/rc.local, so it's mounted at startup, you can't use the short notation for your home folder. During startup, everything is done through the root user, so using ~ for home, means it's the home folder of Root (/root). Change it to the full path. For example:
Code: Select all   Expand viewCollapse view
mount -t vboxsf share /home/<username>/host

Q: I get a protocol error when mounting.
Q: I get the error /sbin/mount.vboxsf: mounting failed with the error: No such device.
A: You mount the SF on a mount point with the same name as the share itself, change the name or mount point.
A: You're sharing a personal folder like your Home Folder (Linux), or My Documents (Windows) on the Host. Define a new share, like a sub folder.

Q: I get an error "Unexpected error: Text file busy." when trying to edit a file.
A: When using gedit, this can happen on shared folders. This is a bug in gedit, not VB. Use a different editor.
Posts: 17800
Joined: 17. Mar 2008, 13:41
Location: /dev/random
Primary OS: Debian other
VBox Version: PUEL
Guest OSses: Windows XP, Windows 7, Linux

Return to Linux Guests

Who is online

Users browsing this forum: No registered users and 0 guests