Gangmax Blog

Resolve the problem when installing virtualbox on Ubuntu

之前我在机器上安装virtualbox都是直接执行apt-get命令即可:

1
sudo apt-get install virtualbox-ose

但是今天执行之后启动virtualbox发现有如下错误:

1
No suitable module for running kernel found

搜索了一些文章,比如这里说是dkms的问题,我重新安装后错误依旧。然后我尝试从官方网站添加官方apt source并安装:

1
2
3
4
deb http://download.virtualbox.org/virtualbox/debian lucid contrib non-free # Add this line to the "/etc/apt/sources.list" file.
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add - # Run this command to add the Oracle public key before running "sudo apt-get update".
sudo apt-get update
sudo apt-get install virtualbox-4.1

安装最后有以下日志输出:

1
2
3
4
5
6
7
8
9
 * Stopping VirtualBox kernel modules                                    [ OK ] 
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS
Error! Your kernel headers for kernel 2.6.38-13-generic-pae cannot be found at
/lib/modules/2.6.38-13-generic-pae/build or /lib/modules/2.6.38-13-generic-pae/source.

* Failed, trying without DKMS
* Recompiling VirtualBox kernel modules
* Look at /var/log/vbox-install.log to find out what went wrong

运行virtualbox有以下错误:

1
2
3
4
5
6
7
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (2.6.38-13-generic-pae) or it failed to
load. Please recompile the kernel module and install it by

sudo /etc/init.d/vboxdrv setup

You will not be able to start VMs until this problem is fixed.

看来遇到了和安装”virtualbox-ose”同样的错误。

针对安装过程中的”Your kernel headers for kernel 2.6.38-13-generic-pae cannot be found”的错误提示,我想到应该是因为我安装目前使用的”2.6.38-13-generic-pae”内核时,只安装了”image” package而没有安装”headers” package所致。于是安装:

1
sudo apt-get install linux-headers-2.6.38-13-generic-pae 

成功安装之后再次安装”virtualbox-ose”(如果可以选择,我还是更愿意选择完全开源的实现):

1
sudo apt-get install virtualbox-ose

再次运行virtualbox,依然遇到同样的错误。卸载它,重新安装官方的最新版本”virtualbox-4.1”:

1
sudo apt-get install virtualbox-4.1

安装中有以下日志输出:

1
2
3
4
5
6
7
8
9
10
11
12
正在设置 virtualbox-4.1 (4.1.8-75467~Ubuntu~lucid) ...
addgroup: 组"vboxusers"已经是系统组。退出。
* Stopping VirtualBox kernel modules [ OK ]
* Uninstalling old VirtualBox DKMS kernel modules [ OK ]
* Trying to register the VirtualBox kernel modules using DKMS [ OK ]
* Starting VirtualBox kernel modules [ OK ]

正在设置 libsdl-ttf2.0-0 (2.0.9-1build1) ...

正在处理用于 python-central 的触发器...
正在处理用于 libc-bin 的触发器...
ldconfig deferred processing now taking place

再次运行”virtualbox”,这次已经没有错误了,问题解决。

我搜索了一下,kernel headers的作用是”Kernel-headers includes the C header files for the Linux kernel”,而且从搜索结果中我看到很多VMware的错误也和kernel headers相关,看来vm的运行需要依赖于这些headers文件。

至于为什么ubuntu lucid源中的”virtualbox-ose”无法正常运行,可能是因为它和我使用的linux kernel(2.6.38-13-generic-pae)版本有不匹配的地方,而最新的官方virtualbox-4.1就没有问题了。

Comments