歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux內核 >> Linux內核簡單編譯

Linux內核簡單編譯

日期:2017/3/1 9:52:47   编辑:Linux內核

Linux內核,顧名思義,就是linux系統的核心,負責管理系統的進程、內存、設備驅動程序、文件和網絡系統,決定著系統的性能和穩定性。

簡單的介紹點內核的相關知識,如有不當之處,還請大家批評指正!

本文以我實驗的系統為例,系統為Red Hat 5.5

[root@localhost yum.repos.d]# lsb_release -a
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Release: 5.5
Codename: Tikanga


######內核的簡單介紹###########


在RHEL5.5 Linux系統中內核文件存放的路徑是/boot目錄下,文件名字為vmlinuz-2.6.18-194.el5

[root@localhost boot]# pwd
/boot
[root@localhost boot]# ls
config-2.6.18-194.el5 symvers-2.6.18-194.el5.gz
grub System.map-2.6.18-194.el5
initrd-2.6.18-194.el5.img vmlinuz-2.6.18-194.el5
lost+found
[root@localhost boot]# ll -h vmlinuz-2.6.18-194.el5
-rw-r--r-- 1 root root 1.8M 3?17 2010 vmlinuz-2.6.18-194.el5

如何查看內核版本?

[root@localhost boot]# uname -r
2.6.18-194.el5


我們來詳細分析一下這些數字代表的什麼

2表示主版本號,其實這點跟目前最新的微信5.0.2是一致的;6是次版本號;18是修正號;-194是redhat對內核官方網站發布的內核版本進行修正的修正號;el5是redhat linux的發行版本,代表的enterprise linux 5 的縮寫。

#########編譯內核##################

在編譯內核前,關於內核定制的必要性就不必多講了,無非是給漏洞打補丁或者增加新的功能。

編譯前,必須要確認gcc環境已經安裝好

[root@localhost ~]# rpm -qa | grep gcc
libgcc-4.1.2-48.el5
gcc-4.1.2-48.el5
compat-libgcc-296-2.96-138
gcc-gfortran-4.1.2-48.el5
gcc-c++-4.1.2-48.el5

如果沒有裝的話可以yum install -y *gcc* ncurses-devel(這個也是必須的)

開始編譯

1、我們從官網上下載新的內核源碼文件包

[root@localhost ~]# wget https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.4.tar.bz2 --no-check-certificate

[root@localhost ~]# tar xf linux-2.6.39.4.tar.bz2

[root@localhost ~]# cd linux-2.6.39.4
[root@localhost linux-2.6.39.4]# pwd
/root/linux-2.6.39.4
[root@localhost linux-2.6.39.4]# ls
arch fs MAINTAINERS security
block include Makefile sound
COPYING init mm tools
CREDITS ipc net usr
crypto Kbuild README virt
Documentation Kconfig REPORTING-BUGS
drivers kernel samples
firmware lib scripts

2、配置內核的准備工作 make mrproper

此目的是刪除所有此前編譯生成的文件和內核配置文件,如果你的內核跟我的一樣是剛下載的就不需要執行這一步了;

3、配置內核

[root@localhost ~]# make menuconfig

當輸入這個命令時,會自動彈出下面的桌面對話,所以我不確定這個能不能用在ssh遠程客戶端進行編譯。

Linux Kernel 的詳細介紹:請點這裡
Linux Kernel 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved