Virtualbox 设置虚拟机和物理机共享文件夹
概述
由于我这里使用的是virtualbox,所以用virtualbox来演示,其他虚拟的原理是一样的,这里不做介绍。
步骤1
virtuabox建立共享文件夹
先选定需要建立共享文件夹的虚拟机,选择设置=》共享文件夹,点击右侧蓝色+号图标新建共享文件夹。
选择一个本地机文件夹作为共享文件夹,如果没有特殊权限要求,勾选固定分配项。
步骤2
添加驱动
选择存储=》控制器IDE=》添加光驱=》VBoxGuestAdditions.iso,VBoxGuestAdditions.iso光驱镜像在virtualBox的安装目录下
步骤3
挂载到系统
启动系统后执行以下命令
[root@localhost ~]# mount -t auto /dev/cdrom /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cd /mnt/cdrom/
[root@localhost cdrom]# ls
32Bit AUTORUN.INF cert runasroot.sh VBoxLinuxAdditions.run VBoxWindowsAdditions-amd64.exe VBoxWindowsAdditions-x86.exe
64Bit autorun.sh OS2 TRANS.TBL VBoxSolarisAdditions.pkg VBoxWindowsAdditions.exe
[root@localhost cdrom]# ls
32Bit AUTORUN.INF cert runasroot.sh VBoxLinuxAdditions.run VBoxWindowsAdditions-amd64.exe VBoxWindowsAdditions-x86.exe
64Bit autorun.sh OS2 TRANS.TBL VBoxSolarisAdditions.pkg VBoxWindowsAdditions.exe
[root@localhost cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........
bzip2 not found. Please install: bzip2 tar; and try again.
[root@localhost cdrom]# yum install bzip2
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 bzip2.x86_64.0.1.0.6-13.el7 将被 安装
--> 解决依赖关系完成
...
## 这里我的centos 虚拟机缺少bzip2依赖,提示缺少什么就安装什么,安装依赖后继续执行 VBoxLinuxAdditions.run
已安装:
bzip2.x86_64 0:1.0.6-13.el7
完毕!
[root@localhost cdrom]# ./VBoxLinuxAdditions.run
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.18 Guest Additions for Linux........
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while.
This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.
Please install the Linux kernel "header" files matching the current kernel
for adding new hardware support to the system.
The distribution packages containing the headers are probably:
kernel-devel kernel-devel-3.10.0-1062.4.1.el7.x86_64
[root@localhost ~]# mkdir /local
[root@localhost ~]# mount -t vboxsf local /local
ls /local/
test
[root@localhost ~]# ls /
bin boot dev etc home lib lib64 local media mnt opt proc root run sbin srv sys tmp usr var
# 挂载成功 /local 文件夹显示绿色
# mount -t vboxsf local(该目录为virtualbox界面创建的文件夹名称,根据自己修改) /local