[Linux内核设计与实现]Linux内核编译

今天编译安装了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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值