无法在Vagrant中挂载文件 [英] Unable to mount files in Vagrant

查看:115
本文介绍了无法在Vagrant中挂载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Vagrant或Docker中挂载文件,因此这似乎是由某种权限错误引起的问题.
我的操作系统是Ubuntu 18.04 LTS (Bionic Beaver),据我所知,我没有运行任何SELinux这样的访问控制模块.

I'm unable to mount files in Vagrant or Docker, so it seems like it's an issue caused by some kind of a permission error.
My OS is Ubuntu 18.04 LTS (Bionic Beaver), I'm not running any access control modules like SELinux as far as I'm aware.

在另一个问题中找到了与Docker相关的错误讨论: 无法在Docker中挂载文件

The Docker-related discussion of the error is found in another question: Unable to mount files in Docker

结果是我无法将文件挂载到Vagrant盒子中(即使我有vboxsf):

As a result I'm unable to mount files into Vagrant boxes (even though I have vboxsf):

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=1000,gid=1000 srv_salt /srv/salt

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

我已经在Vagrantfile中指定了这些语句,并且可以在我的同事本地版本中使用,但是在我的版本中,这些文件没有安装或复制到框中:

I have specified these statements in Vagrantfile and it works on my colleagues local builds, but in my build these files do not get mounted or copied into the boxes:

host.vm.synced_folder "salt/", "/srv/salt"
host.vm.synced_folder "pillar/", "/srv/pillar"

结论

在复制文件时,本地计算机上似乎有些混乱,这可能与我的用户的配置方式以及将文件装载到VM和容器中所需的访问权限有关.
如果有人能对此有所启发,我将不胜感激.

Conclusion

It seems something is very messed up on my local machine when it comes to copying over files, possibly has to do with how my user is configured and what access it has to mounting files into VMs and containers.
If anyone can shed some light on this I'd appreciate it.

根据用户@BMitch的建议,我完成了"Virtualbox Guest Additions"安装.
每当我更新软件包时,都会将其记录到日志文件中,大约两个月前在update-20180405_153850.txt中找到了它.

As user @BMitch suggested I went through my "Virtualbox Guest Additions" installation.
Whenever I do an update of my packages I log this into logfiles, found this from update-20180405_153850.txt, almost 2 months ago.

Preparing to unpack .../virtualbox-guest-additions-iso_5.1.34-0ubuntu1.16.04.2_all.deb ...
Unpacking virtualbox-guest-additions-iso (5.1.34-0ubuntu1.16.04.2) over (5.0.40-0ubuntu1.16.04.1) ...

但这对我来说没有意义..我的引导脚本(无用的东西)在我第一次使用此脚本运行时失败了:

But this doesn't make sense to me.. my bootstrapping script (vagrant up'ing the boxes) fails the first time I run it with this:

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=1000,gid=1000 srv_salt /srv/salt

The error output from the command was:

/sbin/mount.vboxsf: mounting failed with the error: No such device

Traceback (most recent call last):
  File "launch-vagrant.py", line 166, in <module>
    main()
  File "launch-vagrant.py", line 120, in main
    vagrant()
  File "launch-vagrant.py", line 95, in vagrant
    main()
  File "launch-vagrant.py", line 67, in main
    start()
  File "launch-vagrant.py", line 83, in start
    _exec('vagrant', 'up')
  File "launch-vagrant.py", line 129, in _exec
    subprocess.check_call(list(args))
  File "/usr/lib/python3.6/subprocess.py", line 291, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['vagrant', 'up']' returned non-zero exit status 1.

我第二次运行它成功,但是显示以下警告消息:

The second time I run it it succeeds but with the following warning message:

