Chinaunix首页 | 论坛 | 博客
  • 博客访问: 352358
  • 博文数量: 87
  • 博客积分: 1322
  • 博客等级: 少尉
  • 技术积分: 915
  • 用 户 组: 普通用户
  • 注册时间: 2011-06-25 18:04
文章分类

全部博文(87)

文章存档

2013年(10)

2012年(9)

2011年(68)

分类: LINUX

2011-11-29 12:57:02

Redhat9,其内核版本为2.4.20-8 ,只能升级到2.6.18或2.4.26,不能直接升到2.6.3x,可能因为变动太大吧。会出错。

VM安装时个人认为选IDE硬盘比较好…


准备工作

1、 查看Linux内核版本
# uname –a

2、 下载2.6内核源码 和 4个内核升级工具:

3、 module-init-tools-3.2.tar.bz2           //注意,最好用这个版本,用再高一点的,如:3.10,则在make moveold是会出错。

mkinitrd-4.1.18-2.i386.rpm

lvm2-2.00.25-1.01.i386.rpm

device-mapper-1.00.19-2.i386.rpm

将下载好的内核源码包和4个升级工具都拷贝到/usr/src文件夹下。

# 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文件夹)

安装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

安装另外三个升级工具
回到/usr/src目录下,依次执行下列3个命令来安装另外三个升级工具:
# rpm -ivh --nodeps mkinitrd-4.1.18-2.i386.rpm (注意,这里一定要加入--nodeps参数,下同)
# rpm -ivh --nodeps lvm2-2.00.25-1.01.i386.rpm
# rpm -ivh --nodeps device-mapper-1.00.19-2.i386.rpm

配置内核选项
# cd linux-2.6.18 (进入到/usr/src/linux-2.6.18目录下)
# make mrproper (该命令可确保源代码目录下没有不正确的.o文件)
# make menuconfig (配置内核各选项)

9、 以下几个一定要选上:

(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 Mass Storage support”(如果是在实环境中,想要更多USB支持,就全选吧。我的是在虚拟机中,用不着了)

Device Drivers --->;Network device support --->Ethernet (10 or 100Mbit) ---><*> AMD PCnet32 PCI support

(3)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文件系统配置很重要,也是必需的,如果没有将这些文件直接编译(*)进内核,在你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

(4)如果你在vmware下编译内核,硬盘用的是scsi的,以下三个选项必选:

Device Drivers ---><*>SCSI device support (此项不选的话,下面两项就选择不上)

Device Drivers ---><*>SCSI device support ---><*>SCSI disk support

Device Drivers---><8>SCSI device support--->SCSI low-level drivers--->; BusLogic SCSI support

Device Drivers ---> Fusion MPT device support --->
Fusion MPT (base + ScsiHost) drivers
Fusion MPT misc device (ioctl) driver(这个不确定)

3.1 Device Drivers -> Block devices -> 
<*> RAM disk support 
(16) Default number xxxxx 
(16384) Default RAM disk size 一定要改为16384以上 
[*] Initial RAM disk (initrd) support

3.3 网卡驱动:请务必把自己网卡对应的驱动编译进内核,常用的网卡是realtek 8139,以下就是这种网卡的配置, 
Device Drivers---> Networking support---> Ethernet (10 or 100Mbit) ---> 
RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL) 
RealTek RTL-8139 PCI Fast Ethernet Adapter support 
AMD PCnet32 PCI support(虚拟机)

3.4 USB支持
Device Drivers ---> USB support ---><*> USB Mass Storage support
Device Drivers -> USB support ->USB HID Boot Protocol drivers -> 
[ M ] USB HIDBP Keyboard support 
[ M ] USB HIDBP Mouse support 
必须选,否则不支持USB鼠标和USB键盘

3.5 CDROM支持
Device Drivers ---> 
<*> ATA/ATAPI/MFM/RLL support 
<*> Intel PIIXn chipsets support
如果这一项不选则升级内核后无法挂载CDROM。 (根据你的CDROM类型自行选择)

3.6 声卡驱动Sound card support ,也要选择自己声卡对应的驱动编译进内核,比较普遍的声卡是AC97,以下就是这种声卡的配置。 
关键是把Sound card support 以及 Advanced Linux Sound Architecture 里面的选项选成模块(M) 
Device Drivers ---> Sound ---> 
<*> Sound card support 
Advanced Linux Sound Architecture ---> 
<*> Advanced Linux Sound Architecture 
<*> Sequencer support 
< > Sequencer dummy client 
<*> OSS Mixer API 
<*> OSS PCM (digital audio) API[*] OSS Sequencer API 
<*> RTC Timer support 
PCI devices ---> 
<*> Intel/SiS/nVidia/AMD/ALi AC97 Controller
<*> (Creative) Ensoniq AudioPCI 1371/1373 (虚拟机)
Open Sound System ---> 
< > Open Sound System (DEPRECATED) 
可以选上新支持的模块Advanced Linux Sound Architecture ,至于旧的Open Sound System 模块就不要再选了。

