Unable to mount files in Vagrant

2019-08-19 07:50发布

Error description

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.

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

Troubleshooting Vagrant

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

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"

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.

Updates

1)

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.

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

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*

1条回答
2楼-- · 2019-08-19 08:20

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.

The 'ls' command should show your Vagrantfile as a minimum in '/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"

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.

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

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

查看更多
登录 后发表回答