一、i386的linux作業系統啟動過程
bios上電自檢——>載入中斷向量到記憶體低1024個位元組單元中——>執行int 19H非強制中斷向量調用,載入並啟動儲存在硬碟MBR中的引導程式,裝有系統硬碟的MBR最後的標誌是55AAH,MBR引導程式載入並啟動儲存在使用中的磁碟分割PBR中的引導程式——>bios載入核心和initrd(由bootload初始化的記憶體盤,在linux核心啟動前,bootload會將儲存介質中的initrd檔案載入到記憶體,核心啟動時會在訪問真正的根檔案系統前訪問該記憶體中的initrd檔案系統)——>跳轉執行核心(核心頭部有自解壓程式)——>執行initrd——>負載檔案系統,啟動第一個進程init。當然,如果我們在編譯核心時,直接把SCSI、EXT3等編譯進核心,則可以不用設定initrd。否則,initrd是必須的,不然在啟動過程中會提示“VFS:unable
to mounting root fs”。
另外,對於多作業系統,實際上是多核心的作業系統,比如本文將要加裝2.6核心的情況下,啟動過程略有不同。即在時,是藉助grub來進行多個核心選擇的。使用BootLoader等軟體置換MBR中的引導程式或PBR中的引導程式,如Windows的NTBoot Loader,Linux下的Lilo、Grub等。Windows NTBoot Loader一般用於在一台機器上安裝多個Windows系統;Lilo或Grub用於在一台機器上安裝多個Linux系統或同時安裝Linux和Windows系統。本機中通過修改grub.conf來置換PBR中的引導程式。
二、加裝核心
1、相關工具製作安裝
由於2.6核心的核心模組處理過程有所改變,因此linux 2.4核心下的modutils工具包已經不再適合linux 2.6核心。需要下載較新版本的module-init-tools和modutils。比如module-init-tools-3.2.2.tar.bz2和modutils-2.4.5-1.src.rpm
地址:
http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/
http://www.kernel.org/pub/linux/utils/kernel/modutils/v2.4/
安裝modutils——由於下載的是源碼包,所以得先產生modutils rpm包,再安裝
#rpm -e --nodeps modutils (強行卸載原有的modutils RPM包)
#mv modutils-2.4.5-1.src.rpm /usr/src/redhat/ (把原始碼包移到/usr/src/redhat目錄下)
#cd /usr/src/redhat/SPECS (進入規範檔案目錄下)
#rmpbuild --bb modutils.spec (產生二進位的rpm包)
#cd ../RPMS/i386 (轉入剛產生的二進位的RPM包所在位置)
#rpm -ivh modutils*.rpm (安裝產生的modutils-2.4.5-1.i386.rpm和modutils-debuginfo-2.4.5-1.i386.rpm二進位RPM包)如下
安裝module-init-tools,它會替代depmod[/sbin/depmod]和其他工具,運行如下命令:
#tar -jxvf module-init-tools-3.2.2.tar.bz2
#cd module-init-tools-3.2.2
#./configure --prefix=/sbin
#make
#make install
./generate-modprobe.conf /etc/modprobe.conf
由於,我們這裡還得製作initrd,所以得安裝工具mkinitrd,則需下載較新版本的mkinitrd,而mkinitrd又依賴於程式包device-mapper,而device-mapper又依賴於lvm2,因此需下載lvm2、device-mapper、mkinitrd。
:
http://down1.chinaunix.net/distfiles/LVM2.2.02.51.tgz
http://down1.chinaunix.net/distfiles/device-mapper.1.02.28.tgz
http://down1.chinaunix.net/distfiles/mkinitrd-4.2.0.3.tar.bz2
它們的安裝與安裝module-init-tools類似
2、核心相關操作
下載核心
隨便點擊版本的下載連結,然後在下載工具上改下載源地址
http://www.kernel.org/pub/linux/kernel/v2.4/linux-2.6.15.5.tar.bz2
解壓核心
# cp linux-2.6.15.5.tar.bz2 /usr/src
# cd /usr/src
# tar -jxvf linux-2.6.15.5.tar.bz2
# ln -s linux-2.6.15.5 linux-2.6
# cd linux-2.6
編譯核心
# make mrproper (該命令可確保原始碼目錄下沒有不正確的.o檔案)
# make menuconfig (配置核心各選項)
個重要的配置:
* 關於"Code maturity level options"選項, 一定要選上"Prompt for development and/or incomplete code/drivers"
* 關於"Loadable Module support"選項, 一定要選上"Module unloading"和"Automatic kernel module loading"這兩個選項.
* 關於"Processor type and features"選項, 一定要選上"Preemptible Kernel"選項, 這是2.6.x核心優於2.4.x核心的重要原因之一.
* 關於"Device Drivers -->Block Devices"的配置, 一定要選上對"Loopback device support"和"Ramdisk support"的支援.
* 關於"Device Drivers -->Multi-device support(RAID and LVM)", 要選上"Device mapper support".
* 關於"Device Drivers -->Input device support", 記得要選上"Keyboards,Sun XT Newton"和"Mice"的支援.
* 關於"Device Drivers -->Graphics support -->Console display driver support", 要選上對"Framebuffer Console support"的支援.
* 關於"Sound -->Sound card support,Advanced Linux Sound Architecture -->"ALSA, 要選上"OSS API emulation"選項. OSS可以不用了.
* 關於USB, 能選的都選上吧,能*的選*,M的選M
* 檔案系統 ,請務必要選中ext3檔案系統,
File systems--->
[*] Ext3 journalling file system support
[*] Ext3 Security Labels
[*] JBD (ext3) debugging support
以上三項一定要選上,而且要內建(即標*). 這個非常重要,在配置完後一定要檢查一下.config檔案有沒有"CONFIG_EXT3_FS=y"這一項. 如果不是"CONFIG_EXT3_FS=y"而是"CONFIG_EXT3_FS=m",你在運行核心時就會遇上以下錯誤: pivotroot: pivot_root(/sysroot,/sysroot/initrd) failed
* 網卡驅動
請務必把自己網卡對應的驅動編譯進核心,比較普遍的網卡是realtek 8139,以下就是這種網卡的配置,以供參考
Device Drivers--->
Networking support--->
Ethernet (10 or 100Mbit) --->
<*> Ethernet (10 or 100Mbit)
<*> RealTek RTL-8139 C+ PCI Fast Ethernet Adapter support (EXPERIMENTAL)
<*> RealTek RTL-8139 PCI Fast Ethernet Adapter support
<*> AMD PCInet32 PCI support
* 音效卡驅動
也要選擇自己音效卡對應的驅動編譯進核心,比較普遍的音效卡是i810_audio,以下就是這種音效卡的配置,以供參考
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 i8x0/MX440, SiS 7012; Ali 5455; NForce Audio; AMD768/8111
Open Sound System --->
< > Open Sound System (DEPRECATED)
*Ramdisk大小
Device Drivers --->Block device->Default Ramdisk的大小應為1024的整數倍。預設值為4096,我們改為12288。
注意,如果用vmware進行編譯,那麼需要注意一些地方:
如果你在vmware下重新編譯核心,硬碟用的是scsi的,以下選項必選:
Device Drivers --->SCSI device support ---> <*> SCSI disk support
Device Drivers --->SCSI device support --->SCSI low-level drivers ---> <*> BusLogic SCSI support
配置部分來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/LUOPING198410/archive/2009/08/24/4480119.aspx
# make dep (建立編譯時間所需的從屬檔案。注意:如果核心從未編譯過,此步可跳過)
# make clean (清除核心編譯的目標檔案。注意:如果核心從未編譯過,此步可跳過)
# make bzImage (產生gzip壓縮的核心bzImage,位於/usr/src/linux-2.6/arch/i386/boot目錄)
3、編譯核心模組並安裝
# make modules (編譯核心模組)
# make modules_install (安裝核心模組,把核心模組安裝/lib/modules/2.6.15.5目錄)
4、針對2.6核心和2.4核心的差異,修改指令碼和設定檔
# gedit /etc/modules.conf
將"alias scsi hostadapter BusLogic"這行注釋掉,
即#alias scsi hostadapter BusLogic
儲存 /etc/modules.conf,退出
由於在配置中,找不到"alias scsi hostadapter BusLogic"這行,所以上步可以省略。
#mkdir /sys
#gedit /etc/rc.sysinit
1)找到行"mount -f /proc"在其下面增加內容:
if [ "$KERNELVER" = "2.6" ]; then
mount -f /sys
fi
2)找到行"action $"Mounting proc filesystem: " mount -n -t proc /proc /proc",在其下面增加如下內容:
if [ "$KERNELVER" = "2.6" ]; then
action $"Mounting sysfs filesystem: " mount -n -t sysfs /sys /sys"
fi
3)修改/etc/fstab檔案系統列表,在其中增加如下內容:
none /sys sysfs defaults 0 0
4)修改/etc/init.d/halt指令碼中的halt_get_remaining函數,將
awk '$2 ~ /^\/$|^\/proc|^\/dev/{next}
改為
awk '$2 ~ /^\/$|^\/proc|^\/sys|^\/dev/{next}
由於核心符號檔案/proc/ksyms被命名為/proc/kallsyms,所以必須修改啟動指令碼/etc/rc.sysinit。在其頭部增加如下內容:
UNAME='uname -r'
KERNELVER=${UNAME:0:3}
if [ "$KERNELVER" = "2.6" ]; then
KSYMS=/proc/kallsyms
else
KSYMS=/proc/ksyms
fi
然後,把rc.sysinit檔案中所有出現/proc/ksyms的地方都換成$KSYMS變數引用(用gedit開啟檔案有尋找、替換功能)
Linux 2.6的USB驅動模組被改名了,在主機控制器方面,usb-ohci被改為ochi-hcd,usb-uhci被改為uhci-hcd。因此,需在/etc/modprobe.conf設定檔中進行相應修改(我在本次操作中發現沒有此設定檔,故此不省略)
此外,支援USB鍵盤的模組名稱也從keybdev改為usbkbd,支援USB滑鼠的模組名稱也從mousedev改為submouse,故修改啟動指令檔/etc/rc.sysinit:
UNAME='uname -r'
KERNELVER=${UNAME:0:3}
if [ "$KERNELVER" = "2.6" ]; then
KSYMS=/proc/kallsyms
KEYBDEV_NAME=usbkdb
MOUSEDEV_NAME=usbmouse
else
KSYMS=/proc/ksyms
KEYBDEV_NAME=keybdev
MOUSEDEV_NAME=mousedev
fi
然後把/etc/rc.sysinit指令碼中出現keybdev和mousedev的地方都改為$KEYBDEV_NAME和$MOUSEDEV_NAME。
接著,修改指令碼/etc/rc.sysinit中的如下內容:
needusbstorage=
if [ $usb = "1" ]; then
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /proc/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /proc/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
fi
action $"Initializing USB keyboard: " modprobe $KEYBDEV_NAME 2> /dev/null
action $"Initializing USB mouse: " modprobe $MOUSEDEV_NAME 2> /dev/null
fi
改為:
needusbstorage=
if [ $usb = "1" ]; then
if [ "$KERNELVER" = "2.6" ]; then
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /sys/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /sys/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
else
needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /proc/bus/usb/devices 2>/dev/null`
LC_ALL=C grep 'hid' /proc/bus/usb/drivers || action $"Initializing USB HID interface: " modprobe hid 2> /dev/null
fi
action $"Initializing USB keyboard: " modprobe $KEYBDEV_NAME 2> /dev/null
action $"Initializing USB mouse: " modprobe $MOUSEDEV_NAME 2> /dev/null
fi
5、安裝核心
# grub-install /dev/sda
# make install
make install主要完成如下幾個工作:
複製產生的核心映像和核心符號表到/boot目錄。在核心編譯完成後,源碼目錄arch/i386/boot/中會產生bzImage檔案,該檔案被複製到/boot目錄並重新命名為vmlinuz-2.6.15.5。同時會在/linux-2.6/中產生核心符號表,該檔案被複製到/boot目錄並重新命名為System.map-2.6.15.5。然後在/boot/目錄下建立軟串連檔案vmlinuz和System.map,分別串連到vmlinuz-2.6.15.5和System.map-2.6.15.5。
在/boot/目錄下產生initrd-2.6.15.5.img.
配置引導程式grub
注意,配置引導程式在/boot/grub/grub.conf檔案中配置,千萬不要把kernel /vmlinux-2.6.0 項後面的" ro root=LABEL=/" 改成"ro root=/dev/sda1",否則等你啟用新核心時機器就會當掉,出錯資訊如下:kernel panic : no init found ,try passing init = option to kernel......或者是:kernel panic:VFS:Unable to mount root fs on unknown-block(0,0)。如果你是ext3檔案系統,則在定製核心設定檔時把對Ext3、Ext2檔案的支援直接編譯進核心,否則,等你啟用新核心時機器就會當掉,出錯資訊如下:kernel
panic : no init found ,try passing init = option to kernel......或者是:kernel panic:VFS:Unable to mount root fs on unknown-block(0,0)。
注意:嵌入式作業系統啟動過程則不同。先是開機啟動uboot,uboot分兩階段,第二階段會載入核心,其中在編譯時間產生的是zImage,通過# mkimage -n 'linux-2.6.25.8' -A arm -O linux -T kernel -C none -a 0x30008000 -e 0x30008040 -d zImage.bin bzImage.bin。產生帶標頭檔的壓縮核心鏡像。所以載入的是bzImage.bin核心。兩次解壓後,啟動核心,並負載檔案系統。即uboot——>bzImage——>檔案系統(init、開機動畫、Qt)。它並不需要initrd-xxx.img和grub等等。