今天编译安装了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
进入/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
首先按照模块,命令如下:
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
运行下面的命令会将内核安装到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
mkinitramfs -v -o initrd.img-2.6.34.13 2.6.34.13
至此内核文件都生成好了,剩下最重要的一步就是配置grub了。如果你使用grub2,只需要运行如下命令就可以生产启动项菜单。
update-grub
参考资料:
《Linux内核设计与实现》,第二版
鸟哥的Linux私房菜:http://linux.vbird.org/linux_basic/0540kernel.php