如何在 Fedora/CentOS 上修复此问题

如何在 Fedora/CentOS 上修复此问题

我收到此错误:

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)

错误是:

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

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

答案1

确保您安装了内核头文件包。

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)

编辑:

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

以 root 身份

$ nano /etc/apt/sources.list 

在下面添加一行以进行挤压

deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free

然后添加 apt-secure 的 Oracle 公钥

$ wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

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

apt-get update
apt-get install virtualbox-4.2

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

apt-get install dkms

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

答案2

如何在 Fedora/CentOS 上修复此问题

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

$ sudo yum update     

如果它更新了内核版本,您将必须重新启动,以便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 

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

资料来源:

答案3

@hhh 你应该只搜索linux-headers并找到适合你的架构的。就我而言:

# aptitude search linux-headers      
v   linux-headers                                                       -                                                                              
p   linux-headers-2.6-amd64                                             - Header files for Linux amd64 configuration (dummy package)                   
p   linux-headers-3.2.0-4-all                                           - All header files for Linux 3.2 (meta-package)                                
p   linux-headers-3.2.0-4-all-amd64                                     - All header files for Linux 3.2 (meta-package)                                
i A linux-headers-3.2.0-4-amd64                                         - Header files for Linux 3.2.0-4-amd64                                         
i A linux-headers-3.2.0-4-common                                        - Common header files for Linux 3.2.0-4                                        
p   linux-headers-3.2.0-4-common-rt                                     - Common header files for Linux 3.2.0-4-rt                                     
p   linux-headers-3.2.0-4-rt-amd64                                      - Header files for Linux 3.2.0-4-rt-amd64                                      
i   linux-headers-amd64                                                 - Header files for Linux amd64 configuration (meta-package)                    
p   linux-headers-rt-amd64                                              - Header files for Linux rt-amd64 configuration (meta-package)

因此,就我而言,我有一个 64 位架构,我必须安装linux-headers-amd64

另一件事是apt-get add不存在的。apt-get用替换apt-key

答案4

尝试:

yum install kernel* dkms gcc

然后

yum install kernel-uek-devel

然后重新启动机器

相关内容