vagrant で CentOS を入れようとすると Guest Additions がエラーになる

かんたんに仮想マシンが作れる!というフレコミの割に毎回エラーで苦労するvagrantである。 今回の環境は以下の通り。
  • Windows10
  • VirtualBox 6.1.30
  • Vagrant 2.2.19
  • 使ったboxは bento/centos-8
vagrant init bento/centos-8 で設定ファイルを作り、vagrant up したところ以下のエラーが。
==> default: Mounting shared folders...
    default: /vagrant => D:/vagrant/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
知ってる知ってる、GuestAdditions のバージョンが合ってないからだろ?
Vagrant の Box の Guest Additions を最新化する方法 |
本稿では Vagrant の Box (ゲストマシン) にインストールされている Guest Additions を最新化する方法について解説します。
そんなときは、バージョンを合わせてくれるプラグインを以下のコマンドでインストールすればOK。

vagrant plugin install vagrant-vbguest

で、vagrant reload したんだけど今度はこんなことに。
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
[default] GuestAdditions seems to be installed (6.1.30) correctly, but not running.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
Redirecting to /bin/systemctl start vboxadd.service
Job for vboxadd.service failed because the control process exited with error code.
See "systemctl status vboxadd.service" and "journalctl -xe" for details.
Redirecting to /bin/systemctl start vboxadd-service.service
Job for vboxadd-service.service failed because the control process exited with error code.
See "systemctl status vboxadd-service.service" and "journalctl -xe" for details.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
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: Kernel headers not found for target kernel
4.18.0-348.2.1.el8_5.x86_64. Please install them and execute
  /sbin/rcvboxadd setup
ValueError: File context for /opt/VBoxGuestAdditions-6.1.30/other/mount.vboxsf already defined
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
==> 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.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/usr/sbin/rcvboxadd setup

Stdout from the command:

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: Kernel headers not found for target kernel
4.18.0-348.2.1.el8_5.x86_64. Please install them and execute
  /sbin/rcvboxadd setup


Stderr from the command:

ValueError: File context for /opt/VBoxGuestAdditions-6.1.30/other/mount.vboxsf already defined
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
初めて見るエラーだ。
「VirtualBox Guest Additions: Kernel headers not found for target kernel」とあり、ググったところ、カーネルのバージョンが合ってない場合に出るとのこと。
Vagrantのマウントエラーでわかるバージョン不一致の解決方法 - Qiita
###はじめにVirtualBox+Vagrantで仮想環境を立ち上げる前に通知が来ていたのでVirtualBoxのバージョンアップしてVagarant upしたらエラーが出てしまった∑(; ̄□…
vagrant ssh でログインして、カーネルのアップデートを実行。
$ sudo yum -y update kernel && sudo yum -y install gcc kernel-devel kernel-headers make bzip2 perl
今度こそOKだろうと vagrant reload したらまたエラー。
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
[default] GuestAdditions seems to be installed (6.1.30) correctly, but not running.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
Redirecting to /bin/systemctl start vboxadd.service
Job for vboxadd.service failed because the control process exited with error code.
See "systemctl status vboxadd.service" and "journalctl -xe" for details.
Redirecting to /bin/systemctl start vboxadd-service.service
Job for vboxadd-service.service failed because the control process exited with error code.
See "systemctl status vboxadd-service.service" and "journalctl -xe" for details.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
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-348.2.1.el8_5.x86_64.

VirtualBox Guest Additions: Look at /var/log/vboxadd-setup.log to find out what
went wrong
ValueError: File context for /opt/VBoxGuestAdditions-6.1.30/other/mount.vboxsf already defined
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
==> 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.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/usr/sbin/rcvboxadd setup

Stdout from the command:

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-348.2.1.el8_5.x86_64.

VirtualBox Guest Additions: Look at /var/log/vboxadd-setup.log to find out what
went wrong


Stderr from the command:

ValueError: File context for /opt/VBoxGuestAdditions-6.1.30/other/mount.vboxsf already defined
modprobe vboxguest failed
The log file /var/log/vboxadd-setup.log may contain further information.
今度は
VirtualBox Guest Additions: Building the modules for kernel 4.18.0-348.2.1.el8_5.x86_64.
VirtualBox Guest Additions: Look at /var/log/vboxadd-setup.log to find out what went wrong
とあるので、なんかビルドしようとしてエラーになってる? /var/log/vboxadd-setup.log にエラーの詳細があるというので見てみると。
Building the main Guest Additions 6.1.30 module for kernel 4.18.0-348.2.1.el8_5.x86_64.
Error building the module.  Build output follows.
make V=1 CONFIG_MODULE_SIG= CONFIG_MODULE_SIG_ALL= -C /lib/modules/4.18.0-348.2.1.el8_5.x86_64/build M=/tmp/vbox.0 SRCROOT=/tmp/vbox.0 -j2 modules
make[1]: warning: -jN forced in submake: disabling jobserver mode.
Makefile:990: *** "Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel".  Stop.
make: *** [/tmp/vbox.0/Makefile-footer.gmk:117: vboxguest] Error 2
Could not find the X.Org or XFree86 Window System, skipping.
modprobe vboxguest failed
please install libelf-dev, libelf-devel or elfutils-libelf-devel とある。 ということで elfutils-libelf-devel を入れてみる。
$ sudo dnf install -y epel-release
$ sudo dnf install -y elfutils-libelf-devel
そんで vagrant reload
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
[default] GuestAdditions seems to be installed (6.1.30) correctly, but not running.
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims:
VBoxService inside the vm claims: 6.1.30
Going on, assuming VBoxService is correct...
Redirecting to /bin/systemctl start vboxadd.service
Redirecting to /bin/systemctl start vboxadd-service.service
==> default: Checking for guest additions in VM...
==> default: Configuring and enabling network interfaces...
==> default: Mounting shared folders...
    default: /vagrant => D:/vagrant/centos8
やったーーー!成功ぉおおーー!!

コメント