前言
环境
win10;
VirtualBox版本: 6.1.30(安装在win10上);
CentOS版本: CentOS-7-x86_64-Minimal-2009(安装在VirtualBox上);
问题
centos需要挂载win10的文件夹,实现共享文件的功能。
实现
1、VirtualBox设置共享文件夹
2、启动CentOS,点击 虚拟机菜单栏 => 设备 => 安装增强功能
遇到报错,实属正常
3、在CentOS中安装依赖,并重启
1 2 |
[root@localhost ~]# yum install vim gcc kernel kernel-devel bzip2 -y [root@localhost ~]# reboot |
4、CentOS安装VBoxLinuxAdditions
重启成功后,执行以下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
############### 挂载虚拟光驱到/mnt ############### [root@localhost ~]# mount /dev/cdrom /mnt mount: /dev/sr0 写保护,将以只读方式挂载 ############### 打开虚拟光驱 ############### [root@localhost ~]# cd /mnt ############### 可以看见VBoxLinuxAdditions ############### [root@localhost mnt]# ls AUTORUN.INF NT3x TRANS.TBL VBoxLinuxAdditions.run VBoxWindowsAdditions.exe autorun.sh OS2 VBoxDarwinAdditions.pkg VBoxSolarisAdditions.pkg VBoxWindowsAdditions-x86.exe cert runasroot.sh VBoxDarwinAdditionsUninstall.tool VBoxWindowsAdditions-amd64.exe windows11-bypass.reg ############### 安装VBoxLinuxAdditions ############### [root@localhost mnt]# ./VBoxLinuxAdditions.run Verifying archive integrity... All good. Uncompressing VirtualBox 6.1.30 Guest Additions for Linux........ VirtualBox Guest Additions installer Copying additional installer modules ... Installing additional modules ... VirtualBox Guest Additions: Starting. VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules. This may take a while. VirtualBox Guest Additions: To build modules for other installed kernels, run VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup <version> VirtualBox Guest Additions: or VirtualBox Guest Additions: /sbin/rcvboxadd quicksetup all VirtualBox Guest Additions: Building the modules for kernel 3.10.0-1160.49.1.el7.x86_64. ############### 安装完成,挂载共享文件夹 ############### [root@localhost mnt]# mount -t vboxsf share /var/docker/site/ |
注意:
挂载命令:
mount -t vboxsf 共享文件夹名称 centos文件夹路径。例:
mount -t vboxsf share /var/docker/site/
取消挂载命令:
umount -f centos文件夹路径。例:
umount -f /var/docker/site/
5、实现开机自动挂载(可选)
适用于CentOS7/6
1 2 3 4 |
[root@localhost ~]# vi ~/.bashrc // 在最后添加一行 mount -t vboxsf share /var/docker/site/ |
只适用于CentOS6
1 2 3 4 |
[root@localhost ~]# vi /etc/rc.d/rc.local // 在文件的最后面加上挂载命令 mount -t vboxsf share /var/docker/site/ |
参考
VirtualBox CentOS7 Mini 安装增强工具