Oracle VirtualBox上にOracle Linux 7.1をインストールするときにはまったこと

Oracle VirtualBox 上に Oracle Linux 7.1 のゲストOSを構成したとき、Guest Additionsのインストールにはまったので、対応方法をメモしておきます。

問題の症状

Oracle VirtualBox Guest Additions は、通常以下の手順でインストールします(ゲストOSのインストールは完了している前提)。

  1. Guest Additions のディスクイメージをマウントする
    • ツールバーの [デバイス] > [Guest Additions CD イメージの挿入]
  2. ゲストOS上で、マウントされたディスクのアイコンをダブルクリック
    1. で開いたウィンドウで[ソフトウェアの実行]をクリック

上記の手順で、3.までをおこなうと、以下のようなエラーが発生します。

Verifying archive integrity... All good.
…
Installing additional modules ...
Removing existing VirtualBox non-DKMS kernel modules[  OK  ]
Building the VirtualBox Guest Additions kernel modules
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-uek-devel-3.8.13-55.1.6.el7uek.x86_64

Building the main Guest Additions module[失敗]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
…
Installing graphics libraries and desktop services components[  OK  ]
Press Return to close this window...

また、エラーログを確認すると、以下のように出力されています。

/tmp/vbox.0/Makefile.include.header:97: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make again.  中止.
Creating user for the Guest Additions.
Creating udev rule for the Guest Additions kernel module.

これはGuestAdditionがkernelのソースコードを必要としているのに、システムにソースコードがインストールされていないために発生するらしいです。*1

対策

ここで慌てずに、エラーメッセージをよく見ると、以下のような記述があるはずです。

module compilation fails then this could be the reason.
The missing package can be probably installed with
yum install kernel-uek-devel-3.8.13-55.1.6.el7uek.x86_64

上記メッセージにしたがって、以下のコマンドを実行します。 このコマンドは、rootでログインして実行する必要があります。

$ yum install kernel-uek-devel-3.8.13-55.1.6.el7uek.x86_64

その後、ゲストOSをリブートし、Guest Additions のインストールを再度おこなえば、正常にインストールできると思います。