題記:最近,想要學習Linux驅(qū)動程序設計第三版(好書?。。?,需要一個2.6.10的內(nèi)核,于是就想給原有的Redhat 9.0升級一下,耗時一個早上,終于升級成功了,多虧了網(wǎng)上一些大俠的文章,在這我再將我參考的兩篇文章總結(jié)一下,希望能對大家有幫助。
步, 你將會在"make modules_install"這一步時出現(xiàn)問題.
rpm -i modutils-2.4.26-1.src.rpm
rpmbuild -bb /usr/src/redhat/SPECS/modutils.spec
rpm -Fi /usr/src/redhat/RPMS/i386/modutils-2.4.26-1.i386.rpm
5)解壓縮內(nèi)核源代碼.把下載的源代碼包放到目錄/usr/src下,然后
cd /usr/src
tar xvfj linux-2.6.10.tar.bz2
cd linux-2.6.10
二、配置工作
1、配置內(nèi)核選項。有點繁瑣,~~希望一次成功哦~~。
# cd linux-2.6.10 (進入到/usr/src/linux-2.6.10目錄下)
# make mrproper (該命令可確保源代碼目錄下沒有不正確的.o文件)
# make menuconfig (配置內(nèi)核各選項)
此時會出現(xiàn)一個圖形界面,列出了所有的內(nèi)核配置選項,有的選項下還有子選項,你可以用方向鍵來選擇,用Y鍵來確定。經(jīng)過我多次試驗,大多數(shù)選項默認就行,以下幾個選項必
須選擇(請認真核對下面每一個選項,否則編譯很有可能前功盡棄):
(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 buffer devices”;
Device Drivers --->USB support --->選上“USB Mass Storage support”(如果是在實環(huán)境中,想要更多USB支持,就全選吧。我的是在虛擬機中,用不著了)
Device Drivers --->;Network device support --->Ethernet (10 or 100Mbit) --->
<*> RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL) > 0
<*> RealTek RTL-8139 PCI Fast Ethernet Adapter support
(3)File system--->(以下9個選項是關(guān)于ext2和ext3文件系統(tǒng)配置,全部選上)
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文件系統(tǒng)配置很重要,也是必需的,如果對Ext3、Ext2文件的支持直接編譯進內(nèi)核,在你reboot時機器就會當?shù)?,出現(xiàn)如下錯誤信息:
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
(我的機器就是在重啟之后出現(xiàn)第三種錯誤,進不去系統(tǒng),郁悶死,只好重裝了~~~如果依照本文做完所有步驟,當你重啟Linux系統(tǒng)后,若不幸進不去2.6.10內(nèi)核,你會發(fā)現(xiàn)你的出
錯信息就是上面三種了~~~哈!)
(4)3)聲卡驅(qū)動 (這里我選擇的是AC97的聲卡)
也要選擇自己聲卡對應的驅(qū)動編譯進內(nèi)核,比較普遍的聲卡是i810_audio,以下就是這種聲卡的配置,以供參考 Device Drivers ---> Sound ---> <*> Sound card support
Advanced Linux Sound Architecture ---> <*> Advanced Linux Sound Architecture
<*> Sequencer support 4
< > Sequencer dummy client
<*> OSS Mixer API
<*> OSS PCM (digital audio) API
[*] OSS Sequencer API
<*> RTC Timer support MAGUM
PCI devices ---> <*> Intel i8x0/MX440, SiS 7012; Ali 5455; NForce Audio; AMD768/8111 PI
Open Sound System ---> < > Open Sound System (DEPRECATED)
(5)如果你在vmware下編譯內(nèi)核,硬盤用的是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
三、編譯工作
OK,繁雜的配置工作完成了,至此,編譯前的準備工作都做好了!
9、開始編譯啦……
在/usr/src/linux-2.6.10目錄下,執(zhí)行以下命令即可編譯。編譯需要一段時間,給自己倒杯茶耐心等候吧!
# make dep (建立編譯時所需的從屬文件。注意:如果內(nèi)核從未編譯過,此步可跳過)
# make clean (清除內(nèi)核編譯的目標文件。注意:如果內(nèi)核從未編譯過,此步可跳過)
# make bzImage (注意大小寫。這一步才是真正編譯內(nèi)核)
內(nèi)核編譯成功后,會在/usr/src/linux/arch/i386/boot目錄中生成一個新內(nèi)核的映像文件bzImage。如果用make zImage編譯,內(nèi)核很大的話,系統(tǒng)會提示你使用make
bzImage命令來編譯,所以我直接用make bzImage來編譯。
# make modules (編譯可加載模塊)
# make modules_install (安裝可加載模塊)
安裝成功后,系統(tǒng)會在/lib/modules目錄下生成一個2.6.10子目錄,里面存放著新內(nèi)核的所有可加載模塊。
# make install (安裝新內(nèi)核)
注意:
make install的時候可能會出現(xiàn)如下錯誤信息:
No module BusLogic found for kernel 2.4.20
mkinitrd failed
此問題一般只出現(xiàn)在SCSI硬盤+VMWARE+REDHAT架構(gòu)中,因為BusLogic被編譯進了內(nèi)核而不是一個module的形式(2.4內(nèi)核的Buslogic模塊即使靜態(tài)編譯進內(nèi)核也不行)。解決方式是
直接將BusLogic.o文件復制過去:
# cp /usr/src/linux-2.6.10/drivers/scsi/BusLogic.o /lib/modules/2.6.10/kernel/drivers/scsi
不過別忘記,復制過后再執(zhí)行一下make install。
四、啟動新內(nèi)核
10、將新內(nèi)核和System.map文件拷貝到/boot目錄下,依次執(zhí)行以下命令:
# cp /usr/src/linux-2.6.10/arch/i386/boot/bzImage /boot/vmlinuz-2.6.10
# cp /usr/src/linux-2.6.10/System.map /boot/System.map-2.6.10
# cd /boot (進入boot目錄)
# rm –rf System.map (刪除原來的連接)
# ln –s System.map-2.6.10 System.map (重新建立連接)
11、修改Grub啟動管理器
如果沒有錯誤的話, 下面開始修改grub配置文件(不要告訴我你用的lilo)
在/boot目錄下,執(zhí)行以下命令:
# new-kernel-pkg --mkinitrd --depmod --install 2.6.10 (這時候你的/boot下會生成一個initrd-2.4.18.img,并且你的grub.conf文件也作了相應更改)
# df (查看根目錄在那個分區(qū),下一步要用到。注意,這里根分區(qū)一般是你最大的那個分區(qū),也就是“/”,千萬不要搞錯哦。我的為 /dev/hda7)
# vi /boot/grub/grub.conf
進入grub.conf文件,找到如下信息:
default=1
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.10)
root (hd0,0)
kernel /boot/vmlinuz-2.6.10 ro root= LABEL=/
initrd /boot/initrd-2.6.10.img
做兩處修改:
(1) 將default=1改為default=0(不改的話也可以,只不過重啟之后會默認進入2.4內(nèi)核)
(2) 將kernel行的“LABEL=/”換成根目錄所在的分區(qū)(上一步查看的就是)
此步很重要,修改錯誤將可能導致進不去系統(tǒng),我把我修改后的grub.conf文件列出來,不明之處,可以對照修改:
default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
title Red Hat Linux (2.6.10)
root (hd0,0)
kernel /boot/vmlinuz-2.6.10 ro root=/dev/hda7
initrd /boot/initrd-2.6.10.img
title Red Hat Linux (2.4.20-8)
root (hd0,0)
kernel /boot/vmlinuz-2.4.20-8 ro root=LABEL=/
initrd /boot/initrd-2.4.20-8.img
12,OK,大功告成!趕快重啟,看看升級后的2.6內(nèi)核吧~~~~