无法在Vagrant中挂载文件

时间:2018-05-24 13:47:21

标签: permissions vagrant mount privileges

错误说明

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

与Docker相关的错误讨论在另一个问题中找到: Unable to mount files in Docker

排除Vagrant

因此我无法将文件挂载到Vagrant框中(即使我有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中指定了这些语句,它适用于我的同事本地构建,但在我的构建中,这些文件不会被挂载或复制到框中:

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

结论

在复制文件时,我的本地计算机上似乎有些混乱,可能与我的用户配置方式以及将文件挂载到VM和容器的访问权限有关。 如果有人能够对此有所了解,我会很感激。

更新

1)

正如用户@BMitch建议我浏览了我的" Virtualbox Guest Additions"安装。
每当我更新我的软件包时,我都会将其记录到日志文件中,大约2个月前从update-20180405_153850.txt发现。

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) ...

但这对我来说没有意义..我的第一次运行它时,我的自举脚本(流氓和盒子)失败了:

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.

第二次运行它会成功,但会显示以下警告信息:

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,而不是在我的本地机器上。

但我改变了/usr/share/virtualbox/VBoxGuestAdditions.iso的文件模式,所以这可能会解决问题:

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*

1 个答案:

答案 0 :(得分:1)

对流浪者的问题: 默认情况下,Vagrant将主机Vagrant文​​件的文件夹挂载到'/ vagrant'。如果基本文件系统挂载有效,请测试'ls -l / vagrant'的输出。

'ls'命令应该在'/ vagrant'中将您的Vagrantfile显示为最小值。

如果Vagrantfile在虚拟机中可见,那么基本上mount可与vagrant一​​起使用。

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

您似乎在相对于Vagrantfile安装了附加文件夹。在这种情况下,您可以在内部修改VM以将它们链接到所需的dest文件夹。

例如,您可以在VM的配置状态中执行此操作。

# 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的内容添加到