/*******************************************************************
* RedHat5.8 编译内核驱动 合成initrd.img
* 说明:
* 需要编译RedHat5.8的内核驱动,找了一下资料,并操作一下,并编译
* 一下IO驱动,能够正常运作。
*
* 2017-3-1 深圳 南山平山村 曾剑锋
******************************************************************/
一、参考文档:
1. Redhat Enterprise Linux内核源码下载网址
http://ilinuxkernel.com/?p=22
2. Linux下RPM软件包的安装及卸载
http://os.51cto.com/art/201001/177866.htm
3. RedHat5.8更改yum源
http://blog.csdn.net/sz_bdqn/article/details/47015863
二、安装RedHat5.8 yum源:
1. 163 yum源:wget http://mirrors.163.com/.help/CentOS5-Base-163.repo;
2. 把$releasever替换成5;
三、下载对应版本的Linux Kernel:
1. 通过shell命令查看Linux Kernel版本:uname -a;
2. 下载对应版本的Linux Kernel rpm包:ftp://ftp.redhat.com/pub/redhat/linux/enterprise/5Server/en/os/SRPMS/;
3. 通过rmp命令安装:rpm -ivh <Linux Kernel rpm 包>;
4. 查看/usr/src/kernels/是否存在对应版本的内核源代码。
四、编译内核:
1. cd /usr/src
2. cd redhat/SPECS
3. rpmbuild –bp –-target=$(uname –m) kernel.spec # 最后的kernel.spec不一定是这个名字,以当前文件夹文件为准
4. cd /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686 # 以最后生成的文件夹为准
5. cp /boot/config-2.6.16-1.2798.fc6 .config # 以最后拥有的config文件为准
6. 修改/usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i686中的Makefile文件:
VERSION=2
PATCHLEVEL=6
SUBLEVEL=18
EXTRAVERSION= -1.2798.fc6 # 主要是要修改这里的,要跟当前内核的一样,可以通过uname -a查看
7. make menuconfig # 如果有需要单独配置的,可以通过这里去配置
8. make
9. make modules
10. make install
11. make modules_install
12. 修改/boot/grub/grub.conf文件来满足需求:
1. 8250.nr_uarts=10 # 串口数
2. vga=785 # 用于ALT+CTRL+Fn功能
13. 其中又遇到过无法识别磁盘的问题,需要重新更新initrd.img文件
五、重新合成initrd.img:
1. mkinitrd 帮助:
[root@main1 ~]# mkinitrd -h
usage: mkinitrd [--version] [--help] [-v] [-f] [--preload <module>]
[--force-ide-probe] [--force-scsi-probe | --omit-scsi-modules]
[--image-version] [--force-raid-probe | --omit-raid-modules]
[--with=<module>] [--force-lvm-probe | --omit-lvm-modules]
[--builtin=<module>] [--net-dev=<interface>] [--with-fips]
[--without-usb] [--without-multipath] [--without-dmraid]
[--fstab=<fstab>] [--nocompress] <initrd-image> <kernel-version>
(ex: mkinitrd /boot/initrd-2.2.5-15.img 2.2.5-15)
2. 查看内核版本:
[root@main1 modules]# pwd
/lib/modules
[root@main1 modules]# ls
2.6.18-308.el5
[root@main1 modules]#
3. 执行命令:
mkinitrd /boot/initrd-2.6.18-308.el5.img 2.6.18-308.el5