今天編譯安裝了Linux 2.6.34.13版本的內核(此前內核版本是2.6.32.5)。由於採用了原來系統的配置項,所以配置時比較省事。新內核啓動運行之後,目前聲卡,網卡等都工作正常。
編譯安裝Linux 2.6.34.13版本的內核過程如下:
1、下載內核
http://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.34/linux-2.6.34.13.tar.bz2
2、解壓,並將內核代碼放在/usr/src目錄下。
我的目錄組織如下所示:
yongmi@yongmi-hn:/usr/src$ ls -l
total 12
drwxr-xr-x 24 yongmi yongmi 4096 Dec 15 21:35 linux-2.6.34.13
drwxr-xr-x 4 root root 4096 Dec 2 21:13 linux-headers-2.6.32-5-686
drwxr-xr-x 4 root root 4096 Dec 2 21:13 linux-headers-2.6.32-5-common
lrwxrwxrwx 1 root root 26 Dec 2 21:13 linux-kbuild-2.6.32 -> ../lib/linux-kbuild-2.6.32
3、清除以前的配置
進入/usr/src/linux-2.6.34.13目錄,並運行以下命令。
make mrproper
該命令所做的事情是:Remove all generated files + config + various backup files
4、重新配置內核選項
配置內核選項可以使用下列選項:
Configuration targets:
config - Update current config utilising a line-oriented program
menuconfig - Update current config utilising a menu based program
xconfig - Update current config utilising a QT based front-end
gconfig - Update current config utilising a GTK based front-end
oldconfig - Update current config utilising a provided .config as base
localmodconfig - Update current config disabling modules not loaded
localyesconfig - Update current config converting local mods to core
silentoldconfig - Same as oldconfig, but quietly, additionally update deps
randconfig - New config with random answer to all options
defconfig - New config with default answer to all options
allmodconfig - New config selecting modules when possible
allyesconfig - New config where all options are accepted with yes
allnoconfig - New config where all options are answered with no
其中常用的命令是
make menuconfig
它以菜單分類的形式來配置內核選項。
由於我只是想編譯內核,對這些配置暫時不關心,所以直接使用了原來機器的配置。命令如下:
make oldconfig
運行該命令將以前存在的配置項直接拷貝過來,如果某個配置項原來沒有,而新內核又要求配置的話,程序會給出選擇,基本上使用默認值就可以。
這些配置項一般有三種選擇:
Y- 將該功能編譯進內核
N- 不將該功能編譯進內核
M-包含該功能,但是以模塊的形式存在。5、編譯內核
直接運行以下命令:
make bzImage
make modules
編譯完成之後會在/usr/src/linux-2.6.34.13/arch/x86/boot目錄下存在如下文件,這就是編譯之後的內核代碼。
-rw-r--r-- 1 root root 2.5M Dec 15 20:10 bzImage
6、安裝模塊與內核
首先按照模塊,命令如下:
make modules_install
模塊將安裝在下面這個目錄中
yongmi@yongmi-hn:/lib/modules$ ls -l
total 8
drwxr-xr-x 4 root root 4096 Dec 2 22:40 2.6.32-5-686
drwxr-xr-x 3 root root 4096 Dec 15 22:32 2.6.34.13
注:2.6.32-5-686是我原來內核的模塊文件,新內核模塊放在2.6.34.13中。
運行下面的命令會將內核安裝到boot目錄下:
make install
yongmi@yongmi-hn:/boot$ ls -lh
-rw-r--r-- 1 root root 109K Sep 23 09:40 config-2.6.32-5-686
-rw-r--r-- 1 root root 113K Dec 15 21:35 config-2.6.34.13
drwxr-xr-x 3 root root 4.0K Dec 15 22:38 grub
-rw-r--r-- 1 root root 8.4M Dec 2 19:06 initrd.img-2.6.32-5-686
-rw-r--r-- 1 root root 1.3M Sep 23 09:40 System.map-2.6.32-5-686
-rw-r--r-- 1 root root 1.3M Dec 15 21:35 System.map-2.6.34.13
-rw-r--r-- 1 root root 2.2M Sep 23 09:40 vmlinuz-2.6.32-5-686
-rw-r--r-- 1 root root 2.5M Dec 15 21:35 vmlinuz-2.6.34.13
此時,boot目錄下還缺少initrd.img-2.6.34.13文件,可以使用如下命令生成:
mkinitramfs -v -o initrd.img-2.6.34.13 2.6.34.13
注:debian squeese下是mkinitramfs命令,其它系統下可能是mkinitrd命令。
至此內核文件都生成好了,剩下最重要的一步就是配置grub了。如果你使用grub2,只需要運行如下命令就可以生產啓動項菜單。
update-grub
7、重啓機器,使用新內核。
參考資料:
《Linux內核設計與實現》,第二版
鳥哥的Linux私房菜:http://linux.vbird.org/linux_basic/0540kernel.php