3.7 文件系统 
请务必要选中ext3文件系统, 
File systems---> 
[*] Ext3 journalling file system support 
[*] Ext3 Security Labels 
[*] JBD (ext3) debugging support

File Systems --->Psedo File Systems ---> 
[ * ] devfs support (OBSOLETE) 
[ * ] Automatically mount at boot

其实像我经常要和windows主机间共享文件,所以在file system里也选上ntfs,vfat, samba systemfile,来使内核支持这些文件类型。如果没选,在新内核下也可以再补充编译,详见文章末尾。

开始编译

在/usr/src/linux-2.6.18目录下,

# make dep (建立编译时所需的从属文件。注意:如果内核从未编译过,此步可跳过)

# make clean (清除内核编译的目标文件。注意:如果内核从未编译过,此步可跳过)

# make bzImage (注意大小写。这一步才是真正编译内核)

内核编译成功后,会在/usr/src/linux/arch/i386/boot目录中生成一个新内核的映像文件bzImage。如果用make zImage编译,内核很大的话,系统会提示你使用make   bzImage命令来编译,所以我直接用make bzImage来编译。

# make modules (编译可加载模块)

# make modules_install (安装可加载模块)

安装成功后,系统会在/lib/modules目录下生成一个2.6.18子目录,里面存放着新内核的所有可加载模块。

# make install (安装新内核)

注意:

        make install的时候可能会出现如下错误信息:

        No module BusLogic found for kernel 2.4.12

        mkinitrd failed

此问题一般只出现在SCSI硬盘+VMWARE+REDHAT架构中,因为BusLogic被编译进了内核而不是一个module的形式(2.4内核的Buslogic模块即使静态编译进内核也不行)。解决方式是直接将BusLogic.o文件复制过去:

# cp /usr/src/linux-2.6.18/drivers/scsi/BusLogic.o /lib/modules/2.6.18/kernel/drivers/scsi

不过别忘记,复制过后再执行一下make install。

11、启动新内核

将新内核和System.map文件拷贝到/boot目录下,依次执行以下命令:    

# cp /usr/src/linux-2.6.18/arch/i386/boot/bzImage   /boot/vmlinuz-2.6.18    

# cp /usr/src/linux-2.6.18/System.map   /boot/System.map-2.6.18    

# cd /boot (进入boot目录)

# rm –rf System.map (删除原来的连接)    

# ln –s System.map-2.6.18 System.map   (重新建立连接)

12、 修改Grub启动管理器

如果没有错误的话, 下面开始修改grub配置文件(不要告诉我你用的lilo)

在/boot目录下,执行以下命令:

# new-kernel-pkg --mkinitrd --depmod --install 2.6.18 (这时候你的/boot下会生成一个initrd-2.4.18.img,并且你的grub.conf文件也作了相应更改)

# df (查看根目录在那个分区,下一步要用到。注意,这里根分区不时boot的那个50M的分区,而一般是你最大的那个分区,也就是“/”,千万不要搞错哦。我的为 /dev/hda2)

# vi /grub/grub.conf

进入grub.conf文件,找到如下信息:

default=1

timeout=10

splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.6.1

        root (hd0,0)

        kernel /vmlinuz-2.6.18 ro root= LABEL=/

        initrd /initrd-2.6.18.img

做两处修改:

(1) 将default=1改为default=0(不改的话也可以,只不过重启之后会默认进入2.4内核)

(2) 将kernel行的“LABEL=/”换成根目录所在的分区(上一步查看的就是)

此步很重要,修改错误将可能导致进不去系统,我把我修改后的grub.conf文件列出来,不明之处,可以对照修改:

default=0

timeout=10

splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.6.1

        root (hd0,0)

        kernel /vmlinuz-2.6.18 ro root=/dev/hda2

        initrd /initrd-2.6.18.img

title Red Hat Linux (2.4.20-

        root (hd0,0)

        kernel /vmlinuz-2.4.20-8 ro root=LABEL=/

        initrd /initrd-2.4.20-8.img

搞定了,OK!

**********************************************
使用新内核可能出现的问题及对策
**********************************************

1. RedHat用户rpm命令不能使用,解决办法:请把变量在全局配置文件中声明。
  这是RPM的一个Bug,特别是对于RH9的用户,请打开/etc/profile文件,命令如下: 
  #vi /etc/profile (在文件的末尾加上几句如下) 
  if [`uname -r`="2.6.0" ];then 
  export LD_ASSUME_KERNEL=2.2.5 
  fi 
  也就是给系统加上一个全局的环境变量,也可直接键入#export LD_ASSUME_KERNEL=2.2.5。 
  

2. 新内核根本起不来,解决方法:重新配置内核(学问挺大),也许还根引导记录有关(很少了); 
  

3. 新内核模块无法加载,会导致很多问题,比如了防火墙没法工作了,mount不上光盘和vfat及ntfs文件系统,其解决方法:升级module-init-tools软件包,
   RedHat的用户可能还要修改/etc/rc.d/rc.sysinit文件;

阅读(1618) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~