講述了解Linux內核創(chuàng)建新系統(tǒng)
特別值得一提的是Linux內核源碼包是必須學習的,這里我們主要討論介紹Linux內核,包括介紹深談安裝新Linux內核等方面。Linux的基礎知識,包括Fedora的安裝、磁盤分區(qū)、Linux的基礎操作,旨在讓讀者對Linux有個初步的認識。涉及文件管理、磁盤管理、用戶與組群管理、man幫助、軟件包管理、文件壓縮和打印機管理。
去官方下載最新的Linux內核源碼包
官方網(wǎng)址:www.kernel.org
當前最新版本:2.6.31,下載網(wǎng)址:http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2
您可以使用 wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2 下載
解壓源碼包
(這里有些人說要將源碼解壓到/usr/src目錄下,其實是不正確的,你可以解壓到任何目錄)
cd ~wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2
tar -jxvf linux-2.6.31.tar.bz2
配置選項
cd linux-2.6.31
cp /boot/config-`uname -r` .config
make mrproper (刪除上次編譯產生的垃圾,初次編譯不需要)
make menuconfig (啟動Linux內核選項配置界面)
說明一下,make menuconfig會尋找linux-2.6.31目錄下的.config配置文件,如果找不到,則使用與CPU相關的config文件作為默認的配置。當然,我們也可以拷貝當前系統(tǒng)的配置作為對照,如cp /boot/config-`uname -r` .config (.config是隱藏文件 ls -a查看)
注意:如果是同版本的Linux內核編譯,還需要備份下當前模塊
cd /lib/modules
mv 2.6.31 2.6.31_old
指定Linux內核識別碼vim Makefile EXTRAVERSION = .custom-1 (第4行)
傳統(tǒng)方式編譯
make all (2.6以前版本需要手工運行如下命令)
(# make dep <==建立相依的屬性關系!
# make clean <==將舊的資料去除掉!
# make bzImage <==開始編譯核心!這個核心是經過壓縮的 (30分鐘左右)
# make modules <==開始編譯模塊!這個動作視您剛剛編譯的模塊數(shù)量!(1小時左右)
make modules_install (安裝模塊到/lib/modules/2.6.31),make install (系統(tǒng)將會把vmlinuz和System.map復制到/boot目錄下同時修改grub/boot/grub/menu.lst,2.6以前版本需要手動拷貝vmlinuz和System.map)
RPM方式編譯
會產生RPM包,方便提供給別人使用make rpm,編譯完成之后,在~/rpmbuild /SRPMS/目錄發(fā)現(xiàn)一個新的src.rpm包, 比如.SRPMS/kernel-2.6.31.custom-1.src.rpm, Linux內核rpm包位于~/rpmbuild/RPMS/i386/ (或RPMS/i586/, RPMS/i686/, 等. 看你的平臺類型). 比如.RPMS/i386/kernel-2.6.31.custom-1.i386.rpm. 可以看到Linux內核識別碼已添加到軟件包的名字中.
安裝新Linux內核
現(xiàn)在去新的rpmLinux內核包存在的目錄(基于你的平臺類型, 比如. ~/rpmbuild/RPMS/i386/)安裝rpm包,cd ~/rpmbuild/RPMS/i386
rpm -ivh kernel-2.6.31.custom-1.i386.rpm(現(xiàn)在你甚至能夠拷貝到其它的Fedora系統(tǒng), 通過上面的方式安裝. 你將不再需要編譯Linux內核.)
接下來我們?yōu)樾翷inux內核創(chuàng)建一個ramdisk, 否則系統(tǒng)將不能引導新Linux內核:
mkinitrd /boot/initrd-2.6.31.custom-1.img 2.6.31.custom-1
然后編輯/boot/grub/menu.lst文件, 看一下你系統(tǒng)上已經存在(正在工作的)引導Linux內核信息, 拷貝其中的一個實例, 替換為你新的Linux內核和ramdisk:vim /boot/grub/menu.lst
比如, 我的menu.lst, 在我添加新的Linux內核信息前的情況:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-1.2798.fc6.img
修改后的情況:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora Core (2.6.18-custom-2.6.18.2)
root (hd0,0)
kernel /vmlinuz-2.6.18-custom-2.6.18.2 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-custom-2.6.18.2.img
title Fedora Core (2.6.31.custom-1)
root (hd0,0)
kernel /vmlinuz-2.6.31.custom-1 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.31.custom-1.img
(你可以通過下面命令發(fā)現(xiàn)正確的vmlinuz和initrd文件:ls -l /boot)
重啟系統(tǒng),在Grub引導菜單中,選擇linux-2.6.31.custom-1。Reboot,重啟之后,大功告成,你的新Linux內核已經安裝好了。
【編輯推薦】