无法安装 VIrtualbox,`"Specify KERN_DIR=<directory>"` -- 将 Virtual Box 安装到 Debian?

hhh*_*hhh 39 debian virtualbox linux-kernel

我收到此错误:

Makefile:181: *** 错误:无法找到当前 Linux 内核的来源。指定 KERN_DIR= 并再次运行 Make。停止。

基本上我在做:

$ sudo /etc/init.d/vboxdrv setup
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-devel-2.6.32-573.18.1.el6.x86_64

Building the main Guest Additions module                   [FAILED]
(Look at /var/log/vboxadd-install.log to find out what went wrong)
Run Code Online (Sandbox Code Playgroud)

错误是:

Makefile:181: *** 错误:无法找到当前 Linux 内核的来源。指定 KERN_DIR= 并再次运行 Make。停止

这是什么错误以及如何修复它?

Bra*_*don 35

确保安装内核头文件包。

http://www.cyberciti.biz/faq/howto-install-kernel-headers-package

Make sure you have updated version

Type the following command
$ sudo apt-get update

OR as root user enter:
# apt-get update

Search for kernel version (optional)

Type the following command:
$ apt-cache search linux-headers-$(uname -r)

Install linux-header package under Debina or Ubuntu Linux

Type the following command:
$ sudo apt-get install linux-headers-$(uname -r)

OR as root user:
# apt-get install linux-headers-$(uname -r)
Run Code Online (Sandbox Code Playgroud)

编辑:

我只是碰巧需要将它也安装在我自己的服务器上,并且在尝试在 debian 存储库中使用 virtualbox 时遇到了同样的错误。我继续添加 VirtualBox repo 并从那里安装。这更好,因为它们是最新的。

作为根

$ nano /etc/apt/sources.list 
Run Code Online (Sandbox Code Playgroud)

在下面添加行以进行挤压

deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free
Run Code Online (Sandbox Code Playgroud)

然后添加 apt-secure 的 Oracle 公钥

$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
Run Code Online (Sandbox Code Playgroud)

然后运行更新并安装最新的 4.2

apt-get update
apt-get install virtualbox-4.2
Run Code Online (Sandbox Code Playgroud)

安装 dkms 包以确保 VirtualBox 主机内核模块是最新的

apt-get install dkms
Run Code Online (Sandbox Code Playgroud)

去应该不错。从 VirtualBox 的 Linux 网站上获得了这些说明,该网站目前似乎已关闭,但链接是https://www.virtualbox.org/wiki/Linux_Downloads

  • 即使我执行了上述命令,命令 `apt-cache search linux-headers-$(uname -r)` 也没有返回任何内容。 (2认同)

use*_*153 29

如何为 Fedora/CentOS 解决这个问题

首先确保您安装的软件包(尤其是内核)是最新的:

$ sudo yum update     
Run Code Online (Sandbox Code Playgroud)

如果它更新内核版本,您将必须重新启动以uname -r匹配/usr/src/kernels/. 然后

$ sudo yum install kernel-devel gcc
$ echo export KERN_DIR=/usr/src/kernels/`uname -r` >> ~/.bashrc
$ source ~/.bashrc     # to set the variable in your current shell
$ sudo echo $KERN_DIR  # verify the value is set
$ sudo ls $KERN_DIR    # verify the directory exists 
Run Code Online (Sandbox Code Playgroud)

编译后 VirtualBox 内核模块应该可以正常工作。

资料来源: