Linux 2.6.34内核编译

Linux 2.6.34内核编译,第1张

Linux-2.6.34内核编译指南

2010-06-11 22:45 作者:玮琦 页面排版:玮琦

对linux内核的编译来说是每个编译者都必须掌握的一个阶段,但是编译内核是有相对一些难度的,也许你可能不知如何着手,请不必为此烦恼或者放弃,经过一些归纳和总结我编写了比较详细的步骤,从而可以为广大的爱好者以及新手能带来更好的帮助和深入的了解

一、下载内核

到www.kernel.org 下载新内核到 /usr/src

下载建议最好下载比当前已安装版本高的内核我下载的是 linux-2.6.34.tar.bz2( 原来的内核是 2.6.18-128.e15-i686)

★ 我察看当前内核的版本

[root@localhost~]#uname -a

Linux localhost.localdomain 2.6.18-128.e15-i686 #1 SMP Tue Jun 8 10:30:55 CST 2010 i686 i686 i386 GNU/Linux

然后将其解压到/usr/src目录下,使用下面的命令解压得到linux-2.6.34:

[root@localhost~]#tar -jxvf linux-2.6.34.tar.bz2

[root@localhost~]#bzip2 -d linux-2.6.34.tar.bz2

如果所下载的是.tar.gz(.tgz)文件,请使用下面的命令:

[root@localhost~]#tar -zxvf linux-2.6.34.tar.gz

为了不把原来的目录覆盖掉所以呢在当前路径下做一个链接为linux:

[root@localhost~]#ln -s /usr/src/linux-2.6.34 /usr/src/linux

二、配置内核

[root@localhost~]#make clean 清除原有不需要的模块和文件(垃息)

[root@localhost~]#make mrproper 清理源代码数

[root@localhost~]#make menuconfig 基于ncurse的图形配置界面,可以在文本下以菜单方式,进行配置。

Load an Alternate Configuration File,导入.config文件

注:内核配置有两种方法,一种是直接置入内核* ;另一种是编成模块M ;两种方法各有优点;直接编入内核的,比如设备的启动,不再需要加载模块的这一过程了;而编译成模块,则需要加载设备的内核支持的模块;但直接把所有的东西都编入内核也不是可行的,内核体积会变大,系统负载也会过重。我们编内核时最好把极为重要的编入内核;其它的如果您不明白的,最好用默认.

移动键盘上下左右键,按Enter 进入一个目录。把指针移动到Exit就退出当前目录到上级目录;

下面图形界面蓝色区域为选择区:

General setup -→

[*] Enable loadable module support --->

-*- Enable the block layer -→

Processor type and features --->

Power management and ACPI options --->

Bus options (PCI etc.) --->

Executable file formats / Emulations --->

-*- Networking support --->

Device Drivers -→

Firmware Drivers --->

File systems --->

Kernel hacking -→

Security options --->

-*- Cryptographic API -→

[*] Virtualization -→

Library routines --->

---

Load an Alternate Configuration File

Save an Alternate Configuration File

<Select><Exit ><Help >

修改完毕选择Save an Alternate Configuration File,然后退出配置

[root@localhost~]#cp ../kernels/2.6.18-128.e15-i686/.config /usr/src

★ 编辑配置文件.config

[root@localhost~]#vim .config

找到105行的"#CONFIG_SYSFS_DEPRECATED is not set"改为"CONFIG_SYSFS_DEPRECATED=y" 保存

假如不修改该行,在升级重新启动后会报如下的错,导致启动失败

Volume group "VolGroup00" not found

Unalbe to access resume device (/dev/VolGroup00/LogVol00)

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!

★ 编译开始,大概需要半个小时到一个小时的时间自己可以倒杯凉茶耐心候。

[root@localhost~]#make

★ 编译外挂模块和需要加载的模块安装

[root@localhost~]#make modules &&make modules_install

这时候会出现3个警告[2]

