Vagrant error "Failed to mount folders in Linux guest" after halt or reload

11,464

Solution 1

It turns out, upgrading the Linux kernel will cause the Virtual Box Guest Additions to stop working until they are rebuilt by running the following command in the VM

sudo /etc/init.d/vboxadd setup

I had upgraded the kernel without thinking about it when I ran yum update (similar to apt-get upgrade) to get updates to other software.

Alternatively, if you install the dkms package as described here, then the kernel module should be automatically updated when the kernel is updated.

Solution 2

To fix this issue virtual box addition has to be installed. For example, I use Centos 7. Firstly download centos 7 minimal and then install guest addition, please see all steps below

  1. Download centos 7

    vagrant init centos/7

    vagrant up

    vagrant ssh

  2. Install Guest addition for virtual box

    yum update

    reboot

    vagrant ssh

    yum update kernel

    reboot

    vagrant ssh

    yum groupinstall "Development tools"

    yum install kernel-devel

    yum install wget

    wget http://download.virtualbox.org/virtualbox/5.0.2/VBoxGuestAdditions_5.0.2.iso

    sudo mkdir /media/VBoxGuestAdditions

    sudo mount -o loop,ro VBoxGuestAdditions_5.0.2.iso /media/VBoxGuestAdditions

    sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run rm VBoxGuestAdditions_5.0.2.iso

    sudo umount /media/VBoxGuestAdditions

    sudo rmdir /media/VBoxGuestAdditions

    sudo /etc/init.d/vboxadd setup

    sudo chkconfig --add vboxadd

    sudo chkconfig vboxadd on

    exit

  3. Package new box

    vagrant package --base my-virtual-machine

Solution 3

Hit the same issue, but with a different fix: I already had dkms installed (virtualbox-guest-dkms under Debian Jessie).

The thing was that the module «vboxsf» wasn't loaded automatically, and running mount shared_directory didn't work (No such file or directory error).

But after running modprobe vboxsf, the mounting was fine.

So I edited /etc/modules and appended vboxsf on a new line: problem solved!

Side note: if running modprobe vboxsf ends up on a error, you don't have the vboxsf module installed, so you should install DKMS module first.

Solution 4

Right after I got the same error I did this:

$ vagrant ssh
$ sudo apt-get update
$ exit

then installed vagrant-vbguest

$ vagrant plugin install vagrant-vbguest

then

$ vagrant halt
$ vagrant up

and it worked!

Looking at the logs it seems that vagrant-vbguest did some cleanup in terms of vbguest additions on the guest (the VM).

[default] GuestAdditions versions on your host (4.3.38) and guest (4.3.10) do not match.
 * Stopping VirtualBox Additions
   ...done.
rmmod: ERROR: Module vboxsf is not currently loaded
rmmod: ERROR: Module vboxguest is not currently loaded
Reading package lists...
Building dependency tree...
Reading state information...
The following packages will be REMOVED:
  virtualbox-guest-dkms* virtualbox-guest-utils* virtualbox-guest-x11*
0 upgraded, 0 newly installed, 3 to remove and 12 not upgraded.
After this operation, 12.1 MB disk space will be freed.
(Reading database ... 113238 files and directories currently installed.)
Removing virtualbox-guest-dkms (4.3.10-dfsg-1ubuntu5) ...
Error! Could not locate dkms.conf file.
File:  does not exist.
Removing virtualbox-guest-x11 (4.3.10-dfsg-1ubuntu5) ...
Purging configuration files for virtualbox-guest-x11 (4.3.10-dfsg-1ubuntu5) ...
Removing virtualbox-guest-utils (4.3.10-dfsg-1ubuntu5) ...
Purging configuration files for virtualbox-guest-utils (4.3.10-dfsg-1ubuntu5) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for libc-bin (2.19-0ubuntu6.9) ...
Reading package lists...
Building dependency tree...
Reading state information...
dkms is already the newest version.
linux-headers-3.13.0-91-generic is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.
Copy iso file /Applications/VirtualBox.app/Contents/MacOS/VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
mount: block device /tmp/VBoxGuestAdditions.iso is write-protected, mounting read-only
Installing Virtualbox Guest Additions 4.3.38 - guest version is 4.3.10
Verifying archive integrity... All good.
Uncompressing VirtualBox 4.3.38 Guest Additions for Linux............
VirtualBox Guest Additions installer
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox DKMS kernel modules ...done.
Removing existing VirtualBox non-DKMS kernel modules ...done.
Building the VirtualBox Guest Additions kernel modules ...done.
Doing non-kernel setup of the Guest Additions ...done.
Starting the VirtualBox Guest Additions ...done.

P.S. I'm on OS X using the following software versions:

$ vagrant plugin list
solve (0.8.2)
  - Version Constraint: 0.8.2
vagrant-berkshelf (4.1.0)
vagrant-hostmanager (1.5.0)
  - Version Constraint: 1.5.0
vagrant-hostsupdater (1.0.2)
vagrant-omnibus (1.3.1)
  - Version Constraint: 1.3.1
vagrant-proxyconf (1.2.0)
  - Version Constraint: 1.2.0
vagrant-share (1.1.5, system)
vagrant-vbguest (0.12.0)

$ VBoxManage --version
4.3.38r106717

$ vagrant --version
Vagrant 1.8.4

Hope this helps.

Solution 5

Just install the Vagrant plugin vagrant-vbguest, it can keep your VirtualBox Guest Additions up to date.

vagrant plugin install vagrant-vbguest
Share:
11,464
Tom Panning
Author by

Tom Panning

A developer who is always in learning mode.

Updated on June 07, 2022

Comments

  • Tom Panning
    Tom Panning almost 2 years

    I'm trying to use a Vagrant box from someone else, and it works fine when I first start it, but after I stop it and restart it with either vagrant halt and vagrant up, or vagrant reload, I get the following error message:

    Failed to mount folders in Linux guest. This is usually because
    the "vboxsf" file system is not available. Please verify that
    the guest additions are properly installed in the guest and
    can work properly. The command attempted was:
    
    mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
    mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant
    
    The error output from the last command was:
    
    /sbin/mount.vboxsf: mounting failed with the error: No such device
    

    Right now, searching for this error message turns up a lot of people having trouble with a bug Virtual Box 4.3.10, but that's not the problem I'm having.

  • Terry Wang
    Terry Wang over 9 years
    True, if dkms is properly configured, it should take care of automatically rebuilding the kernel module after a kernel update.
  • Tom Panning
    Tom Panning over 9 years
    @TerryWang Thanks, I've updated the answer to point that out. I linked to the best resource that I could find on dkms, but feel free to change the link if there's a better one.
  • matrim_c
    matrim_c over 6 years
    +1 Running a CentOS machine. Was unable to get the latest VBoxGuestAdditions tools, or mount my shared folder. For me, I needed to only follow your instructions until mounting the VBoxGuestAdditions - my VM was already up to date for kernel / dev tools. Once the ISO was mounted, running vagrant reload worked, using the mounted drive to install the missing tools.
  • Christian Long
    Christian Long over 6 years
    This took care of the problem for me. The vagrant-vbguest plugin installed the kernel and kernel-devel packages, and then updated the Guest Additions.
  • Sam Habiel
    Sam Habiel about 6 years
    It's /etc/init.d/vboxdrv on my system now.