如何在 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 存儲庫並從那裡安裝。這更好,因為它們更新了。

作為根用戶

$ 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-getapt-key.

答案4

嘗試:

yum install kernel* dkms gcc

然後

yum install kernel-uek-devel

然後重新啟動你的機器

相關內容