ことの発端
vagrantを利用しDockerの環境を作成しようとしていました。
Dockerをインストールする際、最初にyum update
を実行する必要があったのですが、これを実行した後に、VMを再起動(vagrant halt
-> vagrant up
)すると以下のようなエラーが発生してしまいました。
$ vagrant up
・・・
==> default: Machine booted and ready!
GuestAdditions seems to be installed (5.0.6) correctly, but not running.
bash: line 2: /etc/init.d/vboxadd: No such file or directory
bash: line 2: /etc/init.d/vboxadd: No such file or directory
==> default: 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!
/etc/init.d/vboxadd setup
Stdout from the command:
Stderr from the command:
bash: line 2: /etc/init.d/vboxadd: No such file or directory
なにやら、guest additions
のチェックで失敗しているような感じ。この時点では、さっぱり訳がわからない感じでした。
ひとまず、VMに入ってみる
ひとまず、VMに入ってみたところ無事にログインまではできていました。
そしたら、あのエラーは一体何だったのかが気になるところだったのですが、その疑問はすぐにわかりました。
それは・・・/vagrant
ディレクトリがホスト側とのディレクトリと共有ができていなかったようでした。(厳密には、他にも影響があった気もしますが。)
Guest Additionsをインストールしてみる。
Guest Additions機能がうまく動いていないならば、それを改めてインストールしてみることに。
インストールまでは以下の手順で行いました。
- VMをシャットダウン(
vagrant halt
) - Virtual Box上から、対象のVMに対して 光学ドライブ を追加
- VMを起動(
vagrant up
) - Virtual Box上から、対象のVMをダブルクリック
- 対象のVMのメニュー上から、
Devices
->Insert Guest Additions CD images ...
を選択してGuest Additions CDを挿入 - ゲストOS上で、Guest Additions CDをマウント(
sudo mount -r /dev/cdrom /mnt
) - Guest Addtionsをインストール(
sudo sh VBoxLinuxAdditions.run
)
すると、結果として・・・
VirtualBox Guest Additions installer
Removing installed version 5.0.6 of VirtualBox Guest Additions...
Removing existing VirtualBox non-DKMS kernel modules[ OK ]
Copying additional installer modules ...
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[ OK ]
Building the VirtualBox Guest Additions kernel modules
The gcc utility was not found. If the following module compilation fails then
this could be the reason and you should try installing it.
The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-3.10.0-229.14.1.el7.x86_64
Building the main Guest Additions module[失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Doing non-kernel setup of the Guest Additions[ OK ]
Installing the Window System drivers
Could not find the X.Org or XFree86 Window System, skipping.
少し、予想はしていましたがBuilding the main Guest Additions module[失敗]
が示す通り、失敗していました。
心折れずにエラーをよく読んでみる。
エラーメッセージをよく確認してみると、以下のことが書いてありました。
- Building the VirtualBox Guest Additions kernel modules
The gcc utility was not found. If the following module compilation fails then
this could be the reason and you should try installing it.
(Virtual Box Guest Additionsを構築しようとしたけど、gcc utilityが見つからなかったよ。gcc utilityをインストールしてみ)
2. The headers for the current running kernel were not found. If the following
module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-devel-3.10.0-229.14.1.el7.x86_64
(現在動作しているkernelのヘッダが見つからなかったよ。yum install kernel-devel-3.10.0-229.14.1.el7.x86_64
コマンドを実行してみ)
なので、エラーメッージの指示に従って以下のコマンドを実行しました。
- sudo yum install gcc -y
- sudo yum install kernel-devel-3.10.0-229.14.1.el7.x86_64 -y
そして、最後に
3. sudo sh VBoxLinuxAdditions.run
を実行すると、エラーなくGuest Additionsがインストールできました。
念のため
最後に
- VMを再起動してもエラーメッセージが出ないこと
-
/vagrant
ディレクトリがホスト側とのディレクトリと共有できていること
がを確認し、問題は解消されていました。
補足情報
今回問題が発生した動作条件は以下の通りです。
- ホストOS : OS X El Capitan
- VM : Virtual Box 5.0.6
- ゲストOS : Cent OS 7.1