当前位置导航:炫浪网>>网络学院>>操作系统>>Linux教程

Linux内核升级&补丁安装手册

第一步:Linux2.4.18升级到2.4.31
首先说明下我的环境:
三台装有RedHat8(2.4.18-14)的主机。初步的任务就是升级内核到2.4.31然后再安装补丁Squashfs。
下载升级需要的源代码linux-2.4.31.tar.gz拷贝到/usr/src下
CODE:
#cd /usr/src/
#tar -zxvf linux-2.4.31.tar.gz

如果你安装了2.4.18-14的源代码的话,/usr/src下可能有个链接指向2.4.18的源码.在2.4中这个链接名叫linux2.4,首先将它删除,重新建立一个链接指向2.4.31的源码,取名为linux2.4或者linux都行,我选择后者。

CODE:
#ln -s linux-2.4.31 linux
#cd linux

由于是对内核编译是新手,所以如果直接去选择内核配置一定会是件很头疼的事情,当然对于老手来说可能是一种乐趣。 我还是参考一下系统现成的配置为好,然后再从中修改。

CODE:
cp /boot/config-2.4.18-14 ./.config
make menuconfig

在这里我们对原来的配置不做太多改动,只是根据自己的需要进行一些修改。(我这里的选择都是根据上面要求选择的)
首先,处理器选项,选择P4(Y不是M)

而且是SMP的(Y不是M)

还需要把loopback块设备编译进内核(因为squashfs要用到的),在“Block devices --->”中选择“ <*> Loopback device support ”(Y)。

对了,一定要记住为你的网卡选择驱动,以我的机子为例,在“Network device support ---> ”中选择“Ethernet (1000 Mbit) ---> ”子菜单进入后,选择“ <*> Intel(R) PRO/1000 Gigabit Ethernet support ”这一项(Y)

好了,下来就可以退出了,一路exit最后可以看到一个启动项已经生成了选择保存配置文件的修改。
建立依赖关系


CODE:
#make dep
#make clean
#make bzImage[大概花费了5分钟时间]

完成时提示