Copy iso file /usr/share/virtualbox/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /dev/loop0 is write-protected, mounting read-only
Installing Virtualbox Guest Additions 5.2.11 - guest version is unknown
Verifying archive integrity... All good.
Uncompressing VirtualBox 5.2.11 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 5.2.11 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
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-693.21.1.el7.x86_64
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel modules.
This system is currently not set up to build kernel modules.
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-693.21.1.el7.x86_64
An error occurred during installation of VirtualBox Guest Additions 5.2.11. Some functionality may not work as intended.
In most cases it is OK that the "Window System drivers" installation failed.

很显然,这是VBox Guest Additions安装在实际的包装盒中,而不是在我的本地计算机上.

Clearly, this is the VBox Guest Additions installed in the actual boxes and not on my local machine.

但是我确实更改了/usr/share/virtualbox/VBoxGuestAdditions.iso的文件模式,所以也许可以解决该问题:

I did however change the file mode for /usr/share/virtualbox/VBoxGuestAdditions.iso so maybe that will fix the issue:

petrus@DD-XPS-15-9550:/usr/share/virtualbox$ ll
total 56656
drwxr-xr-x   3 root root     4096 maj 14 00:28 ./
drwxr-xr-x 384 root root    16384 maj 16 12:58 ../
drwxr-xr-x   2 root root    12288 maj 13 23:06 nls/
-rw-r--r--   1 root root 57970688 apr 20 15:50 VBoxGuestAdditions.iso
-rwxr-xr-x   1 root root     2600 nov 29  2016 VBox.sh*
-rwxr-xr-x   1 root root     4163 apr 13 18:37 VBoxSysInfo.sh*
petrus@DD-XPS-15-9550:/usr/share/virtualbox$ sudo chmod ugo+w VBoxGuestAdditions.iso 
[sudo] password for petrus: 
petrus@DD-XPS-15-9550:/usr/share/virtualbox$ ll
total 56656
drwxr-xr-x   3 root root     4096 maj 14 00:28 ./
drwxr-xr-x 384 root root    16384 maj 16 12:58 ../
drwxr-xr-x   2 root root    12288 maj 13 23:06 nls/
-rw-rw-rw-   1 root root 57970688 apr 20 15:50 VBoxGuestAdditions.iso
-rwxr-xr-x   1 root root     2600 nov 29  2016 VBox.sh*
-rwxr-xr-x   1 root root     4163 apr 13 18:37 VBoxSysInfo.sh*

推荐答案

对于流浪汉问题: 默认情况下,Vagrant将主机Vagrant文​​件的文件夹安装到'/vagrant'.如果基本文件系统安装成功,请测试"ls -l/vagrant"的输出.

To the vagrant problem: By default Vagrant mounted the folder of host Vagrant file to '/vagrant'. Test the output of 'ls -l /vagrant' if the basic file system mount works.

"ls"命令应将您的Vagrant文​​件显示为"/vagrant"中的最小值.

The 'ls' command should show your Vagrantfile as a minimum in '/vagrant'.

如果Vagrantfile在虚拟机中可见,则挂载基本上与vagrant一​​起使用.

If the Vagrantfile is visible in the virtual machine basically the mount works with vagrant.

host.vm.synced_folder "salt/", "/srv/salt"
host.vm.synced_folder "pillar/", "/srv/pillar"

似乎您相对于Vagrantfile挂载了其他文件夹.在这种情况下,您可以在内部修改VM,以将其链接到所需的dest文件夹.

It seem you mount your additional folder relative to your Vagrantfile. In that case you can modify your VM internally to link them to the desired dest folder.

例如,您可以在VM的置备状态下执行此操作.

You can do that in the provision state of your VM for example.

# Vagrantfile snippet
config.vm.provision "shell", inline: <<-SHELL
ln -s /vagrant/salt /srv/salt
ln -s /vagrant/pillar /srv/pillar  
SHELL

也许此文件在配置时不可用,然后在您首次登录后将其作为一项任务运行,或者将类似于VM的/etc/rc.local的内容运行

Maybe this file are not available at provision time then run them as one time task after your first login or put something similar to /etc/rc.local of your VM

这篇关于无法在Vagrant中挂载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