歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Fedora 14 編譯LDD3的源碼

Fedora 14 編譯LDD3的源碼

日期:2017/3/1 11:15:41   编辑:Linux編程
直接到example下的某個目錄如scull下去make,會出現一堆錯誤
說明一下,Fedora14帶內核源碼的頭文件(或者yum install kernel-devel安裝這些頭文件),沒帶源碼,但是對於編譯ldd3裡的的例子,這些頭文件就足夠了
並且Makefile已經指定了正確的內核目錄
#KERNELDIR ?= /lib/modules/$(shell uname -r)/build
所以出現的這些錯誤,僅僅是由內核版本不一致造成的
ldd3的例子是2.6.10內核時代的東東,而fc14的內核版本是2.6.35.6-45
2.6.35內核中更新了的一些數據結構,所以用當時參照2.6.10內核寫的ldd3的例子就很可能用新內核去編譯時而出錯
解決方法是讓ldd的例子去適應新的內核版本或者給換個2.6.10的內核去編譯
error: ‘system_utsname’ undeclared
新版本沒有這個東東,干脆就在那個文件裡定義一個char *system_utsname="x86";然後在代碼中去掉.machine


如果想擁有一個完整的內核源代碼來代替fc14自帶的殼,可以如下去做
到下面鏈接下載14的kernel即kernel-2.6.35.6-45.fc14.src.rpm
http://download.fedora.RedHat.com/pub/fedora/linux/releases/14/Fedora/source/SRPMS/
另外,15的
http://download.fedora.redhat.com/pub/fedora/linux/releases/15/Fedora/source/SRPMS/
而13 12 11 10 9 等在此處
http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/
比如
http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/12/Fedora/source/SRPMS/
目前的情況是這樣,但不久後14 15可能也會搬到archives去
說明:也可到www.kernel.org去下某個版本的內核源碼,但是下載編譯後,要給fc14換上(安裝)這個內核鏡像,
這樣以後用這個版本的內核源碼編譯的內核模塊在本機insmod時才能順利通過
執行

rpm -uvh kernel-2.6.35.6-45.fc14.src.rpm
執行

cd /root/rpmbuild/SPECS
說明:fedora14默認/root/rpmbuild為srpm的主目錄(貌似以前版本為/usr/src/redhat/)
refer to http://help.directadmin.com/item.php?id=381
執行以下命令,出現錯誤
  1. [root@localhost SPECS]# rpmbuild -bp --target $(uname -m) kernel.spec
  2. Building target platforms: i686
  3. Building for target i686
  4. error: Failed build dependencies:
  5. xmlto is needed by kernel-2.6.35.6-45.fc14.i686
  6. asciidoc is needed by kernel-2.6.35.6-45.fc14.i686
  7. elfutils-devel is needed by kernel-2.6.35.6-45.fc14.i686
  8. perl(ExtUtils::Embed) is needed by kernel-2.6.35.6-45.fc14.i686
把缺少的東東分別安裝一下
yum install xmlto
yum intsall asciidoc
yum install elfutils-devel
yum install perl-ExtUtils-Embed.noarch (this refers to http://joysofprogramming.com/install-perl-extutils-embed-fedora-rhel/)
重新執行上面那個命令,
源碼已經塞進了/root/rpmbuild/BUILD
  1. [root@localhost rpmbuild]# ls
  2. BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
  3. [root@localhost rpmbuild]# cd BUILD
  4. [root@localhost BUILD]# ls
  5. kernel-2.6.35.fc14
  6. [root@localhost BUILD]# ls kernel-2.6.35.fc14/
  7. linux-2.6.35.i686 vanilla-2.6.35
  8. [root@localhost BUILD]# ls kernel-2.6.35.fc14/linux-2.6.35.i686/
  9. arch config-rhel-generic fs net
  10. block configs include README
  11. config-arm config-s390x init REPORTING-BUGS
  12. config-debug config-sparc64-generic ipc samples
  13. config-generic config-x86_64-generic Kbuild scripts
  14. config-i686-PAE config-x86-generic kernel security
  15. config-ia64-generic COPYING lib sound
  16. config-nodebug CREDITS MAINTAINERS tools
  17. config-powerpc32-generic crypto Makefile usr
  18. config-powerpc32-smp Documentation merge.pl virt
  19. config-powerpc64 drivers mm
  20. config-powerpc-generic firmware modules.order
  21. [root@localhost BUILD]# cd kernel-2.6.35.fc14/linux-2.6.35.i686/
  22. [root@localhost linux-2.6.35.i686]#
執行
  1. [root@localhost linux-2.6.35.i686]# vi Makefile
  2. /*修改line 4為
  3. EXTRAVERSION = .6-45.fc14.i686
  4. 要保證與uname -r的結果一致
  5. */
  6. [root@localhost linux-2.6.35.i686]# make mrproper
  7. [root@localhost linux-2.6.35.i686]# cp configs/kernel-2.6.35.6-i686.config .config
  8. [root@localhost linux-2.6.35.i686]#

或者考/boot下的config來用也行
執行
make

執行
make modules
現在已經達到了一個編譯過的完整的內核源碼了,
/lib/modules/2.6.35.6-45.fc14.i686/build/本來就存在並連接到/usr/src/kernels/2.6.35.6-45.fc14.i686,
現在將其連接到/root/rpmbuild/BUILD/kernel-2.6.35.fc14/linux-2.6.35.i686/即可
(這個貌似也不必自己動手去做,執行過make install 時會自動修正鏈接)
執行
make modules_install
*********************************************************************
如果想安裝一下剛才編譯過的內核
執行
make install
(系統將會把vmlinuz和System.map復制到/boot目錄下並自動加上$(uname -r)後綴,
同時修改grub/boot/grub/menu.lst,2.6以前版本需要手動拷貝vmlinuz和System.map)
重啟即可見到新內核

對於grub.conf(menu.list僅是一個指向他的符號)
  1. # grub.conf generated by anaconda http://www.linuxidc.com
  2. #
  3. # Note that you do not have to rerun grub after making changes to this file
  4. # NOTICE: You have a /boot partition. This means that
  5. # all kernel and initrd paths are relative to /boot/, eg.
  6. # root (hd0,0)
  7. # kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-LogVol02
  8. # initrd /initrd-[generic-]version.img
  9. #boot=/dev/sda
  10. default=0
  11. timeout=10
  12. splashimage=(hd0,0)/grub/splash.xpm.gz
  13. hiddenmenu
  14. title Fedora (2.6.35.6-45.fc14.i686)
  15. root (hd0,0)
  16. kernel /vmlinuz-2.6.35.6-45.fc14.i686 ro root=/dev/mapper/VolGroup-LogVol02 rd_LVM_LV=VolGroup/LogVol02 rd_LVM_LV=VolGroup/LogVol00 rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
  17. initrd /initramfs-2.6.35.6-45.fc14.i686.img
kernel所指文件是內核鏡像
initrd所指img文件用於引導硬件到實際內核vmlinuz能夠接管並繼續引導的狀態
而System.map是內核導出的符號表
這三種文件都會存在/boot下
*********************************************************************
看來fedora下重新安裝一個內核還是蠻方便的
Copyright © Linux教程網 All Rights Reserved