Bahadır Can
Tech notes about Cloud, DevOps and AI

Tech notes about Cloud, DevOps and AI

Solution for unable to mount shared folders to Vagrant VM

Bahadır Can's photo
Bahadır Can
·Oct 22, 2021·

5 min read

Subscribe to my newsletter and never miss my upcoming articles

When does this error happen?

When using CentOS VM deployed with vagrant, update kernel to latest:

dnf upgrade

Stop/start VM from CLI

    vagrant halt
    vagrant up

VM starts but can't mount shared folders.

C:\boxes\centos8> vagrant up
    Bringing machine 'default' up with 'virtualbox' provider...
    ==> default: Checking if box 'bento/centos-8' version '202109.10.0' is up to date...
    ==> default: Clearing any previously set forwarded ports...
    ==> default: Clearing any previously set network interfaces...
    ==> default: Preparing network interfaces based on configuration...
        default: Adapter 1: nat
    ==> default: Forwarding ports...
        default: 22 (guest) => 2222 (host) (adapter 1)
    ==> default: Booting VM...
    ==> default: Waiting for machine to boot. This may take a few minutes...
        default: SSH address: 127.0.0.1:2222
        default: SSH username: vagrant
        default: SSH auth method: private key
    ==> default: Machine booted and ready!
    ==> default: Checking for guest additions in VM...
        default: No guest additions were detected on the base box for this VM! Guest
        default: additions are required for forwarded ports, shared folders, host only
        default: networking, and more. If SSH fails on this machine, please install
        default: the guest additions and repackage the box to continue.
        default:
        default: This is not an error message; everything may continue to work properly,
        default: in which case you may ignore this message.
    ==> default: Mounting shared folders...
        default: /vagrant => C:/boxes/centos8
    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,_netdev vagrant /vagrant

    The error output from the command was:

    /sbin/mount.vboxsf: mounting failed with the error: No such device
    PS C:\boxes\centos8>

Root Cause:

Support for newer Linux Kernels is not available for the currently installed Oracle VM Virtual Box Manager. Check the following page for more info for which release adds support for newer kernel versions: https://www.virtualbox.org/wiki/Changelog

Solution:

Update Oracle VM Virtual Box Manager by removing the old version and installing the new version. Normally this step does not erase your VM but take your backup anyways. Install vagrant-vbguest plugin from cli.

vagrant plugin install vagrant-vbguest

Run vagrant up once again. The problem should be solved.

C:\boxes\centos8> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-8' version '202109.10.0' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address: 127.0.0.1:2222
    default: SSH username: vagrant
    default: SSH auth method: private key
==> default: Machine booted and ready!
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.26
Going on, assuming VBoxService is correct...
[default] GuestAdditions versions on your host (6.1.28) and guest (6.1.26) do not match.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.26
Going on, assuming VBoxService is correct...
Last metadata expiration check: 0:44:36 ago on Fri 22 Oct 2021 05:36:16 AM UTC.
Package binutils-2.30-93.el8.x86_64 is already installed.
Package make-1:4.2.1-10.el8.x86_64 is already installed.
Package perl-interpreter-4:5.26.3-419.el8_4.1.x86_64 is already installed.
Package bzip2-1.0.6-26.el8.x86_64 is already installed.
Dependencies resolved.
================================================================================
 Package                  Arch      Version                  Repository    Size
================================================================================
Installing:
 elfutils-libelf-devel    x86_64    0.182-3.el8              baseos        59 k
 gcc                      x86_64    8.4.1-1.el8              appstream     23 M
 kernel-devel             x86_64    4.18.0-305.19.1.el8_4    baseos        18 M
Installing dependencies:
 annobin                  x86_64    9.50-1.el8               appstream    107 k
 cpp                      x86_64    8.4.1-1.el8              appstream     10 M
 glibc-devel              x86_64    2.28-151.el8             baseos       1.0 M
 glibc-headers            x86_64    2.28-151.el8             baseos       478 k
 isl                      x86_64    0.16.1-6.el8             appstream    841 k
 kernel-headers           x86_64    4.18.0-305.19.1.el8_4    baseos       7.1 M
 libmpc                   x86_64    1.1.0-9.1.el8            appstream     61 k
 libpkgconf               x86_64    1.4.2-1.el8              baseos        35 k
 libxcrypt-devel          x86_64    4.1.1-4.el8              baseos        25 k
 pkgconf                  x86_64    1.4.2-1.el8              baseos        38 k
 pkgconf-m4               noarch    1.4.2-1.el8              baseos        17 k
 pkgconf-pkg-config       x86_64    1.4.2-1.el8              baseos        15 k
 zlib-devel               x86_64    1.2.11-17.el8            baseos        58 k

Transaction Summary
================================================================================
Install  16 Packages

Total download size: 62 M
Installed size: 147 M
Downloading Packages:
...

...
Installed:
  annobin-9.50-1.el8.x86_64
  cpp-8.4.1-1.el8.x86_64
  elfutils-libelf-devel-0.182-3.el8.x86_64
  gcc-8.4.1-1.el8.x86_64
  glibc-devel-2.28-151.el8.x86_64
  glibc-headers-2.28-151.el8.x86_64
  isl-0.16.1-6.el8.x86_64
  kernel-devel-4.18.0-305.19.1.el8_4.x86_64
  kernel-headers-4.18.0-305.19.1.el8_4.x86_64
  libmpc-1.1.0-9.1.el8.x86_64
  libpkgconf-1.4.2-1.el8.x86_64
  libxcrypt-devel-4.1.1-4.el8.x86_64
  pkgconf-1.4.2-1.el8.x86_64
  pkgconf-m4-1.4.2-1.el8.noarch
  pkgconf-pkg-config-1.4.2-1.el8.x86_64
  zlib-devel-1.2.11-17.el8.x86_64

Complete!
Copy iso file C:\Program Files\Oracle\VirtualBox\VBoxGuestAdditions.iso into the box /tmp/VBoxGuestAdditions.iso
Mounting Virtualbox Guest Additions ISO to: /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
Installing Virtualbox Guest Additions 6.1.28 - guest version is 6.1.26
Verifying archive integrity... All good.
Uncompressing VirtualBox 6.1.28 Guest Additions for Linux........
VirtualBox Guest Additions installer
Removing installed version 6.1.26 of VirtualBox Guest Additions...
Copying additional installer modules ...
Installing additional modules ...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Building the VirtualBox Guest Additions kernel
modules.  This may take a while.
VirtualBox Guest Additions: To build modules for other installed kernels, run
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup <version>
VirtualBox Guest Additions: or
VirtualBox Guest Additions:   /sbin/rcvboxadd quicksetup all
VirtualBox Guest Additions: Building the modules for kernel
4.18.0-305.19.1.el8_4.x86_64.
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
Unmounting Virtualbox Guest Additions ISO from: /mnt
==> default: Checking for guest additions in VM...
==> default: Mounting shared folders...
    default: /vagrant => C:/boxes/centos8
==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> default: flag to force provisioning. Provisioners marked to run always will still run.
C:\boxes\centos8>
 
Share this