操作系统项目(一)编译内核源码

下载完内核就可以对内核源代码编译了。本文描述的内核源码为2.6.30.1版本。

解压

tar jxf linux-2.6.30.1.tar.xz
cd linux-2.6.30.1/

生成基本的配置信息

make defconfig

配置

使用menuconfig进行配置

sudo apt-get install libncurses5-dev
make menuconfig

错误排除

1.出现错误syscall_trace_leave

arch/x86/include/asm/ptrace.h:146:13: note: previous declaration of 'syscall_trace_leave' was here
make[2]: *** [arch/x86/kernel/ptrace.o] Error 1
make[1]: *** [arch/x86/kernel] Error 2
make: *** [arch/x86] Error 2

解决方案参考这个补丁:https://patchwork.kernel.org/patch/1301031/

Patch

--- linux-2.6.32.59/arch/x86/include/asm/ptrace.h
+++ fix_ptrace.o_compile_error/arch/x86/include/asm/ptrace.h
@@ -130,6 +130,7 @@ 
 #ifdef __KERNEL__

 #include <linux/init.h>
+#include <linux/linkage.h>

 struct cpuinfo_x86;
 struct task_struct;
@@ -142,8 +143,8 @@ 
              int error_code, int si_code);
 void signal_fault(struct pt_regs *regs, void __user *frame, char *where);

-extern long syscall_trace_enter(struct pt_regs *);
-extern void syscall_trace_leave(struct pt_regs *);
+extern asmregparm long syscall_trace_enter(struct pt_regs *);
+extern asmregparm void syscall_trace_leave(struct pt_regs *);

 static inline unsigned long regs_return_value(struct pt_regs *regs)
 {

2.错误gcc不识别-m参数


gcc: error: unrecognized command line option ‘-m’
gcc: error: elf_i386: No such file or directory
make[1]: *** [arch/x86/vdso/vdso32-int80.so.dbg] Error 1

由于我现在用的是ubuntu 12.10 使用的是gcc-4.7,发现了一个新版本的移植的问题,所以安装gcc-4.4,然后重新链接就搞定了,可以继续编译:


sudo apt-get install gcc-4.4
cd /usr/bin
sudo ln -s -f gcc-4.4 gcc

继:续编译中:

#使用-j4指定4个线程编译
make -j4

编译成功

基本使用的默认设置,就是第一步的make defconfig后的配置参数,然后make -j4,好像编译的挺快的,后面在详细研究以下各种参数,已经如何启用这个自己编译的内核 :)。

CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-x86
  CALL    scripts/checksyscalls.sh
  CHK     include/linux/compile.h
  VDSOSYM arch/x86/vdso/vdso32-int80-syms.lds
  VDSOSYM arch/x86/vdso/vdso32-sysenter-syms.lds
  VDSOSYM arch/x86/vdso/vdso32-syms.lds
  LD      arch/x86/vdso/built-in.o
  LD      vmlinux.o
  MODPOST vmlinux.o
WARNING: modpost: Found 3 section mismatch(es).
To see full details build your kernel with:
'make CONFIG_DEBUG_SECTION_MISMATCH=y'
  GEN     .version
  CHK     include/linux/compile.h
  UPD     include/linux/compile.h
  CC      init/version.o
  LD      init/built-in.o
  LD      .tmp_vmlinux1
  KSYM    .tmp_kallsyms1.S
  AS      .tmp_kallsyms1.o
  LD      .tmp_vmlinux2
  KSYM    .tmp_kallsyms2.S
  AS      .tmp_kallsyms2.o
  LD      .tmp_vmlinux3
  KSYM    .tmp_kallsyms3.S
  AS      .tmp_kallsyms3.o
  LD      vmlinux
  SYSMAP  System.map
  SYSMAP  .tmp_System.map
  OBJCOPY arch/x86/boot/compressed/vmlinux.bin
  GZIP    arch/x86/boot/compressed/vmlinux.bin.gz
  LD      arch/x86/boot/compressed/piggy.o
  LD      arch/x86/boot/compressed/vmlinux
  OFFSETS arch/x86/boot/offsets.h
  AS      arch/x86/boot/header.o
  CC      arch/x86/boot/version.o
  LD      arch/x86/boot/setup.elf
  OBJCOPY arch/x86/boot/setup.bin
  OBJCOPY arch/x86/boot/vmlinux.bin
  BUILD   arch/x86/boot/bzImage
Root device is (8, 11)
Setup is 10060 bytes (padded to 10240 bytes).
System is 3539 kB
CRC d3a625ec
Kernel: arch/x86/boot/bzImage is ready  (#2)
  Building modules, stage 2.
  MODPOST 2 modules

生成压缩映像文件

执行以下命令

make bzImage

参考:http://www.cnblogs.com/QuLory/archive/2012/09/27/2706429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值