[已解决]vagrant共享文件夹挂载失败.Vagrant was unable to mount VirtualBox shared folders

来源:互联网 发布:云南映象知乎 编辑:程序博客网 时间:2024/06/06 04:45

问题现象

到公司打开笔记本,启动vagrant 虚拟机. 提示以下错误

请看截图


 

错误信息:

Vagrant was unable to mount VirtualBox shared folders. This is usually
because the filesystem "vboxsf" is not available. This filesystem is
made available via the VirtualBox Guest Additions and kernel module.
Please verify that these guest additions are properly installed in the
guest. This is not a bug in Vagrant and is usually caused by a faulty
Vagrant box. For context, the command attempted was:
mount -t vboxsf -o uid=1001,gid=1001 work_ /work
The error output from the command was:
/sbin/mount.vboxsf: mounting failed with the error: No such file or directory

让我们来翻译下:

vagrant 无法装载VirtualBox的共享文件夹,因为文件系统"vboxsf"无法使用.

这个文件系统通过VirtualBox客户添加内核模块获得,请确认是否被正确安装.

这不是vagrant的问题,而是VirtualBox引起的问题.

请尝试执行,以下命令:

mount -t vboxsf -o uid=1001,gid=1001 work_ /work

命令输出的错误信息为:

sbin/mount.vboxsf:挂载失败:找不到这个文件或目录

问题分析

这个共享文件夹,可以把windows的目录和linux的某个目录互相映射,当在win下做了文件新增,删除,修改等操作后,会自动同步到linu的某个目录下,
在本机开发环境,用来编写php代码,可以带来很多方便.

错误现象中,
"这不是vagrant的问题,而是VirtualBox引起的问题"
看到这句话我笑了,vagrant和vitualBox互相配合使用,这就开始互相甩锅了吗? 哈哈

我就想,这么共享目录是在哪里配置的呢?
从Vagrantfile配置文件中,看到这样一段配置:
 # Share an additional folder to the guest VM. The first argument is  # the path on the host to the actual folder. The second argument is  # the path on the guest to mount the folder. And the optional third  # argument is a set of non-required options.  # config.vm.synced_folder "../data", "/vagrant_data"  #config.vm.synced_folder "E:/project/projects/server", "/work/", owner: "www-data", group: "www-data"  #自动同步的目录  config.vm.synced_folder "D:/Project/php/", "/work/", owner: "www-data", group: "www-data"

打开Oracle VM VirtualBox软件时,也可以看到这样的配置:


我尝试把自动挂载开启. 然后重启,无效.
更换新的目录重新映射, 无效.

问题原因

百思不得其解时,我再次想起了错误现象中的那句, "这不是vagrant的问题,而是VirtualBox引起的问题",或许这几句话是对的呢.

顺着这个思路,我访问了VirtualBox官网的buglist, 找到了这个信息



可以看到,是在5.1.20这个版本中出现的这个问题, 我看了下我使用的版本是5.1.16, 竟然比这个有问题的版本还低.

最下面写到,已在5.1.22修复了这个问题.

解决方法

那么,立刻升级吧.  下载新版本安装后,重新启动, 果然,问题解决了,请看截图,提示共享目录,挂载成功.


所思所想

错误现象中提供的信息,虽然不可尽信,但也不得不信,   至少提供了一个解决问题的方向. 顺着它试一试,说不定会有奇效.

若有疑问,评论中进行沟通.谢谢各位小伙伴.
原创粉丝点击