Chinaunix首页 | 论坛 | 博客
  • 博客访问: 660944
  • 博文数量: 168
  • 博客积分: 2928
  • 博客等级: 中校
  • 技术积分: 1904
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-04 09:56
文章分类

全部博文(168)

文章存档

2010年(168)

我的朋友

分类: LINUX

2010-04-12 22:31:30

【linux 基础】内核编译

linux基础 2010-03-26 17:41:42 阅读86 评论0 字号:

第一部分:操作步骤.... 1

第二部分:删除编译好的内核.... 2

第三部分:重要内容的详细说明:.... 2

说明1:配置内核功能时 General setup. 2

编译内核的时候的 三个文件(vmlinuz System-map initrd.img)的简介: 3

说明2bzImagevmlinuxz. 3

说明3initrd.img. 3

说明4System-map. 3

说明5:创建initrd-xxx.img时都做了哪些动作呢?... 4

说明6grub 的设置... 4

说明7/boot 目录下文件的说明... 5

第四部分:linux-2.6.33.1内核的报错信息.... 5

第五部分:遗留问题:.... 6

如何更新部分内核?... 6

如何安装单个模块?... 6

内核补丁的使用详情?... 6

第六部分:参考文档:.... 6

第七部分:题外话:参照下面的脚本来编写ofbize的安装脚.... 6

 

正文:

当前版本:2.6.18-92.el5 i686

失败版本:linux-2.6.33.1

成功版本:linux-2.6.27.45

# vi /usr/src/kernels/linux-2.6.33.1/READMEE  <==编译内核前先读一下README

 

# uname -rm

2.6.18-92.el5 i686

下载linux-2.6.27.45.tar.bz2/usr/src/kernels/ 下载地址:

#cd /usr/src/kernels

# tar -jxf linux-2.6.27.45.tar.bz2 –C /usr/src/kernels/

# cd linux-2.6.33.1

# make mrproper           <==清理战场,尽在第一次编译前执行,以后执行make clean就可以了!

# make menuconfig    <==配置内核功能

# make clean             <==清除暂存档

# make bzImage          <==编译核心,持续了2小时

# make modules    <==编译模组

# make modules_install    <==模块会被安装到该目录下 /lib/modules/$(uname -r)/

# make install        <==自动方式安装内核,执行这个命令则后面的步骤全部省略!

或者手动方式

# cp /usr/src/kernels/linux-2.6.33.1/arch/x86/boot/bzImage \

> /boot/vmlinuz-2.6.33.1bkeep  <==实际核心

# cp /usr/src/kernels/linux-2.6.33.1/.config \

> /boot/config-2.6.33.1bkeep   <==建议设定档也复制备份

 

# mkinitrd -v /boot/initrd-2.6.33.1bkeep.img  2.6.33.1bkeep   <==创建initrd

#vi /boot/grub/menu.lst    <==编辑grub的配置文件

title Red Hat Enterprise Linux Server (2.6.27)

kernel (hd0,0)/vmlinuz-2.6.27 ro root=LABEL=/

initrd /initrd-2.6.27.img

title Red Hat Enterprise Linux Server (2.6.33.1)

        root (hd0,0)

        kernel /vmlinuz-2.6.33.1 ro root=LABEL=/ rhgb quiet

        initrd /initrd-2.6.33.1.img

 

如果系统不稳定的话,那么我们怎么样的去删除我们编译的内核的呢

处理的步骤 有以下三步:

第一步: /usr/src/kernels/linux-2.6.33.1目录删除 ---rm -r -f /usr/src/kernels/linux-2.6.33.1

第二步: 删除/lib/modules/linux-2.6.33.1bkeep目录 rm -r -f /lib/modules/linux-2.6.33.1bkeep

第三步: 删除 /boot/menu.lst文件中的 对应的title kernel initrd部分

:配置内核功能时 General setup

General setup: Linux 最相关的程序互动、核心版本说明、是否使用发展中程式码等资讯都在这里设定的

# make menuconfig  ===> General setup ===>

[ ] Prompt for development and/or incomplete code/drivers

    # 这个建议不要选择,因为我们不是核心专家,不需要使用发展中或不完整的程式码!

