一
1、Linux的2.6.20版本内核包(linux-2.6.20.tar.gz):作用就不多说了,自然是内核的源码包;
2、Modutils 3.2 工具包(module-init-tools-3.2.tar.gz):原2.4.x下的工具包不适用于2.6.x,必须升级;
3、Mkinitrd 4.1.18-2 工具包(mkinitrd-4.1.18-2.i386.rpm):在make install时需要使用该工具;
4、Device Mapper 开发包(device-mapper-1.00.19-2.i386.rpm):Mkinitrd工具包依赖该包;
5、LVM 开发包(lvm2-2.00.25-1.01.i386.rpm):Device Mapper依赖该包;
6、Binutils 开发包(binutils-2.17.tar.gz):如升级安装于虚拟机上的Red Hat Linux,则必需该包。(就是没有安装它我失败了很多次)
将下载好的内核源码包和4个升级工具都拷贝到/usr/src文件夹下。
二
1:
# cd /usr/src (进入到/usr/src目录下,如果已经在/usr/src目录下,可不执行该命令)
# rm -rf linux (删除linux文件夹。值得一提的是,如果内核先前从未编译过,则没有这个文件夹,此命令行可略过)
# tar jvxf linux-2.6.18.tar.bz2 (解压新内核)
# ln -s linux-2.6.18 linux (重新生成linux文件夹)
2:安装module-init-tools工具
在/usr/src目录下,依次执行下列命令:
# tar jvxf module-init-tools-3.2.tar.bz2 (解压module-init-tools)
# cd module-init-tools-3.2 (由/usr/src目录进入module-init-tools目录下)
#./configure --prefix=/
# make moveold
# make all install
#./generate-modprobe.conf /etc/modprobe.conf
3:下面安装3个工具包,
将当前目录切换到
mkinitrd-4.1.18-2.i386.rpm、device-mapper-1.00.19-2.i386.rpm和lvm2-2.00.25-1.01.i386.rpm的下载目录(三个文件最好在同一目录)下,依次执行如下命令:
rpm -ivh --nodeps --force lvm2-2.00.25-1.01.i386.rpm
rpm -ivh --nodeps --force device-mapper-1.00.19-2.i386.rpm
rpm -ivh --nodeps --force mkinitrd-4.1.18-2.i386.rpm
4:
在虚拟机上运行Red Hat Linux 9.0或安装内核到最后出现bzImage编译错误的情况,则必须安装Binutils 开发包,虚拟机上该类型的错误消息一般为:
OBJCOPY arch/i386/boot/compressed/vmlinux.bin
BFD: Warning: Writing section `.bss' to huge (ie negative) file offset 0xc025d000.
objcopy: arch/i386/boot/compressed/vmlinux.bin: File truncated
make[2]: *** [arch/i386/boot/compressed/vmlinux.bin] Error 1
make[1]: *** [arch/i386/boot/compressed/vmlinux] Error 2
make: *** [bzImage] Error 2
将当前目录切换到binutils-2.17.tar.gz下载目录,依次执行如下命令:
tar zxf binutils-2.17.tar.gz
cd binutils-2.17
./configure
make
make install
5:配置内核选项
cd linux-2.6.20
make mrproper
make menuconfig
此时会出现一个图形界面,列出了所有的内核配置选项,其中有几项是必需的,用“Y”键选中:
(1)“Loadable Module support”中,选“Module unloading”和 “Automatic kernel module loading”;
(2) “Device Drivers”→“Block Devices”中,选“Loopback device support”;
“Device Drivers”→“Multi-device support(RAID and LVM)”中,选“device mapper support”;
“Device Drivers”→“Graphics support”中,选“Support for frame buffer devices”;
“Device Drivers”→“USB support”中,若不在虚拟机环境中,应尽量全选以支持USB;
“Device Drivers”→“Network device support ”→“Ethernet (10 or 100Mbit)”中,选根据网卡不同选你的网卡类型的;
(3)由于Red Hat 9.0使用ext3作为文件系统,故“File System”中的所有关于ext2、ext3的选项必选;
对于要求系统提供比较多样的网络协议的开发人员,还应在“Network Support”中进行相应设置。
File system--->(以下9个选项是关于ext2和ext3文件系统配置,全部选上)
Second extended fs support
Ext2 extended attributes
Ext2 POSIX Access Control Lists
Ext2 Security Labels
Ext3 journalling file system support
Ext3 extended attributes
Ext3 POSIX Access Control Lists
Ext3 Security Labels
JBB (ext3) debugging support
File system--->DOS/FAT/NT Filesystems --->选上“NTFS file system support”;
注意:
ext2和ext3文件系统配置很重要,也是必需的,如果对Ext3、Ext2文件的支持直接编译进内核,在你reboot时机器就会当掉,出现如下错误信息:
kernel panic : no init found ,try passing init = option to kernel.....
或者是:
VFS:Cannot open root device "hdxy" or unknow-block(0,0)
Please append a correct "root=" boot option
kernel panic:VFS:Unable to mount root fs on unknown-block(0,0)
或者是:
mount: error 19 mounting ext3
pivotroot: pivot_root(/sysroot,/sysroot/initrd) failed: 2
umount /initrd/proc fail: 2
Freeing unused kernel memory: 244k freed
Kernel panic - not syncing: No init found. Try passing init = option to kernel
(我的机器就是在重启之后出现第三种错误,进不去系统,郁闷死,只好重装了~~~如果依照本文做完所有步骤,当你重启Linux系统后,若不幸进不去2.6.18内核,你会发现你的出错信息就是上面三种了~~~哈!)
(4)如果在VMware虚拟机下编译内核,SCSI硬盘,则以下三个选项必选:
“Device Drivers”→“SCSI device support”;
“Device Drivers”→“SCSI device support”→“SCSI disk support”;
“Device Drivers”→“SCSI device support”→“SCSI low-level drivers”→“BusLogic SCSI support”;
6:编译内核
{# make dep (建立编译时所需的从属文件。注意:如果内核从未编译过,此步可跳过)
# make clean (清除内核编译的目标文件。注意:如果内核从未编译过,此步可跳过)
聂耽的文档有这个
}
make
{# make bzImage (注意大小写。这一步才是真正编译内核)
内核编译成功后,会在/usr/src/linux/arch/i386/boot目录中生成一个新内核的映像文件bzImage。如果用 make zImage编译,内核很大的话,系统会提示你使用make bzImage命令来编译,所以我直接用make bzImage来编译。
聂耽有这项
}
make modules
make modules_install
make install
如果是VMware虚拟机+SCSI硬盘的用户,在make install之前,还要执行以下命令:
cp /usr/src/linux-2.6.20/drivers/scsi/BusLogic.o /lib/modules/2.6.20/kernel/drivers/scsi
不过别忘记,复制过后再执行一下make install。这一步若卡住了,下面的都无法进行,如果看本文档还是没有解决问题,就来我的网上留言本求助吧,进http://www.piaoyang.org ,点“留言本”即可,我会及时看到你的求助信息的。
修改/etc/modules.conf文件,将后面有
mpt×××
mpt×××
的行去掉或注释掉
四、启动新内核
内核编译到此就完全结束了,若想要成功启动内核,还要做一些后续的工作。依次执行如下命令:
cp /usr/src/linux-2.6.20/arch/i386/boot/bzImage /boot/vmlinuz-2.6.20(使用VMware的用户必需)
cp /usr/src/linux-2.6.20/System.map /boot/System.map-2.6.20
cd /boot
rm -rf System.map(删除原有的内核启动连接)
ln -s System.map-2.6.20 System.map(设置新的内核启动连接)
若你的Linux为GRUB启动,则还要修改相应的启动文件:
cd /boot
new-kernel-pkg --mkinitrd --depmod --install 2.6.20
df(该命令查看根分区,即标识为“/”的分区,看好后要记住它的名字,假设为/dev/sda2)
gedit /boot/grub/grub.conf
在弹出的编辑窗口中,将“default=1”改为“default=0”,并将“kernel”行的“LABEL=/”改为上一步所查看的分区,按我们上一步的假设,改完以后的“kernel”行应该是下面的样子:
kernel /vmlinuz-2.6.20 ro root=/dev/sda2
由于本人使用虚拟机安装,所以上面的内容可能会与实环境有些出入,但蓝色粗体部分一定是这样的。
如果想在新内核下支持Hotplug、USB设备或体验sysfs文件系统等,还需要安装相应的工具包并改变配置文件。关于这些问题,这里不再叙述,以后开辟新帖供大家专门研究讨论。
好了,整个内核升级大功告成!重新启动之后,在操作系统选择栏中会看到如下两项:
Red Hat Linux(2.6.20)
Red Hat Linux(2.4.20-8)
选择第一项,就可以真正使用2.6.20的Linux系统了
补充两点:
1、安装module-init-tools工具时,命令"make moveold"将把系统原来的modutils工具程序改名为"*.old"(比如,lsmod.old等等). NOTE! 这是非常重要的一步, 千万不要省略. 这将使得你可以继续使用原有的linux-2.4.x系统, 因为在2.4.x系统下, 新的module-init- tools工具包实际上是倚赖原来"*.old"程序来加载内核模块. 如果忘记了这一步也不要紧张, 可以先下载并安装原来的modutils程序包, 然后按照上面的步骤重来一遍就可以了.
2、在安装3个升级工具时,如果加了--nodeps参数仍未能安装成功,请尝试再加入参数--force
:= -O binary -R .note -R .comment -S
drzh 于 2009-05-02 23:12:38发表:
从头学起,争取超越!