Suse环境下编译linux-2.6.24内核

Suse环境下编译linux-2.6.24内核

1.下载linux-2.6.24内核源码:

https://mirrors.edge.kernel.org/pub/linux/kernel/v2.6/linux-2.6.24.tar.gz

2.解压linux-2.6.24.tar.gz文件,会生成linux-2.6.24目录

tar –xzf linux-2.6.24.tar.gz

3.编译环境构建

一般linux系统都自带gcc和make等编译工具,这里我的编译环境为SUSE Linux、gcc version 4.8.5、GNU Make 4.0

4.配置内核

linux提供了多种内核配置工具, 最基础的是 make config工具, 它列出每个编译选项, 而且是基于文本的

目前一般都推荐使用主流的make menuconfig工具, 但它需要curse库的支持, 在suse中默认是没有的, 所以在这里我使用的是make config工具

执行make config命令,自动生成.config配置文件

可能遇到以下错误:

Makefile:434: *** mixed implicit and normal rules.  Stop.

解决方法:

修改根目录下Makefile文件的第434行

-config %config : scripts_basic outputmakefile FORCE

+config : scripts_basic outputmakefile FORCE

可能也会遇到错误:

Makefile:1503: *** mixed implicit and normal rules.  Stop.

解决方法同上

    解决完以上错误后再次执行make config,会逐条列出每个编译选项,每个编译选项会有类似[M/n/y?]、[N/y/?]、[Y/n/?]的用户选项,位于首位的为内核推荐的配置,一直回车即可

    配置完成后会显示 # configuration written to .config 字样,在根目录下可以看到 .config文件,可以手动打开查看并编辑

5.编译内核源代码

依次执行

    make vmlinux  -j8(编译核心,-j指定使用多少线程进行gcc编译)

    make bzImage (制作bzImage,这个是给initramfs用的)

    make modules -j8 (编译模块)

    make modules_install (模块安装)

    make install(内核安装,修改grub等)

编译过程中的warning不用关注,关注error即可

遇到错误可以去stackoverflow上搜索,一般都能解决:

ü  gcc: error: elf_x86_64: No such file or directory

   gcc: error: unrecognized command line option ‘-m’

   解决方法:

   修改arch/x86/vdso/Makefile文件中第20行

   - cmd_syscall = $(CC) -m elf_x86_64 -nostdlib $(SYSCFLAGS_$(@F))

   + cmd_syscall = $(CC) –m64 -nostdlib $(SYSCFLAGS_$(@F))

ü  Error: .size expression for copy_user_generic_c does not evaluate to a constant scripts/Makefile.build:243: recipe for target 'arch/x86/lib/copy_user_64.o' failed

   解决方法:

   修改arch/x86/lib/copy_user_64.S文件第347行

  -END(copy_user_generic_c)

  +END(copy_user_generic_string)

ü undefined reference to `__mutex_lock_slowpath'

  解决方法:

  修改kernel/mutex.c文件中的第61行:

  -static void fastcall noinline __sched

  +static __used void fastcall noinline __sched

  修改kernel/mutex.c文件中的第98行:

  -static void fastcall noinline __sched

  +static __used void fastcall noinline __sched

  修改kernel/mutex.c文件中的第297行:

  -static void fastcall noinline __sched

  +static __used void fastcall noinline __sched

   ü  error: conflicting types for ‘getline’

解决方法:

修改scripts/unifdef.c文件,将其中所有的getline替换成get_line,共计三处,分别位于209、515、529行

编译完成后可以在linux-2.6.24根目录下看到以下文件和其他的临时文件

vmlinux   :  未经压缩的原始linux内核镜像.

/arch/<arch>/boot/zImage(bzImage):  使用zlib压缩后的内核镜像.

    注:不同的体系结构对压缩后内核镜像的默认命名不同,比如arm的是zImage,而i386的是bzImage.(z表示zlib, bz表示"big zlib")

执行 make install 后会发现/boot目录下多了linux-2.6.24的相关文件,自动更新了/boot/grub2、grub.cfg文件

之前的linux内核依然保留,两个内核版本同时存在

6.reboot重启选择新的内核进行启动即可

可能是由于我编译的linux内核的版本较老的缘故,

启动卡在了Loading Initial ramdisk….,新的内核无法启动,原因后续探究

此文的主要目的是体验linux的编译与安装流程

原文地址:https://www.cnblogs.com/tongyishu/p/11996741.html