(vbird)  Local version - append to kernel release

[*] Automatically append version information to the version string

    # 我希望我的核心版本成为 2.6.30.3.vbird ,那这里可以就这样设定!

    Kernel compression mode (Bzip2)  --->

    # 建议选择成为 Bzip2 即可,因为压缩比较佳!

[*] Support for paging of anonymous memory (swap)

    # 任何人均可存取 swap 是合理的!所以这里务必要勾选!

[*] System V IPC

    # IPC Inter Process Communication (程序通讯) 缩写,与程序沟通有关,要选!

[*] BSD Process Accounting

[ ]   BSD Process Accounting version 3 file format

    # 与标准 Unix (BSD) 的程序支援有关,但不要支援 version 3 ,可能有相容性问题

[ ] Export task/process statistics through netlink (EXPERIMENTAL)

    # 这个额外的进阶选项可以将他取消的!

[*] Auditing support

[*]   Enable system-call auditing support

    # 上面这两个是额外核心功能 ( SELinux) 载入时所需要的设定!务必选择

    RCU Subsystem  --->

      RCU Implementation (Classic RCU)  --->

    # 选择标准 RCU 即可,不需要使用大量 CPU 的整合功能。

Kernel .config support

[ ]   Enable access to .config through /proc/config.gz (NEW)

    # .config 这个核心功能列表可以写入实际的核心档案中!

(17) Kernel log buffer size (16 => 64KB, 17 => 128KB)

[ ] Control Group support (NEW)  --->

    # 整合 CPU 或分离装置的功能,属于进阶设定,我们先不要使用这功能。

[*] Create deprecated sysfs layout for older userspace tools (NEW)

    # 如果使用支援旧式装置,如 /sys/devices 者,这里要勾选!但如果是 2008

    # 年后的 distribution ,这里可能需要取消喔! CentOS 5.x 要选的!

-*- Kernel->user space relay support (formerly relayfs)

-*- Namespaces support

[*]   UTS namespace (NEW)

[*]   IPC namespace (NEW)

    # 使用 uname 时,会输出较多的资讯,所以可以尝试选择看看。

