root@yu28:/mnt# mount -t vboxsf linuxstudy /mnt/linuxstudy/
/sbin/mount.vboxsf: mounting failed with the error: Protocol error root@yu28:/mnt# mount.vboxsf linuxstudy /mnt/linuxstudy/
root@yu28:/mnt#
root@yu28:/mnt# ls
linuxstudy programming root@yu28:/mnt# cd linuxstudy/
root@yu28:/mnt/linuxstudy# ls
aaaa.txt procon ProducerConsumer.txt rwlock2.c rwlock31.txt rwlock3.c testcallback
figure ProducerConsumer rwlock rwlock2.txt rwlock32.txt rwlocktest testcallback.c
foldersharing.jpg ProducerConsumer.c rwlock1 rwlock3 rwlock33.txt rwlocktest.cpp root@yu28:/mnt/linuxstudy# umount -f /mnt/linuxstudy/
umount2: Device or resource busy
umount: /mnt/linuxstudy/: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
root@yu28:/mnt/linuxstudy# cd ..
root@yu28:/mnt# ls
linuxstudy programming root@yu28:/mnt# umount -f /mnt/linuxstudy/
root@yu28:/mnt#
root@yu28:/mnt# ls
linuxstudy programming
root@yu28:/mnt# cd linuxstudy/ root@yu28:/mnt/linuxstudy# ls
root@yu28:/mnt/linuxstudy#
reference:
4.6. Folder sharing
Shared folders allow you to access files of your host system from within the guest system, much like ordinary shares on Windows networks would -- except that shared folders do not need a networking setup. Shared folders must physically reside on the host and are then shared with the guest; sharing is accomplished using a special service on the host and a file system driver for the guest, both of which are provided by VirtualBox.
In order to use this feature, the VirtualBox Guest Additions have to be installed. Note however that Shared Folders are only supported with Windows (2000 or newer) guests and Linux guests.
To share a host folder with a virtual machine in VirtualBox, you must specify the path of that folder and choose for it a "share name" that the guest can use to access it. Hence, first create the shared folder on the host; then, within the guest, connect to it.
There are several ways in which shared folders can be set up for a particular virtual machine:
In the graphical user interface of a running virtual machine, you can select "Shared folders" from the "Devices" menu, or click on the folder icon on the status bar in the bottom right corner of the virtual machine window.
If a virtual machine is not currently running, you can configure shared folders in each virtual machine's "Settings" dialog.
From the command line, you can create shared folders using the the VBoxManage command line interface; see Chapter 8, VBoxManage reference. The command is as follows:
VM shares which are only available to the VM for which they have been defined;
transient VM shares, which can be added and removed at runtime and do not persist after a VM has stopped; for these, add the -transient option to the above command line.
Shared folders have read/write access to the files at the host path by default. To restrict the guest to have read-only access, create a read-only shared folder. This can either be achieved using the GUI or by appending the parameter -readonly when creating the shared folder with VBoxManage.
Then, you can mount the shared folder from inside a VM the same way as you would mount an ordinary network share:
In a Windows guest, starting with VirtualBox 1.5.0, shared folders are browseable and are therefore visible in Windows Explorer. So, to attach the host's shared folder to your Windows guest, open Windows Explorer and look for it under "My Networking Places" -> "Entire Network" -> "VirtualBox Shared Folders". By right-clicking on a shared folder and selecting "Map network drive" from the menu that pops up, you can assign a drive letter to that shared folder.
Alternatively, on the Windows command line, use the following: net use x: //vboxsvr/sharename
While vboxsvr is a fixed name (note that vboxsrv would also work), replace "x:" with the drive letter that you want to use for the share, and sharename with the share name specified with VBoxManage.
In a Linux guest, use the following command:
mount -t vboxsf [-o OPTIONS] sharename mountpoint
Replace sharename with the share name specified with VBoxManage, and mountpoint with the path where you want the share to be mounted (e.g. /mnt/share). The usual mount rules apply, that is, create this directory first if it does not exist yet.
Beyond the standard options supplied by the mount command, the following are available:
iocharset CHARSET
to set the character set used for I/O operations (utf8 by default) and
convertcp CHARSET
to specify the character set used for the shared folder name (utf8 by default).
The generic mount options (documented in the mount manual page) apply also. Especially useful are the options uid, gid and mode, as they allow access by normal users (in read/write mode, depending on the settings) even if root has mounted the filesystem.