`

编译linux kernel

 
阅读更多

  (1)安装module-init-tools-3.0.tar.gz:

  # 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

  不知道为什么,我用module-init-tools-3.1时make出错。如果改用3.0的就没事了。

  (2)安装modutils-2.4.25-8.9.i386.rpm:

  # rpm -Uvih modutils-2.4.25-8.9.i386.rpm 
  对modutils进行升级。

  (3)安装新内核:

  将新内核copy到/usr/src下,

  #tar xzvf linux-2.6.11.tar.gz -----解压缩. 
  II. 将名为linux的符号链接删掉,这时旧版本内核的符号链接. 
  #ln -s linux-2.6.11 linux ------建立linux-2.6.11的符号链接linux.

  设置内核. 
  # cd /usr/src/linux 
  # make mrproper -----删除不必要的文件和目录.

  #make config(基于文本的最为传统的配置界面,不推荐使用)

  #make menuconfig(基于文本选单的配置界面,字符终端下推荐使用)

  #make xconfig(基于图形窗口模式的配置界面,Xwindow下推荐使用)

  #make oldconfig(如果只想在原来内核配置的基础上修改一些小地方,会省去不少麻烦)

  它们的目的是一样的,那就是生成一个.config文件

  这三个命令中,make xconfig的界面最为友好,如果你可以使用Xwindow,你就用这个好了,这个比较方便,也好设置。如果你不能使用Xwindow,那么就使用make menuconfig好了。界面虽然比上面一个差点,总比make config的要好多了。 
选择相应的配置时,有三种选择,它们分别代表的含义如下:

    Y--将该功能编译进内核 
    N--不将该功能编译进内核 
    M--将该功能编译成可以在需要时动态插入到内核中的模块

  如果使用的是make xconfig,使用鼠标就可以选择对应的选项。如果使用的是 make menuconfig,则需要使用空格键进行选取。你会发现在每一个选项前都有个括号, 但有的是中括号有的是尖括号,还有一种圆括号。用空格键选择时可以发现,中括号里要么是空,要么是"*",而尖括号里可以是空,"*"和"M"。这表示前者对应的项要么不要,要么编译到内核里;后者则多一样选择,可以编译成模块。而圆括号的内容是要你在所提供的几个选项中选择一项。

  附内核配置选项说明(这是我在网上找到的,还可以,有些也是不一样的,给你一个参考)

  代码成熟度选项:

Code maturity level options ---> 
[*] Prompt for development and/or incomplete code/drivers 
[*] Select only drivers expected to compile cleanly

  打开使用开发中、不完全的代码/驱动会让内核配置多出很多选项,由于我们需要使用一些正在开发中的功能,因此必需打开这一选项。 
通用设置选项,

General setup --->

() Local version - append to kernel release 
这里填入的是64字符以内的字符串,你在这里填上的字符口串可以用uname -a命令看到。 
[*] Support for paging of anonymous memory (swap) 
这是使用交换分区或者交换文件来做为虚拟内存的,当然要选上了。 
[*] System V IPC 
表示系统5的Inter Process Communication,它用于处理器在程序之间同步和交换信息,如果不选这项,很多程序运行不起来 
[*] POSIX Message Queues 
这是POSIX的消息队列,它同样是一种IPC。建议你最好将它选上 
[*] BSD Process Accounting 
这是充许用户进程访问内核将账户信息写入文件中的。这通常被认为是个好主意,建议你最好将它选上。 
[*] BSD Process Accounting version 3 file format 
[*] Sysctl support 
这个选项能不重新编译内核修改内核的某些参数和变量,如果你也选择了支持/proc,将能从/proc/sys存取可以影响内核的参数或变量。建议你最好将它选上 
[ ] Auditing support 
审记支持,用于和内核的某些子模块同时工作,例如SELinux。只有选择此项及它的子项,才能调用有关审记的系统调用 
(15) Kernel log buffer size (16 => 64KB, 17 => 128KB) 
内核日志缓存的大小,12 => 4 KB,13 => 8 KB,14 => 16 KB单处理器,15 => 32 KB多处理器,16 => 64 KB for x86 NUMAQ or IA-64,17 => 128 KB for S/390 
[*] Support for hot-pluggable devices 
是否支持热插拔的选项,肯定要选上 
[*] Kernel Userspace Events 
内核中分为系统区和用户区,这里系统区和用户区进行通讯的一种方式,选上。 
[*] Kernel .config support 
将.config配置信息保存在内核中,选上它及它的子项使得其它用户能从/proc中得到内核的配置 
[*] Enable access to .config through /proc/config.gz 
[ ] Configure standard kernel features (for small systems) ---> 
这是为了编译某些特殊的内核使用的,通常你可以不选择这一选项,你也不用对它下面的子项操心了。 
--- Configure standard kernel features (for small systems) 
[ ] Load all symbols for debugging/kksymoops 
是否装载所有的调试符号表信息,如果你不需要对内核调试,不需要选择此项。 
[*] Enable futex support 
不选这个内核不一定能正确的运行使用glibc的程序,当然要选上 
[*] Enable eventpoll support 
不选这个内核将不支持事件轮循的系统调用,最好选上 
[*] Optimize for size 
这个选项使gcc使用-Os的参数而不是-O2的参数来优化编译,以获得更小尺寸的内核,建议选上。 
[*] Use full shmem filesystem 
除非你在很少的内存且不使用交换内存时,才不要选择这项 
(0) Function alignment 
(0) Label alignment 
(0) Loop alignment 
(0) Jump alignment

可加载模块: 
Loadable module support ---> 
[*] Enable loadable module support 
[*] Module unloading 
不选这个功能,加载的模块就不能卸载 
[ ] Forced module unloading 
[ ] Module versioning support (EXPERIMENTAL) 
[ ] Source checksum for all modules 
[*] Automatic kernel module loading

处理器类型及特性: 
Processor type and features ---> 
Subarchitecture Type (PC-compatible) ---> 
Processor family (Pentium-4/Celeron(P4-based)/Pentium-4 M/Xeon) ---> 
[ ] Generic x86 support 
这一选项针对x86系列的CPU使用更多的常规优化。如果你在上面一项选的是i386、i586之类的才选这个 
[*] HPET Timer Support 
HPET是替代8254芯片的下一代时钟处理器。这里你可以安全的选上这一选项。如果硬件不支持的话,将仍使用8254时钟处理器 
[*] Symmetric multi-processing support 
对称多处理器支持,在单CPU的机器上,不选这个选项会更快一些。由于超线程技术,看起来是两颗CPU,因些要选上这个选项 
(1) Maximum number of CPUs (2-255) 支持的最大CPU数 
[ ] SMT (Hyperthreading) scheduler support 
[*] Preemptible Kernel 
这个选项能使应用程序即使内核在高负载时也很可靠,建议最好选上 
[*] Machine Check Exception 
这个选项能让CPU检测到系统故障时通知内核,一般我用组装的台式机会选这项。 
< > Toshiba Laptop support 
< > Dell laptop support 
< > /dev/cpu/microcode - Intel IA32 CPU microcode support 
< > /dev/cpu/*/msr - Model-specific register support 
< > /dev/cpu/*/cpuid - CPU information support 
Firmware Drivers ---> 
< > BIOS Enhanced Disk Drive calls determine boot disk (EXPERIMENTAL) 
High Memory Support (4GB) ---> 
[ ] Allocate 3rd-level pagetables from highmem 
[ ] Math emulation 
[*] MTRR (Memory Type Range Register) support 
[ ] Boot from EFI support (EXPERIMENTAL) 
[*] Enable kernel irq balancing 

[ ] Use register arguments (EXPERIMENTAL)

电源管理: 
Power management options (ACPI, APM) ---> 
[*] Power Management support 
[ ] Power Management Debug Support 
[ ] Software Suspend (EXPERIMENTAL) 
ACPI (Advanced Configuration and Power Interface) Support ---> 
APM (Advanced Power Management) BIOS Support ---> 
CPU Frequency scaling --->

ACPI (Advanced Configuration and Power Interface) Support ---> 
[*] ACPI Support 
这是一种电源管理方式,你可以看看你的BIOS是否支持。如果支持的话建议你选上这项 
[ ] Sleep States (EXPERIMENTAL) 
< > AC Adapter 
< > Battery 
<*> Button 捕获Power、Sleep、Lid(我也不知道这是什么按钮)等按钮是否按下,并做相应的动作 
<*> Video 集成在板上的显卡的ACPI支持,对有些板卡可能不起作用 
< > Fan 
<*> Processor 
<*> Thermal Zone 
< > ASUS/Medion Laptop Extras 
< > IBM ThinkPad Laptop Extras 
< > Toshiba Laptop Extras 
(0) Disable ACPI for systems before Jan 1st this year 
[ ] Debug Statements 
[*] Power Management Timer Support

APM (Advanced Power Management) BIOS Support ---> 
< > APM (Advanced Power Management) BIOS support 
高级电源管理的支持,一般来说笔记本应该选上,台式机可以不选。 
[ ] Ignore USER SUSPEND 
[*] Enable PM at boot time 
[ ] Make CPU Idle calls when idle 
[ ] Enable console blanking using APM 
[ ] RTC stores time in GMT 按Unix的标准,硬件的时钟应该设为格林威治时间 
[ ] Allow interrupts during APM BIOS calls 
[*] Use real mode APM BIOS call to power off

[*] CPU Frequency scaling 
这一选项允许改变CPU的主频,使CPU在低负荷或使用电池时降低主频,达到省电的目的。 
[ ] Enable CPUfreq debugging 
< > /proc/cpufreq interface (deprecated) 
Default CPUFreq governor (performance) ---> 
--- 'performance' governor 
<*> 'powersave' governor 
<*> 'userspace' governor for userspace frequency scaling 
[ ] /proc/sys/cpu/ interface (2.4. / OLD) 
<*> 'ondemand' cpufreq policy governor自动调节主频 
<*> CPU frequency table helpers 多数的CPU需要这一项来调节主频 
<*> ACPI Processor P-States driver 报告处理器的状态 
< > AMD Mobile K6-2/K6-3 PowerNow! 
< > AMD Mobile Athlon/Duron PowerNow! 
< > AMD Opteron/Athlon64 PowerNow! 
< > Cyrix MediaGX/NatSemi Geode Suspend Modulation 
<*> Intel Enhanced SpeedStep Intel的变频技术支持 
[ ] Use ACPI tables to decode valid frequency/voltage pairs 
--- Built-in tables for Banias CPUs 
< > Intel Speedstep on ICH-M chipsets (ioport interface) 
< > Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface) 
< > Intel Pentium 4 clock modulation 
< > nVidia nForce2 FSB changing 
< > Transmeta LongRun 
< > VIA Cyrix III Longhaul 
--- shared options 
[ ] /proc/acpi/processor/../performance interface (deprecated) 
[ ] Relaxed speedstep capability checks

总线类型: 
[*] PCI support 
PCI access mode (Any) --->强列建议选Any,系统将优先使用MMConfig,然后使用BIOS,最后使用Direct检测PCI设备。 
[ ] Message Signaled Interrupts (MSI and MSI-X) 
[ ] Legacy /proc/pci interface 
[ ] PCI device name database 
[ ] ISA support 
[*] EISA support 
[*] Vesa Local Bus priming 
[*] Generic PCI/EISA bridge 
[*] EISA virtual root device 
[ ] EISA device name database 
[ ] MCA support 
< > NatSemi SCx200 support 
PCCARD (PCMCIA/CardBus) support ---> 
PCI Hotplug Support --->

PCCARD (PCMCIA/CardBus) support --->一般只有笔记本电脑上才会有PCMCIA插槽,如果你是台式机的话,可以不选这一项,然后跳过这一部份。

PCI Hotplug Support ---> 
< > Support for PCI Hotplug (EXPERIMENTAL)

  一般来讲只有服务器上会有热插拔的设备,如果你使用的是台式机,你可以不选择此项并跳过这一部份。

可执行文件格式,

[*] Kernel support for ELF binaries 
ELF是开放平台下最常用的二进制文件,它支持不同的硬件平台 
< > Kernel support for a.out and ECOFF binaries 
<*> Kernel support for MISC binaries

  此选项允许插入二进制的封装层到内核中,当使用Java、.NET、Python、Lisp等语言编写的程序时非常有用

  硬件设备相当复杂,看得偶头晕,大家针对自己的设备慎重选择(手边最好准备一本汉英字典:)如果想使用adsl,记得网络部分除了TCP/IP协议还得把ppp部分编译进内核,想当初偶就是把这个给忘了,郁闷了许久。

文件系统, 
<*> Second extended fs support 
[*] Ext2 extended attributes 
[*] Ext2 POSIX Access Control Lists 
[*] Ext2 Security Labels 
<*> Ext3 journalling file system support 
[*] Ext3 extended attributes 
[*] Ext3 POSIX Access Control Lists 
[*] Ext3 Security Labels 
[ ] JBD (ext3) debugging support 
<*> Reiserfs support 
[ ] Enable reiserfs debug mode 
[ ] Stats in /proc/fs/reiserfs 
[*] ReiserFS extended attributes 
[*] ReiserFS POSIX Access Control Lists 
[*] ReiserFS Security Labels 
JFS filesystem support 
[*] JFS POSIX Access Control Lists 
[ ] JFS debugging 
[ ] JFS statistics 
XFS filesystem support 
[*] Realtime support (EXPERIMENTAL) 
[*] Quota support 
[*] Security Label support 
[*] POSIX ACL support 
< > Minix fs support 
< > ROM file system support 
[*] Quota support 
< > Old quota format support 
Quota format v2 support 
[*] Dnotify support 
< > Kernel automounter support 
< > Kernel automounter version 4 support (also supports v3) 
CD-ROM/DVD Filesystems ---> 
DOS/FAT/NT Filesystems ---> 
Pseudo filesystems ---> 
Miscellaneous filesystems ---> 
Network File Systems ---> 
Partition Types ---> 
Native Language Support ---> 
Profiling support ---> 
Kernel hacking ---> 
Security options ---> 
Cryptographic options ---> 
Library routines --->

  这个东东你要是搞不来就不要搞,默认的也可以的。先学习一下怎么样编译内核,等成功了,有了经验了在改也没有事的!

编译内核: 
# cd /usr/src/linux 
# make dep -----链接程序代码与函数库. 
# make clean -----删除不必要的模块和文件. 
# make bzImage -----开始编译系统内核. 
# make modules -----开始编译外挂模块. 
# make modules_install -----安装编译完成的模块. 
要好常时间的,我洗了一件衣服,抽了N根白沙之后,总算完成了,好激动呀! 
# su - 
# /sbin/depmod -a -----创建模块的链接. 

更换内核: 
# cd /boot -----切换到引导分区/boot. 
# rm System.map vmlinuz -----删除旧的符号链接. 
# mv /usr/src/linux/System.map System.map 
# mv /usr/src/linux/arch/i386/boot/bzImage vmlinuz

如果你用GRUB来管理开机,简单点就是你装了win还装了linux就要修改/boot/grub下的menu.1st文件: 
# vi /boot/grub/menu.1st 
键入i进入编辑模式:


# grub.conf generated by anaconda 

# Note that you do not have to rerun grub after making changes to this file 
# NOTICE: You do not have a /boot partition. This means that 
# all kernel and initrd paths are relative to /, eg. 
# root (hd0,1) 
# kernel /boot/vmlinuz-version ro root=/dev/hda2 
# initrd /boot/initrd-version.img 
#boot=/dev/hda 
default=1 
timeout=10 
splashimage=(hd0,1)/boot/grub/splash.xpm.gz 
title Fedora Core(2.6.11) 
root (hd0,1) 
kernel /boot/vmlinuz ro root=/dev/hda2 ---你的linux所在的分区 
title DOS 
rootnoverify (hd0,0) 
chainloader +1


title Fedora Core(2.4.22) 
root (hd0,1) 
kernel /boot/vmlinuz-2.4.22-1.2115.nptl ro root=LABEL=/ hdd=ide-scsi rhgb 
initrd /boot/initrd-2.4.22-1.2115.nptl.img 
这样还可以保留旧版本的内核以防编译新内核失败进不了系统

  重启电脑,好了,进去了。网上说新内核速度好快的,我怎么感觉快不了多少呢。无所谓了,反正是成功了。呵呵,我可是失败了很多次才成功的。好高兴,2点了,穿衣服去吃东西了。

rpm没法用了,怎么办? 
在/usr/lib/rpm/macros里面寻找代码: 
%__dbi_cdb create cdb mpool mp_mmapsize=16Mb mp_size=1Mb 
修改成代码: 
%__dbi_cdb create cdb mpool mp_mmapsize=16Mb mp_size=1Mb private

 

 

 

 

 

 

 

 

 

 

 

------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------------

 

 

内核编译实验环境:Ubuntu 10.04 内核版本 2.6.32-36-generic

 

过程概述:

下载源码:下载链接:http://www.kernel.org/pub/linux/kernel/v2.6/

配置内核:make menuconfig

编译内核:make bzImage

编译内核模块:make modules

安装内核模块:make modules_install

安装内核:make install

完成最后遗留工作

 

一、内核编译的准备工作:

1。使用root用户,方便以后操作

jb@jb-laptop:~$ su
密码: 
root@jb-laptop:/home/jb# 

2。查看自己内核版本,以便选择新编译版本

root@jb-laptop:/home/jb# uname -r
2.6.32-36-generic
root@jb-laptop:/home/jb# 

3。下载升级版本源码,供编译使用

下载链接:http://www.kernel.org/pub/linux/kernel/v2.6/

http://www.kernel.org

我下载的是

linux-2.6.38.8.tar.gz 

格式选择:gz和bz2

都可以,bz2的压缩程度高一点,只是解压缩命令不一样而已

4。解压缩源码

root@jb-laptop:/home/jb# tar -zxvf linux-2.6.38.8.tar.gz 

如果是bz2格式的话使用 tar -jxvf  linux.tar.bz2

5。复制源码到 目录/usr/src/下

root@jb-laptop:/home/jb# mv linux-2.6.38.8  /usr/src/

二、开始编译内核:

1。检查有无不正确的.o文件和依赖关系: make mrproper (其实这一步可以省略,因为是刚下载好的源码,一定是干净的;如果使用的是已经编译过的code,则需要做这一步)

2。配置Kernel选项:make menuconfig (这一步很重要,它决定了你可以个人定制化你的Kernel。当你使用menuconfig时,会有一些选择列出来) 主列表如下:

 

    General Setup: 常规的配置,比如Kernel config, CPU Group,Aduiting等等

    Loadable module support: 定制你要加载哪些modules

    Enable the block layer: 主要是块设备和大文件的设置

    Processor type and features: 处理器配置和定制化

    Power management options: 电源管理的定制化,比如Hibernate这样的

    Bus options: PCI总线的定制

    Executable file formats: 主要是设置ELF的配置

    Networking support: 定制网络选项,包括Wireless,Bluetooth和Network选项

    Device Drivers: 定制你需要加载的设备驱动

    Fireware Drivers: BIOS和EFI这样的固件驱动设置

    File System: 文件系统的设置,包括EXT3, EXT4, FAT, CD/DVD...等等N种

    Kernel hacking: 主要是设置Kernel debugging的,做内核调试会有用

    Security options: 安全选项

    Cryptographic API: 加密设置,包括MD5, SHA1, CRC等等N种加密算法的配置

    Virtualization: 虚拟化设置

    Library routines: 主要定制CRC校验的function

 

    上面是16大项,每一项都有N多小项,说真的这个里面每一项都够研究一阵子的。不过对内核编译而言,你可以全部采用默认选项(会延长编译时间)。设置好了menuconfig,保存退出。


如果出现下面的错误:

*** Unable to find the ncurses libraries or the
 *** required header files.
 *** 'make menuconfig' requires the ncurses libraries.
 *** 
 *** Install ncurses (ncurses-devel) and try again.
 *** 
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2

解决方案:

apt-get install libncurses5-dev

现在可以 make menuconfig 了

3。编译源码生成内核镜像:

make bzImage 

该命令首先编译生成vmlinux,然后压缩生成bzImage(路径是 /usr/src/kernel-version/arch/i386/boot/ )

可以查看有没有bzImage生成

4。编译内核模块

make modules

5。安装内核模块

make modules_install

内核模块编译好后需要安装到Linux系统的相应目录中才可以使用,使用“make modules_install”命令安装内核模块。“/lib/modules/”目录用于存放Linux系统中的内核模块,内核的各个版本都在该目录下建有子目录用于存放内核模块。

该命令首先在/lib/modules/中创建一个以内核发行号为名称的目录,然后根据内核配置生成需要的模块

6。生成新内核

make install

把编译好的内核放入/boot中,会把vmlinuz和System.map复制到/boot目录下,并建立相关的链接

7。完成最后的工作

有些linux版本在make install之后会自动生成initd.img和修改引导程序文件grub.cfg,但是ubuntu10.04并不会,所以就得我们自己来搞定啦

首先是生成initrd.img。

mkinitramfs 2.6.38.8  -o  /boot/initrd.img-2.6.38.8

如果系统提示没有安装mkinitramfs,那就apt-get install mkinitramfs

接着修改引导程序文件grub.cfg

update-grub2

尽量不要手动去修改grub.cfg文件,搞不好连电脑都启动不了

8。重启电脑

reboot

然后在grub引导界面上选择你的新内核

至此,所有的工作就搞定啦,体验你的新内核吧

三、参考链接:

System.map、vmlinuz、initrd.img的产生和作用 

http://dogking.chinaunix.com/space.php?uid=22896670&do=blog&id=189483

内核编译之vmlinuz vmlinux system.map initrd

http://hi.baidu.com/masterfoo/blog/item/3cdd88aa312b91bdca130ca4.html

Linux内核编译步骤(基于Ubuntu10.04+2.6.35.2 Kernel)

http://blog.csdn.net/zufeng_chen/article/details/5824544

 

 

ubuntu10.10下内核编译,解决开机启动出现Could not load /lib/modules/.../modules.dep的问题

http://blog.csdn.net/renclear/article/details/6461753

分享到:
评论
1 楼 doloveme 2013-06-09  
内核编译实验环境:Ubuntu 10.04 内核版本 2.6.32-36-generic



过程概述:

下载源码:下载链接:http://www.kernel.org/pub/linux/kernel/v2.6/

配置内核:make menuconfig

编译内核:make bzImage

编译内核模块:make modules

安装内核模块:make modules_install

安装内核:make install

完成最后遗留工作



一、内核编译的准备工作:

1。使用root用户,方便以后操作

jb@jb-laptop:~$ su
密码:
root@jb-laptop:/home/jb#
2。查看自己内核版本,以便选择新编译版本

root@jb-laptop:/home/jb# uname -r
2.6.32-36-generic
root@jb-laptop:/home/jb#

3。下载升级版本源码,供编译使用

下载链接:http://www.kernel.org/pub/linux/kernel/v2.6/

http://www.kernel.org

我下载的是

linux-2.6.38.8.tar.gz

格式选择:gz和bz2

都可以,bz2的压缩程度高一点,只是解压缩命令不一样而已

4。解压缩源码

root@jb-laptop:/home/jb# tar -zxvf linux-2.6.38.8.tar.gz

如果是bz2格式的话使用 tar -jxvf  linux.tar.bz2

5。复制源码到 目录/usr/src/下

root@jb-laptop:/home/jb# mv linux-2.6.38.8  /usr/src/

二、开始编译内核:

1。检查有无不正确的.o文件和依赖关系: make mrproper (其实这一步可以省略,因为是刚下载好的源码,一定是干净的;如果使用的是已经编译过的code,则需要做这一步)

2。配置Kernel选项:make menuconfig (这一步很重要,它决定了你可以个人定制化你的Kernel。当你使用menuconfig时,会有一些选择列出来) 主列表如下:



    General Setup: 常规的配置,比如Kernel config, CPU Group,Aduiting等等

    Loadable module support: 定制你要加载哪些modules

    Enable the block layer: 主要是块设备和大文件的设置

    Processor type and features: 处理器配置和定制化

    Power management options: 电源管理的定制化,比如Hibernate这样的

    Bus options: PCI总线的定制

    Executable file formats: 主要是设置ELF的配置

    Networking support: 定制网络选项,包括Wireless,Bluetooth和Network选项

    Device Drivers: 定制你需要加载的设备驱动

    Fireware Drivers: BIOS和EFI这样的固件驱动设置

    File System: 文件系统的设置,包括EXT3, EXT4, FAT, CD/DVD...等等N种

    Kernel hacking: 主要是设置Kernel debugging的,做内核调试会有用

    Security options: 安全选项

    Cryptographic API: 加密设置,包括MD5, SHA1, CRC等等N种加密算法的配置

    Virtualization: 虚拟化设置

    Library routines: 主要定制CRC校验的function



    上面是16大项,每一项都有N多小项,说真的这个里面每一项都够研究一阵子的。不过对内核编译而言,你可以全部采用默认选项(会延长编译时间)。设置好了menuconfig,保存退出。


如果出现下面的错误:
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2

解决方案:

apt-get install libncurses5-dev

现在可以 make menuconfig 了

3。编译源码生成内核镜像:

make bzImage

该命令首先编译生成vmlinux,然后压缩生成bzImage(路径是 /usr/src/kernel-version/arch/i386/boot/ )

可以查看有没有bzImage生成

4。编译内核模块

make modules

5。安装内核模块

make modules_install

内核模块编译好后需要安装到Linux系统的相应目录中才可以使用,使用“make modules_install”命令安装内核模块。“/lib/modules/”目录用于存放Linux系统中的内核模块,内核的各个版本都在该目录下建有子目录用于存放内核模块。

该命令首先在/lib/modules/中创建一个以内核发行号为名称的目录,然后根据内核配置生成需要的模块

6。生成新内核

make install

把编译好的内核放入/boot中,会把vmlinuz和System.map复制到/boot目录下,并建立相关的链接

7。完成最后的工作

有些linux版本在make install之后会自动生成initd.img和修改引导程序文件grub.cfg,但是ubuntu10.04并不会,所以就得我们自己来搞定啦

首先是生成initrd.img。

mkinitramfs 2.6.38.8  -o  /boot/initrd.img-2.6.38.8

如果系统提示没有安装mkinitramfs,那就apt-get install mkinitramfs

接着修改引导程序文件grub.cfg

update-grub2

尽量不要手动去修改grub.cfg文件,搞不好连电脑都启动不了

8。重启电脑

reboot

然后在grub引导界面上选择你的新内核

至此,所有的工作就搞定啦,体验你的新内核吧

三、参考链接:

System.map、vmlinuz、initrd.img的产生和作用

http://dogking.chinaunix.com/space.php?uid=22896670&do=blog&id=189483

内核编译之vmlinuz vmlinux system.map initrd

http://hi.baidu.com/masterfoo/blog/item/3cdd88aa312b91bdca130ca4.html

Linux内核编译步骤(基于Ubuntu10.04+2.6.35.2 Kernel)
http://blog.csdn.net/zufeng_chen/article/details/5824544

ubuntu10.10下内核编译,解决开机启动出现Could not load /lib/modules/.../modules.dep的问题
http://blog.csdn.net/renclear/article/details/6461753

相关推荐

Global site tag (gtag.js) - Google Analytics