CODE:
Root device is (22, 2)
Boot sector 512 bytes.
Setup is 4784 bytes.
System is 1010 kB
warning: kernel is too big for standalone boot from floppy
make[1]: Leaving directory `/usr/src/linux-2.4.31/arch/i386/boot'

我想这可能是没有对内核进行裁剪的结果吧,引起内核太大,不过不必理会这个警告,我又不用软盘去启动^_^
接着编译模块

CODE:
#make modules

安装模块

CODE:
#make modules_install

报错

CODE:
depmod: *** Unresolved symbols in /lib/modules/2.4.31/kernel/crypto/autoload.o
depmod: crypto_alg_lookup
depmod: *** Unresolved symbols in /lib/modules/2.4.31/kernel/crypto/proc.o
depmod: crypto_alg_sem
depmod: crypto_alg_list

将这些忽略掉,因为这些不会影响到内核的升级。如果你要去除这些错误,就从make menuconfig再来一次吧,重新进行内核配置。
下来,更新sytem.map文件和vmlinuz文件

CODE:
[root@localhost linux]# cp System.map /boot/System.map-2.4.31
[root@localhost linux]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.31

重新建立文件链接

CODE:
[root@localhost linux]# cd /boot/
[root@localhost boot]# rm -fr System.map
[root@localhost boot]# rm -fr vmlinuz
[root@localhost boot]# ln -s System.map-2.4.31 System.map
[root@localhost boot]# ln -s vmlinuz-2.4.31 vmlinuz

看一下链接是否正确:

CODE:
[root@localhost boot]# ll

我们看到输出中包含两行:

CODE:
System.map -> System.map-2.4.31
vmlinuz -> vmlinuz-2.4.31

接着安装内核:

CODE:
[root@localhost boot]# cd /usr/src/linux
[root@localhost linux]# new-kernel-pkg --install --depmod --mkinitrd 2.4.31

由于添加了install选项和depmod选项,所以会出现跟make modules_install时出现一样的错误:

CODE:
depmod: *** Unresolved symbols in /lib/modules/2.4.31/kernel/crypto/autoload.o
depmod: crypto_alg_lookup
depmod: *** Unresolved symbols in /lib/modules/2.4.31/kernel/crypto/proc.o
depmod: crypto_alg_sem
depmod: crypto_alg_list

依旧忽略。
最后去/boot下检查下,并修改一下启动时的分区设置。

CODE:
[root@localhost linux]# cd /boot/
[root@localhost boot]# vi grub/grub.conf

可以看到一个启动项已经生成了


修改
root = LABEL=/

root = /dev/hdc2
也就是根目录/所在的分区

要获知根目录所在分区,通过命令
df –h 查看

CODE:
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/hdc2 19G 2.4G 15G 13% /
/dev/hdc1 99M 13M 81M 14% /boot
/dev/hdc5 49G 33M 46G 1% /data
none 247M 0 247M 0% /dev/shm

我们得知是/dev/hdc2.
对了,如果要默认启动新的内核或者你是远程操作的话,需要将新的内核设置为默认启动项,将
/boot/grub/grub.conf
中的

CODE:
default=1

改为

CODE:
default=0

确认没有其它问题时,我们就可以reboot试试了。
机器启动正常後,进行查看,看是否符合我们的要求:

CODE:
#uname -a
Linux localhost.localdomain 2.4.31 #1 SMP Tue Jul 10 09:26:01 CST 2007 i686 i686 i386 GNU/Linux

看到内核版本信息已经改变了,而且是SMP的。
查看LOOPBACK是否已经被编译进内核,我们知道loopback是一个块设备,所以去/proc下找找看。

CODE:
[root@localhost root]# cat /proc/devices
Character devices:
1 mem
2 pty
...................
Block devices:
1 ramdisk
7 loop
9 md
22 ide1

找到了loop了, 继续下一步工作。

第二步:给2.4.31内核打补丁,重新编译内核加载新特性

下载squashfs3.1-r2.tar.gz补丁文件,这个版本是针对与2.4内核的,如果你是2.6内核系统的话,需要下载对应2.6版本的。
先打补丁。将squashfs3.1-r2.tar.gz拷贝到/usr/src下


CODE:
[root@localhost src]# tar -zxvf squashfs3.1-r2.tar.gz
[root@localhost src]# cd linux

备份我们升级内核用到的配置文件

CODE:
[root@localhost linux]# cp .config ../backup.config

进行上次编译后的清理

CODE:
[root@localhost linux]# make mrproper

为了将2.4.31的内核跟打过补丁的内核区分开来或者不至引起错误,我们在makefile中添加自定义版本信息来进行区分。
[root@localhost linux]# vi Makefile
修改

CODE:
EXTRAVERSION =

CODE:
EXTRAVERSION = -cucme

保存。
下来需要给内核打补丁

CODE:
[root@localhostlinux]#patch -p1 < ../squashfs3.1-r2/linux-2.4.31/squashfs3.1-patch
patching file fs/Config.in
patching file fs/Makefile
patching file fs/squashfs/inode.c
patching file fs/squashfs/Makefile
patching file fs/squashfs/squashfs2_0.c
patching file fs/squashfs/squashfs.h
patching file include/linux/fs.h
patching file include/linux/squashfs_fs.h
patching file include/linux/squashfs_fs_i.h
patching file include/linux/squashfs_fs_sb.h
patching file init/do_mounts.c
patching file lib/Config.in

然后把配置文件拷贝回来,在make menuconfig中再次进行修改。(这次的工作主要是添加squashfs文件系统)

CODE:
[root@localhost linux]# cp ../backup.config ./.config

由于我们这次编译内核的意图明确,所以可以直奔主题,因为其它的选项都已经选择好了。

CODE:
[root@localhost linux]#make menuconfig

我们直接寻找进入
File systems --->项
可以看到多了一项新的特性,那就是squashfs文件系统
在上面用Y进行选择,这个时候又出现了一个选项


不要轻易决定要不要选,看看squashfs的文档

CODE:
[root@localhost squashfs3.1-r2]# less INSTALL
There are a set of options which are intended for use by embedded systems with
low memory. At the "Additional options for memory-constrained systems" prompt,
please say NO unless you're using an embedded system! Saying Y here allows you
to specify cache sizes and how Squashfs allocates memory.

所以对于这个特性我们选择N。
好了config已经结束,退出。

CODE:
#make dep
[root@localhost linux]# make clean
[root@localhost linux]# make bzImage

接着

CODE:
[root@localhost linux]# make modules
[root@localhost linux]# make modules_install

提示
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/crypto/autoload.o
depmod: crypto_alg_lookup
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/crypto/proc.o
depmod: crypto_alg_sem
depmod: crypto_alg_list
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/drivers/sound/soundcore.o
depmod: open
depmod: read
depmod: lseek
depmod: close
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/drivers/sound/wavefront.o
depmod: open
depmod: read
depmod: close

忽略。

CODE:
[root@localhost linux]# cp System.map /boot/System.map-2.4.31-cucme
[root@localhost linux]# cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.31-cucme
[root@localhost linux]# cd /boot/
[root@localhost boot]# rm -fr System.map
[root@localhost boot]# rm -fr vmlinuz
[root@localhost boot]# ln -s System.map-2.4.31-cucme System.map
[root@localhost boot]# ln -s vmlinuz-2.4.31-cucme vmlinuz

安装内核

CODE:
[root@localhost boot]# cd /usr/src/linux
[root@localhost linux]# new-kernel-pkg --install --depmod --mkinitrd 2.4.31-cucme
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/crypto/autoload.o
depmod: crypto_alg_lookup
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/crypto/proc.o
depmod: crypto_alg_sem
depmod: crypto_alg_list
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/drivers/sound/soundcore.o
depmod: open
depmod: read
depmod: lseek
depmod: close
depmod: *** Unresolved symbols in /lib/modules/2.4.31-cucme/kernel/drivers/sound/wavefront.o
depmod: open
depmod: read
depmod: close

没有必要去重新make menuconfig设法去掉这些错误。
修改grub.conf文件

CODE:
[root@localhost linux]# cd /boot/
[root@localhost boot]# vi grub/grub.conf

可以看到


跟升级时一样修改[根目录对应的分区和默认的启动项].
检查无误重启reboot
启动OK,进行检查
内核版本

CODE:
[root@localhost root]# uname -a
Linux localhost.localdomain 2.4.31-cucme #1 SMP Tue Jul 10 10:49:29 CST 2007 i686 i686 i386 GNU/Linux


文件系统(看squashfs是否编译进内核)

CODE:
[root@localhost root]# cat /proc/filesystems
nodev rootfs
nodev bdev
nodev proc
nodev sockfs
nodev tmpfs
nodev shm
nodev pipefs
ext2
nodev ramfs
iso9660
nodev devpts
squashfs
ext3
nodev usbdevfs
nodev usbfs
nodev autofs


我们看到了squashfs文件系统。
测试squashfs

CODE:
[root@localhost root]# cd /usr/src/squashfs3.1-r2/squashfs-tools/
[root@localhost squashfs-tools]# make
[root@localhost squashfs-tools]# cp mksquashfs unsquashfs /usr/sbin/
[root@localhost root]# mksquashfs /home/307.rm /mnt/test.img
Parallel mksquashfs: Using 1 processor
Creating little endian 3.0 filesystem on /mnt/test.img, block size 65536.

Little endian filesystem, data block size 65536, compressed data, compressed metadata, compressed fragments
Filesystem size 1583.37 Kbytes (1.55 Mbytes)
97.93% of uncompressed filesystem size (1616.90 Kbytes)
Inode table size 132 bytes (0.13 Kbytes)
79.52% of uncompressed inode table size (166 bytes)
Directory table size 22 bytes (0.02 Kbytes)
100.00% of uncompressed directory table size (22 bytes)
Number of duplicate files found 0
Number of inodes 2
Number of files 1
Number of fragments 0
Number of symbolic links 0
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 1
Number of uids 1
root (0)
Number of gids 0


进入mnt下查看下。

CODE:
[root@localhost root]# ll -a /mnt/
total 1596
drwxr-xr-x 2 root root 4096 Jul 10 11:30 .
drwxr-xr-x 21 root root 4096 Jul 10 11:23 ..
-rwx------ 1 root root 1622016 Jul 10 11:30 test.img

我们看到了生成的test.img镜像文件。
关于内核的升级和补丁过程我这两周来就总结这点经验,对于一个老手来说或许是很简单的一件事情,但是对于初学者应该会提供一些帮助吧,当然这里的补丁不一定是squashfs了,也可以是iptables等等。


上一页  [1] [2] [3] [4] [5] [6] 

相关内容
赞助商链接