WARNING: No module dm-mem-cache found for kernel 2.6.34, continuing anyway

WARNING: No module dm-message found for kernel 2.6.34, continuing anyway

WARNING: No module dm-raid45 found for kernel 2.6.34, continuing anyway

经过测试,这3个警告不会影响内核的升级

★ 编译系统内核且生成新的内核文件

[root@localhost~]#make bzImage

[root@localhost~]#cp arch/x86/boot/bzImage /boot/vmlinuz-2.6.34

[root@localhost~]#mkinitrd /boot/initrd-2.6.34.img 2.6.34

[root@localhost~]# cp /boot/initrd-2.6.34.img /tmp

[root@localhost~]#cd /tmp/

[root@localhost~]#ls

[root@localhost~]#initrd-2.6.34.img

[root@localhost~]#mkdir newinitrd

[root@localhost~]# cd newinitrd/

[root@localhost~]# zcat ../initrd-2.6.34.img |cpio -i

[root@localhost~]# ls

bin dev etc init lib proc sbin sys sysroot

[root@localhost~]#vim init

★ 删掉重复的两行,有些情况下是没有就不要执行

echo "Loading dm-region-hash.ko module"

insmod /lib/dm-region-hash.ko

echo "Loading dm-region-hash.ko module"

insmod /lib/dm-region-hash.ko

★ 重新打包initrd

[root@localhost~]# find .|cpio -c -o >../initrd

[root@localhost~]# cd ..

[root@localhost~]# gzip -9 <initrd >initrd-2.6.34.img

★ 将initrd重新复制到/boot目录下

[root@localhost~]#cp initrd-2.6.34.img /boot

★ 给 /boot/grub/grub.conf中添加一个新的启动项,

[root@localhost~]#vim /boot/grup/grup.conf

如我的 grub.conf 增加了

如下一段文字

title Red Hat(2.6.34)

root (hd0,5)

kernel /boot/vmlinuz-2.6.34 ro root=LABEL=/ rhgb quiet

initrd /boot/initrd-2.6.34.img

三、重新起动

[root@localhost~]# reboot

★ 启动成功后查看当前内核版本号

[root@localhost~]#uname -r

2.6.34

四、待解决的问题

★ Iptables启动失败

*** 作系统启动过程中出现下面的错误信息:

Applying ip6tables firewall rules: ip6tables-restore v1.3.5: ip6tables-restore:unable to initalizetable 'filter'

Error accurred at line: 3

Try "ip6tables-restore -h' or 'ip6tables-restore --help' for more information.

Applying iptables firewall rules: iptables-restore v1.3.5: iptables-restore:unable to initalizetable 'filter'

Error accurred at line: 3

Try "iptables-restore -h' or 'iptables-restore --help' for more information.

启动后尝试手动启动防火墙:

[root@localhost~]#service iptables status

防火墙已停

[root@localhost~]#service iptables start

正在卸载 Iiptables 模块:[确定]

应用 iptables 防火墙规则:iptables-restore v1.3.5: iptables-restore: unable to initializetable 'filter'

Error occurred at line: 3

Try `iptables-restore -h' or 'iptables-restore --help' for more information.

[失败]

★ Hidd(Bluetooth HID daemon)启动失败

Starting hidd: Can't open HIDP control socket: Address family not supported by protocol [FAILED]

[root@localhost~]# service hidd status

hidd 已死,但是 subsys 被锁

[root@localhost~]# service hidd start

正在启动 hidd:Can't open HIDP control socket: Address family not supported by protocol

需要准备的材料分别是:电脑、linux连接工具。

1、首先连接上linux主机,进入等待输入指令的linux命令行状态。

2、输入:bash --version,按回车。

3、此时打印出的“version 4.2.46(1)-release”就是该shell的版本。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7422019.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-05
下一篇 2023-04-05

发表评论

登录后才能评论

评论列表(0条)

保存