Fedora 14 编译LDD3的源码


直接到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.bkjia.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下重新安装一个内核还是蛮方便的

相关内容