在debian下编译、升级linux内核

来源:互联网 发布:投资公司网络销售咋样 编辑:程序博客网 时间:2024/05/15 00:30

本文的参考网站:

http://kernel-handbook.alioth.debian.org/

 

在分析linux内核源码的过程中,要是能够修改内核源码并运行修改后的内核,我想肯定是令人高兴的事,哪怕第一次修改仅仅是在启动时打印一行"Hello, Wang Jiankun!",肯定也是令我高兴的。为了能成功编译修改后的内核,今天先编译一遍内核。

为了有一个完整的记录,今天的起点是一台裸机。

1、在裸机上安装一个最小的debian系统

为了能够尽可能清晰的显示编译一个内核所需要的组件,在安装系统时,仅仅安装最小系统,然后需要什么,就使用apt-get安装什么。

使用网络安装,在安装过程中出现Software selection界面时不要选择任何选项,这样安装的系统将是最小的系统。

为了使用ssh远程登录,最小系统安装完成后,要安装ssh服务器并且要设置静态ip地址(debian安装过程中是通过dhcp获取的ip地址)。

2、安装ssh服务器

apt-get install ssh

3、设置静态ip地址

修改文件/etc/network/interfaces,其中蓝色部分是增加的,红色部分是屏蔽掉的,黑色部分是没有变化的。

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0

# Wang Jiankun commented the following line
#iface eth0 inet dhcp

# Wang Jiankun added the the following lines
iface eth0 inet static
address 192.168.1.251
netmask 255.255.255.0
broadcast 192.168.1.255
network 192.168.1.0
gateway 192.168.1.1

重启系统后,修改将生效。

4、通过wget下载linux内核源码

administrator@wangjk:~/kernel$ wget http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.19.tar.bz2

5、解压文件linux-2.6.19.tar.bz2
administrator@wangjk:~/kernel$ tar jxf linux-2.6.19.tar.bz2
tar: bzip2: Cannot exec: No such file or directory
tar: Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error exit delayed from previous errors
administrator@wangjk:~/kernel$

看来是没有bzip2这个包,那就安装一个:

apt-get install bzip2

6、安装debian的kernel-package软件包

在安装kernel-package软件包时,最好使用命令:apt-get build-dep kernel-package,而不要使用命令:

apt-get install kernel-package,后者安装的软件包是前者的子集,使用后者安装kernel-package软件包后,执行make menuconfig命令会出现头文件找不到的错误,如下所示:

administrator@wangjk:~/kernel/linux-2.6.19$ make menuconfig
  HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c:105:23: error: sys/types.h: No such file or directory
scripts/basic/fixdep.c:106:22: error: sys/stat.h: No such file or directory
scripts/basic/fixdep.c:107:22: error: sys/mman.h: No such file or directory
scripts/basic/fixdep.c:108:20: error: unistd.h: No such file or directory
scripts/basic/fixdep.c:109:19: error: fcntl.h: No such file or directory
scripts/basic/fixdep.c:110:20: error: string.h: No such file or directory
scripts/basic/fixdep.c:111:20: error: stdlib.h: No such file or directory
scripts/basic/fixdep.c:112:19: error: stdio.h: No such file or directory

主要是因为libc6-dev软件包没有安装。所以即使使用了apt-get install kernel-package还得使用apt-get build-dep kernel-package,不如一次使用apt-get build-dep kernel-package完成方便。

7、安装libncurses5-dev软件包来支持make menuconfig

通过apt-get build-dep kernel-package安装完成kernel-package后,执行make menuconfig仍然报错,如下所示:

administrator@wangjk:~/kernel/linux-2.6.19$ make menuconfig
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:32:20: error: curses.h: No such file or directory
In file included from scripts/kconfig/lxdialog/checklist.c:24:
scripts/kconfig/lxdialog/dialog.h:97: error: expected specifier-qualifier-list before 'chtype'
scripts/kconfig/lxdialog/dialog.h:187: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:193: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:195: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:196: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:197: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:198: error: expected ')' before '*' token
scripts/kconfig/lxdialog/dialog.h:200: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:31: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:59: error: expected ')' before '*' token
scripts/kconfig/lxdialog/checklist.c:95: error: expected ')' before '*' token
[省略其后部分]

原来是最小系统不支持图形的原因,安装libncurses5-dev后即可。

8、将系统的config文件拷贝到内核目录下

cp /boot/config-2.6.18-6-686 ./.config

9、执行make menuconfig

虽然是将原来系统的config文件拷贝过来的,但是如果所以的配置都采用默认的配置仍然会有问题,在我的系统上在加载文件系统时会死掉,所以还是要做必要的配置,主要是将scsi和sata部分编译进内核而不要编译成模块,如下所示:

Device Drivers  --->           
    Serial ATA (prod) and Parallel ATA (experimental) drivers  --->

    SCSI device support  --->    

将蓝色两部分级联的选项全部编译进内核(其实没有必要全部,但为了简单起见,暂时这样做)。

10、安装fakeroot软件包

11、编译内核

fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image

12、安装内核

wangjk:/home/administrator/kernel# dpkg -i linux-image-2.6.19_custom.1.0_i386.deb 

Selecting previously deselected package linux-image-2.6.19.
(Reading database ... 17679 files and directories currently installed.)
Unpacking linux-image-2.6.19 (from linux-image-2.6.19_custom.1.0_i386.deb) ...
Done.
Setting up linux-image-2.6.19 (custom.1.0) ...
Running depmod.
Finding valid ramdisk creators.
Using mkinitramfs-kpkg to build the ramdisk.
Running postinst hook script /sbin/update-grub.
You shouldn't call /sbin/update-grub. Please call /usr/sbin/update-grub instead!

Searching for GRUB installation directory ... found: /boot/grub
Searching for default file ... found: /boot/grub/default
Testing for an existing GRUB menu.lst file ... found: /boot/grub/menu.lst
Searching for splash image ... none found, skipping ...
Found kernel: /boot/vmlinuz-2.6.19
Found kernel: /boot/vmlinuz-2.6.18-6-686
Updating /boot/grub/menu.lst ... done
13、重启系统引导新内核后查看版本号

administrator@wangjk:~$ cat /proc/version
Linux version 2.6.19 (root@wangjk) (gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)) #1 SMP Thu May 7 21:52:10 CST 2009
administrator@wangjk:~$ 

可以看出已经是我编译的内核了。

       


 

原创粉丝点击