root 发表于 2015-10-12 11:58:28

(4)ubuntu8访问windows共享目录1——VirtualBox Folder Sharing

  本博客(http://blog.iyunv.com/livelylittlefish)贴出作者(三二一、小鱼)相关研究、学习内容所做的笔记,欢迎广大朋友指正!
  
  ubuntu8访问windows共享目录1——VirtualBox Folder Sharing
  
  ubuntu系统访问Windows系统的共享目录有多中方式,此文主要是利用VirtualBox Folder Sharing的功能实现共享。
  

[*]设置共享文件夹
在ubuntu8虚拟机运行的窗口中,设备 --> 分配数据空间 菜单,添加一个共享文件夹,如下图。该例中,共享名称为linuxstudy。




[*]挂载该共享文件夹
sudo mkdir /mnt/programming
sudo mount -t vboxsf linuxstudy /mnt/programming
其中"linuxstudy"是之前创建的共享文件夹的名称
若共享文件夹的名称与加载点名称相同,“mount -t vboxsf”命令不成功,但“mount.vboxsf”命令可以正确执行。

若要自动加载,不每次都手动加载,需在/etc/fstab中添加如下一项
Linuxstudy /mnt/programming vboxsf rw,gid=100,uid=1000,auto 0 0


[*]删除共享
sudo umount -f /mnt/programming




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
linuxstudyprogramming
root@yu28:/mnt# cd linuxstudy/
root@yu28:/mnt/linuxstudy# ls
aaaa.txt         procon            ProducerConsumer.txtrwlock2.c    rwlock31.txtrwlock3.c       testcallback
figure             ProducerConsumer    rwlock                rwlock2.txtrwlock32.txtrwlocktest      testcallback.c
foldersharing.jpgProducerConsumer.crwlock1               rwlock3      rwlock33.txtrwlocktest.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
linuxstudyprogramming
root@yu28:/mnt# umount -f/mnt/linuxstudy/
root@yu28:/mnt#
root@yu28:/mnt# ls
linuxstudyprogramming
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:

VBoxManage sharedfolder add "VM name" -name "sharename"-hostpath "C:/test"

There are two types of shares:

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.

             版权声明:本文为博主原创文章,未经博主允许不得转载。
页: [1]
查看完整版本: (4)ubuntu8访问windows共享目录1——VirtualBox Folder Sharing