[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support

()    Initramfs source file(s)

    # 这是一定要的!因为要支援开机时载入 initail RAM disk 嘛!

[*] Optimize for size 

    # 可以减低核心的档案大小,其实是 gcc 参数使用 -Os 而不是 -O2

[ ] Configure standard kernel features (for small systems)  --->

    # 给嵌入式系统使用的,我们用 PC ,所以这里不选。

[ ] Strip assembler-generated symbols during link (NEW)

[ ] Disable heap randomization (NEW)

    # 2000 年后推出的版本,可以取消这个项目!

    Choose SLAB allocator (SLAB)  --->

[*] Profiling support (EXPERIMENTAL)

[ ] Activate markers (NEW)

OProfile system profiling (EXPERIMENTAL)

[ ]   OProfile AMD IBS support (EXPERIMENTAL) (NEW)

[*] Kprobes

 

三个文件(vmlinuz System-map initrd.img)的简介:

bzImagevmlinuxz

vmlinuz System-map initrd.img这三个文件是 linux内核编译完成后我们需要进行手动制作的或者是使用make install 进行自动安装的

 

vmlinuz是可引导的、压缩的内核。“vm”代表“Virtual MemoryLinux能够使用硬盘空间作为虚拟内存,因此得名“vm”。vmlinuz是可执行的Linux内核,它位于/boot/vmlinuz,它一般是一个软链接。

   vmlinuz的建立有两种方式。一是编译内核时通过“make zImage”创建,然后通过:“cp /usr/src/linux-2.4/arch/i386/linux/boot/zImage /boot/vmlinuz”产生。zImage适用于小内核的情况,它的存在是为了向后的兼容性。二是内核编译时通过命令make bzImage创建,然后通过:“cp /usr/src/linux-2.4/arch/i386/linux/boot/bzImage /boot/vmlinuz”产生。bzImage是压缩的内核映像,需要注意,bzImage不是用bzip2压缩的,bzImage中的bz容易引起 误解,bz表示“big zImage”。 bzImage中的b是“big”意思。

 

initrd.img

initrd.img 这个文件的作用就是在加载完毕内核的信息信息之后,会去再内存条中的保护区域内模拟出一个 linux 根目录的简图,他是为了处理一些内核中没有built-in 驱动程序,关于这个文件的最主要的思想就是 模组和 挂在,在我们的linux kernel载入的最后一步中有一个 root=LABEL=/ rhgb quiet 这个参数其实就是一个承上启下的作用, 就是在为initrd.ing 初始化做好准备,比如我们使用的一些scsi驱动程序就是砸initrd.img中进行释放的 ---这些只是为了让你理解什么是initrd.img文件

但是如果说的术语一点的话,那么就 应该是这样的

initrd-x.x.x.img

   initrd是“initial ramdisk”的简写。initrd一般被用来临时的引导硬件到实际内核vmlinuz能够接管并继续引导的状态。initrd-2.4.7- 10.img主要是用于加载ext3等文件系统及scsi设备的驱动。比如,使用的是scsi硬盘,而内核vmlinuz中并没有这个scsi硬件的驱 动,那么在装入scsi模块之前,内核不能加载根文件系统,但scsi模块存储在根文件系统的/lib/modules下。为了解决这个问题,可以引导一 个能够读实际内核的initrd内核并用initrd修正scsi引导问题。----看看就好,学习最主要的是要能够理解

 

System-map

System-map 这个文件其实就是一个映射表,看到map其实就可以想到是映射表了,但是中电视在映射什么 其实也就是计算机能够是别的 电流信号和我们的人类能够识别的 那么英文啊 什么的

说的通俗一点就是这样 ----

比较尖酸的术语的话就是这样的

   System.map

  System.map是一个特定内核的内核符号表。它是你当前运行的内核的System.map的链接。

  内核符号表是怎么创建的呢? System.map是由“nm vmlinux”产生并且不相关的符号被滤出。对于本文中的例子,编译内核时,System.map创建在/usr/src/linux-2.4/System.map。像下面这样:

  nm /boot/vmlinux-2.4.7-10 > System.map

  下面几行来自/usr/src/linux-2.4/Makefile

  nm vmlinux | grep -v '\(compiled\)\|\(\.o$$\)\|

  \( [aUw] \)\|\(\.\.ng$$\)\|\(LASH[RL]DI\)' | sort > System.map

  然后复制到/boot:

  cp /usr/src/linux/System.map /boot/System.map-2.4.7-10

  在进行程序设计时,会命名一些变量名或函数名之类的符号。Linux内核是一个很复杂的代码块,有许许多多的全局符号。

  Linux内核不使用符号名,而是通过变量或函数的地址来识别变量或函数名。比如不是使用size_t BytesRead这样的符号,而是像c0343f20这样引用这个变量。

对于使用计算机的人来说,更喜欢使用那些像size_t BytesRead这样的名字,而不喜欢像c0343f20这样的名字。

内核主要是用c写的,所以编译器/连接器允许我们编码时使用符号名,当内核运行时使用地址。

  然而,在有的情况下,我们需要知道符号的地址,或者需要知道地址对应的符号。这由符号表来完成,符号表是所有符号连同它们的地址的列表。变量名checkCPUtype在内核地址c01000a5

 

:创建initrd-xxx.img时都做了哪些动作呢?

# mkinitrd -v /boot/initrd-2.6.33.1.img 2.6.33.1

Creating initramfs

Looking for deps of module ehci-hcd

Looking for deps of module ohci-hcd

Looking for deps of module uhci-hcd

Looking for deps of module ext3: jbd

Looking for deps of module jbd

Found root device sda3 for LABEL=/

copy from `/lib/modules/2.6.33.1/kernel/fs/ext3/ext3.ko' [elf32-i386] to `/tmp/initrd.Tq2932/lib/ext3.ko' [elf32-i386]

copy from `/lib/modules/2.6.33.1/kernel/drivers/scsi/scsi_mod.ko' [elf32-i386] to `/tmp/initrd.Tq2932/lib/scsi_mod.ko' [elf32-i386]

....省略部分文字....

Adding module mptspi

Adding module libata

Adding module ata_piix

# cd /lib/modules/2.6.33.1bkeep/

# ls

build            modules.ccwmap       modules.isapnpmap  modules.seriomap

kernel           modules.dep          modules.ofmap      modules.symbols

modules.alias    modules.ieee1394map  modules.order      modules.usbmap

modules.builtin  modules.inputmap     modules.pcimap     source

 

grub 的设置

--概念

# vim /boot/grub/menu.lst

default=0     <==预设开机选项,使用第 1 个开机选单 (title)

timeout=5     <== 5 秒内未动键盘,使用预设选单开机

splashimage=(hd0,0)/grub/splash.xpm.gz <==背景图示所在的档案

hiddenmenu    <==读秒期间是否显示出完整的选单画面(预设隐藏)

title CentOS (2.6.18-92.el5)    <==第一个选单的内容

        root (hd0,0)

        kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/1 rhgb quiet

        initrd /initrd-2.6.18-92.el5.img

案例

[root@192_168_254_222 2.6.33.1]# vim /boot/grub/menu.lst

# grub.conf generated by anaconda

#boot=/dev/sda

default=1

timeout=5

splashimage=(hd0,0)/grub/splash.xpm.gz

hiddenmenu

title Red Hat Enterprise Linux Server (2.6.33.1)         <==已经有了!

        root (hd0,0)

        kernel /vmlinuz-2.6.33.1 ro root=LABEL=/ rhgb quiet

        initrd /initrd-2.6.33.1.img

title Red Hat Enterprise Linux Server (2.6.18-92.el5)

        root (hd0,0)

        kernel /vmlinuz-2.6.18-92.el5 ro root=LABEL=/ rhgb quiet

        initrd /initrd-2.6.18-92.el5.img

 

/boot 目录下文件的说明

[root@www ~]# ls --format=single-column -F /boot
config-2.6.18-92.el5      <==此版本核心被编译时选择的功能与模组设定档
grub/                     <==就是开机管理程式 grub 相关资料目录
initrd-2.6.18-92.el5.img  <==虚拟档案系统档!
System.map-2.6.18-92.el5  <==核心功能放置到记忆体位址的对应表
vmlinuz-2.6.18-92.el5     <==就是核心档案啦!最重要者!

 

 

说明8make bzImage 输出信息

# make bzImage          <==编译核心,持续了2小时

最后注意到,下达了 make bzImage 后,最终的结果应该会像这样:

BUILD   arch/x86/boot/bzImage    <==生产文件的路径

Root device is (8, 3)

Setup is 13944 bytes (padded to 14336 bytes).

System is 2365 kB

CRC d5778175

Kernel: arch/x86/boot/bzImage is ready  (#1)

 

2.6.33.1内核的报错信息

这个错误没有解决!!

当一切准备就绪后,重启系统,选择使用新内核时报错了!

mount: could not find filesystem '/dev/root'

setuproot: moving /dev/failed: no such file or directory

setuproot: error mounting /proc: No such file or directory.

setuproot: error mounting /sys: No such file or directory.

switchroot: mount failed: No such file or directory.

 

Kernel panic - not syncing: Attempted to kill init!

 

解决办法:

arm-linux-gcc 4.00以上的编译器做出都 文件系统老是报这个错

而用rm-linux-gcc 3.xx 版本都都不会,来看一下内核的配置

原来问题在这里

 

Kernel Features --->

            [*] Use the ARM EABI to compile the kernel                  

[*]   Allow old ABI binaries to run with this kernel (EXPERIMENTA)

把这个选上就可以了

 

http://hi.baidu.com/linuxnature/blog/item/4f96bbec8fda954679f05551.html

 

 

VBIRD

linux 基础】版本号 & Patchhttp://bkeep.blog.163.com/blog/static/12341429020102265035865/

Linux基础】模块 & 核心:http://bkeep.blog.163.com/blog/static/123414290201022645941510/

 

的安装脚本

# make install

sh /usr/src/kernels/linux-2.6.27.45/arch/x86/boot/install.sh 2.6.27.45bkeep arch/x86/boot/bzImage System.map "/boot"

 

#vi /usr/src/kernels/linux-2.6.27.45/arch/x86/boot/install.sh

阅读(1561) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~