Vagrant+VirtualBoxにおける仮想マシン立ち上げ時にvagrant up
すると以下のエラーが発生しました。
解決までの道筋を記事にまとめてみました
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:
: No such device
どうやらGuest AdditionsとVirtualBoxのバージョンの不一致で起きるエラーのようです。
こちらのエラーを解決するためにまずVagrant用のvbguestプラグインをインストールする必要があります。以下のコマンドを実行しましょう。
[vagrant@localhost ~]$vagrant plugin install vagrant-vbguest
次に、VirtualBoxのバージョンと仮想マシン内のGuest Additionsのバージョンが異なる場合に、その差を自動的に解消してくれる機能を持つvbguestプラグインを実行します。
[vagrant@localhost ~]$vagrant vbguest
以上のコマンドが実行できたらvagrantを再起動しましょう。
[vagrant@localhost ~]$vagrant reload
以上でGuest AdditionsとVirtualBoxのバージョンの不一致は解消したのですが、違うエラーが発生しました。
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims: 6.0.0
VBoxService inside the vm claims: 7.0.14
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 -xeu vboxadd.service" for details.
Redirecting to /bin/systemctl start vboxadd-service.service
Got different reports about installed GuestAdditions version:
Virtualbox on your host claims: 6.0.0
VBoxService inside the vm claims: 7.0.14
Going on, assuming VBoxService is correct...
VirtualBox Guest Additions: Starting.
VirtualBox Guest Additions: Setting up modules
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
6.1.82-99.168.amzn2023.x86_64. Please install them and execute
/sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted or 'rcvboxadd reload' triggered
VirtualBox Guest Additions: reloading kernel modules and services
VirtualBox Guest Additions: unable to load vboxsf kernel module, see dmesg
VirtualBox Guest Additions: kernel modules and services were not reloaded
The log file /var/log/vboxadd-setup.log may contain further information.
==> laravel: Checking for guest additions in VM...
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: Setting up modules
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
6.1.82-99.168.amzn2023.x86_64. Please install them and execute
/sbin/rcvboxadd setup
VirtualBox Guest Additions: Running kernel modules will not be replaced until
the system is restarted or 'rcvboxadd reload' triggered
VirtualBox Guest Additions: reloading kernel modules and services
VirtualBox Guest Additions: unable to load vboxsf kernel module, see dmesg
Stderr from the command:
VirtualBox Guest Additions: kernel modules and services were not reloaded
The log file /var/log/vboxadd-setup.log may contain further information.
VirtualBox Guest Additionsのエラーで共有フォルダがマウントできない問題のようです。
内容を詳しく見てみると、
VirtualBox Guest Additions: Kernel headers not found for target kernel
6.1.82-99.168.amzn2023.x86_64. Please install them and execute
/sbin/rcvboxadd setup
現在使用しているカーネルに対するヘッダーがインストールされていないため、VirtualBox Guest Additions のモジュールがビルドできないというエラーがでています。
カーネルを更新 & 必要なパッケージをインストールするために以下のコマンドを実行しましょう。
[vagrant@localhost ~]$ sudo yum -y update kernel && sudo yum -y install gcc kernel-devel kernel-headers make bzip2 perl
その後vagrant を再起動すると無事エラーが解決しました!
[vagrant@localhost ~]$vagrant reload