用Linux開源核心打造自己的LINUX發行版

來源:互聯網
上載者:User

  其實,編譯核心並不是一件難事.如果能按照正確的方法來操作,最多花上一個半小時就能搞定.是不是很受鼓舞呀。那今天我就帶大家一起打造一個自己的核心系統.

  一 編譯前準備

  1)下載一份核心原始碼,我下的是linux-2.6.7.tar.bz2,你可在如下地址下載它或者是更新的版本.

  http://kernel.org/pub/linux/kernel/v2.6/

  2) 下載最新版本的module-init-tools( "module-init-tools-3.0.tar.gz" and "modutils-2.4.21-23.src.rpm")

  http://www.kernel.org/pub/linux/ker...ools-3.0.tar.gz

  http://www.kernel.org/pub/linux/ker...4.21-23.src.rpm

  3)安裝module-init-tools. 它會替代depmod [/sbin/depmod]和其他工具.

  tar -zxvf module-init-tools-3.0.tar.gz

  cd module-init-tools-3.0

  ./configure --prefix=/sbin

  make

  make install

  ./generate-modprobe.conf /etc/modprobe.conf

  4)安裝modutils-2.4.21-23.src.rpm. 你可能會看到"user rusty and group rusty not existing"的警告. 沒關係,你只需強制安裝就是了.如果你不對Redhat 9和Redhat 8做這幾步, 你將會在"make modules_install"這一步時出現問題.

  rpm -i modutils-2.4.21-23.src.rpm

  rpmbuild -bb /usr/src/redhat/SPECS/modutils.spec

  rpm -Fi /usr/src/redhat/RPMS/i386/modutils-2.4.21-23.i386.rpm

  5)解壓縮核心原始碼.把下載的原始碼包放到目錄/usr/src下,然後

  cd /usr/src

  tar xvfj linux-2.6.7.tar.bz2

  cd linux-2.6.7

  二、 編譯配置

  在這一部分涉及幾個重要模組的配置請,特別注意.一般用"make menuconfig"命令來配置核心.輸入以上命令後出現一個菜單介面,使用者可以對需要的模組.下面著重講幾個重要的配置。

  1)檔案系統

  請務必要選中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

  2)網卡驅動

  請務必把自己網卡對應的驅動編譯進核心,比較普遍的網卡是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

  3)音效卡驅動

  也要選擇自己音效卡對應的驅動編譯進核心,比較普遍的音效卡是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)

  以上三項配置關係到新核心能否正常運行,請備加註意.其他的配置如果不是很瞭解,大可以按預設的選擇.

  三、 編譯過程

  按如下命令編譯,大概需要一個多小時,大可以好好放鬆一下:-)

  make bzImage

  make modules

  make modules_install

  make install

  運行新核心之前,請檢查一下/boot/grub/grub.conf的內容,下面的配置可作參考

  # 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/hdc3

  # initrd /initrd-version.img

  #boot=/dev/hdc

  default=1

  timeout=10

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

  title Red Hat Linux (2.6.7)

  root (hd0,0)

  kernel /vmlinuz-2.6.7 ro root=LABEL=/

  initrd /initrd-2.6.7.img

  title Red Hat Linux (2.4.20-8)

  root (hd0,0)

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

  initrd /initrd-2.4.20-8.img

  四、 運行核心的常見問題

  1)RPM問題

  進入編譯好的核心後,與RPM相關的命令有些不能使用,並出現下列錯誤:

  rpmdb: unable to join the environment

  error: db4 error(11) from dbenv->open: Resource temporarily unavailable

  error: cannot open Packages index using db3 - Resource temporarily unavailable (11)

  error: cannot open Packages database in /var/lib/rpm

  no packages

  解決方案是執行“export LD_ASSUME_KERNEL =2.2.25”命令,也可以將其寫入/etc/bashrc。

  2)Sound問題

  聲音部分的模組名也改變了。我的筆記本原來的音效卡驅動是i810_audio,現在已改為snd-intel8x0。因此需要把下面的內容添加到/etc/modprobe.conf中:

  alias char-major-14 soundcore

  alias sound snd-intel8x0

  alias sound-slot-0 snd-intel8x0

  alias snd-card-0 snd-intel8x0

  alias sound-service-0-0 snd-mixer-oss

  alias sound-service-0-1 snd-seq-oss

  alias sound-service-0-3 snd-pcm-oss

  alias sound-service-0-8 snd-seq-oss

  alias sound-service-0-12 snd-pcm-oss

  install snd-intel8x0 /sbin/modprobe --ignore-install sound-slot-0 &&

  { /bin/aumix-minimal -f /etc/.aumixrc -L >/dev/null 2>&1; /bin/true; }

  remove snd-intel8x0

  { /bin/aumix-minimal -f /etc/.aumixrc -S >/dev/null 2>&1; /bin/true; };

  /sbin/modprobe -r --ignore-remove sound-slot-0

  然後執行“modprobe sound”載入聲音模組,並使用下列命令檢驗音效卡驅動:

  #cat /proc/asound/cards

  顯示結果如下:

  0 [SI7012]: ICH - SiS SI7012

  SiS SI7012 at 0xdc00, irq 11

  3)VMware問題

  解決方案是:

  ◆ 將/usr/bin/vmware-config.pl中所有的“/proc/ksyms”替換為“/proc/kallsyms”。使用“sed”命令可以達到這個目的。

  ◆ 重新運行該指令碼,使用核心標頭檔編譯新的核心模組。在編譯過程中如發生錯誤,應該進入/usr/lib/vmware/modules/source,使用下面的命令將vmnet.tar解包:

  #tar xvf vmnet.tar

  ◆ 進入vmnet-only目錄修改bridge.c檔案。將“atomic_add(skb->truesize, &sk->wmem_alloc);”修改為“atomic_add(skb->truesize, &sk->sk_wmem_alloc);”,並用類似的方式將“protinfo”改為“sk_protinfo”。

  ◆ 再次把vmnet-only目錄用下面的命令重新打包為vmmon.tar:

  #tar cvf vmmon.tar vmnet-only。

  如果按照上面的操作依舊失敗,另一解決方案是到http://ftp.cvut.cz/vmware/下載vmwar...渲械膔unme.pl。

  4)USB問題

  新的2.6.0核心中使用的USB模組大多數已經改名,因此需要修改/etc/rc.sysinit中對USB子系統初始化的代碼。將該檔案中所有的 “keybdev”改為“usbkbd”、“mousedev”改為“usbmouse”、“/proc/bus/usb”改為 “/sys/bus/usb”,並在/etc/init.d/halt中進行同樣的修改。此外,還要在/etc/rc.sysinit中找到 “needusbstorage”,做如下修改:

  needusbstorage=

  if [ $usb = "1" ]; then

  needusbstorage=`LC_ALL=C grep -e "^I.*Cls=08" /sys/bus/usb/devices 2>/dev/null`

  action $"Initializing USB 1.1 host controller: " modprobe ohci-hcd 2> /dev/null

  action $"Initializing USB HID interfa

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.