VirtualBox配置CentOS7的共享文件夹

来源:互联网 发布:期货交易分析软件ipad 编辑:程序博客网 时间:2024/05/22 03:09
VirtualBox配置CentOS7的共享文件夹

环境:主机操作系统Windows8,虚拟机CentOS7.0,VirtualBox版本4.3.18。

1、安装gcc和kernel-devel

yum -y install gcc kernel-devel

2、安装完成后建立软连接

ln -s /usr/src/kernels/3.10.0-123.9.3.el7-x86_64(内核版本号,按Tab自动补全) /usr/src/linux

3、挂载光盘


mount -t auto /dev/cdrom(也可能是cdrom1,按Tab自动补全) /mnt

4、执行安装

sh /mnt/VBoxLinuxAdditions.run

5、在控制-设备-共享文件夹里设置共享文件夹



6、虚拟机里建立共享文件夹

mkdir /media/share

7、挂载共享文件夹

mount -t vboxsf share /mnt/share

此时如果提示/sbin/mount.vboxsf: mounting failed with the error: No such device,说明内核模块vboxsf未加载,可通过lsmod | grep vboxsf查看(无结果说明未加载)。

8、加载vboxsf模块


modprobe vboxsf

加载成功后再次挂载共享文件夹,成功。

9、设置启动自动挂载

网上查到的方法之一是


/etc/fstab中加入一行share /media/share vboxsf rw,gid=100,uid=1000,auto 0 0,然后重启,结果不行。

网上查到的另一方法是

/etc/rc.local中加入一行mount -t vboxsf share share,然后重启,还是不行。

无奈,只好自己找原因,发现在重启之后未加载内核模块vboxsf,直接挂载共享文件夹会提示/sbin/mount.vboxsf: mounting failed with the error: No such device。

解决这个问题,需要在/etc/sysconfig/modules/中增加一个脚本文件,我命名为vboxsf.modules,内容如下:


#! /bin/sh

 /sbin/modinfo -F filename vboxsf > /dev/null 2>&1
 if [ $? -eq 0 ]; then
     /sbin/modprobe vboxsf
 fi

问题解决。


以上操作使用的是root账户,非root账户可根据提示使用sudo命令。
阅读全文
0 0