共享文件夹, 顾名思义, 即允许虚拟机公用指定主机中的某一个文件夹.
本文以 Ubuntu 16.04 为例, 演示如何使用 Virtual Box 的共享文件夹功能.
1. 安装 Virtual Box 增强功能, 具体步骤不在赘述.
1. 在虚拟机的设置页面中, 进入 "共享文件夹" 选项卡, 新增一个共享条目, 设置如下图所示. (此处指定的为主机中已存在的路径)
2. 保存设置, 并运行虚拟机.
3. 在虚拟机中, 输入命令行:
# 在虚拟机中创建共享文件夹的挂载点, 以下使用路径为 ~
~$ mkdir share
# 使用挂载命令
# vboxsf 后的第一个参数 share 为共享文件夹设置中的名称, 第二个参数 ~/share 为上一步骤创建的路径
~$ sudo mount -t vboxsf share ~/share
4. 若希望可以开机自动挂载, 将上一步骤中的第二条命令添加至 /etc/rc.local 文件中的 "exit 0" 之前, 若没有 "exit 0", 则将命令追加至文件末尾, 保存即可. 笔者的 rc.local 文件内容如下, 仅供参考.
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
# 此处的最后一个参数应为共享文件夹在虚拟机上挂载点的绝对路径
mount -t vboxsf share /home/{your_user_name}/share
exit 0
5. 进入共享文件夹.
~$ cd share
若挂载成功, 在此文件夹应可看到主机中共享文件夹目录下的所有文件.