免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3557 | 回复: 0
打印 上一主题 下一主题

Fedora下内核编译 [第十五期] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-07 22:51 |只看该作者 |倒序浏览
Fedora下内核编译
ChinaUnix网友:JsuFcz
第一步:去官方下载最新的内核源码包
官方网址:www.kernel.org
当前最新版本:2.6.31,下载网址:http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2
您可以使用 wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2下载
第二步:解压源码包(这里有些人说要将源码解压到/usr/src目录下,其实是不正确的,你可以解
压到任何目录)
cd ~
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.31.tar.bz2
tar -jxvf linux-2.6.31.tar.bz2

第三步:配置选项
cd linux-2.6.31
cp /boot/config-`uname -r` .config
make mrproper (
删除上次编译产生的垃圾,初次编译不需要)
make menuconfig (
启动内核选项配置界面)
说明一下,make menuconfig会寻找linux-2.6.31目录下的.config配置文件,如果找不到,则使用与
CPU
相关的config文件作为默认的配置。当然,我们也可以拷贝当前系统的配置作为对照,如
cp /boot/config-`uname -r` .config (.config
是隐藏文件 ls -a查看)
注意:如果是同版本的内核编译,还需要备份下当前模块
cd /lib/modules
mv 2.6.31 2.6.31_old

指定内核识别码
vim Makefile
EXTRAVERSION = .custom-1 (
4)
第四步(1)传统方式编译
make all (2.6
以前版本需要手工运行如下命令)
(
# make dep
      <==建立相依的属性关系!
# make clean
       <==将旧的资料去除掉!
# make bzImage
      <==开始编译核心!这个核心是经过压缩的 (30分钟左右)
# make modules
      <==开始编译模块!这个动作视您刚刚编译的模块数量!(1小时左右)
)
make modules_install (
安装模块到/lib/modules/2.6.31)
make install (
系统将会把vmlinuzSystem.map复制到/boot目录下同时修改grub /boot/grub/menu.lst2.6以前版本需要手动拷贝vmlinuzSystem.map)
第四步(2)RPM方式编译,会产生RPM包,方便提供给别人使用
make rpm
编译完成之后,在~/rpmbuild /SRPMS/目录发现一个新的src.rpm, 比如. SRPMS/kernel-2.6.31.custom-1.src.rpm, 内核rpm包位于~/rpmbuild/RPMS/i386/ (RPMS/i586/, RPMS/i686/, . 看你的平台类型). 比如. RPMS/i386/kernel-2.6.31.custom-1.i386.rpm. 可以看到内核识别码已添加到软件包的名字中.
安装新内核
现在去新的rpm内核包存在的目录(基于你的平台类型, 比如. ~/rpmbuild/RPMS/i386/)安装rpm
cd ~/rpmbuild/RPMS/i386
rpm -ivh kernel-2.6.31.custom-1.i386.rpm

(现在你甚至能够拷贝到其它的Fedora系统, 通过上面的方式安装. 你将不再需要编译内核.)
接下来我们为新内核创建一个ramdisk, 否则系统将不能引导新内核:
mkinitrd /boot/initrd-2.6.31.custom-1.img 2.6.31.custom-1

然后编辑/boot/grub/menu.lst文件, 看一下你系统上已经存在(正在工作的)引导内核信息, 拷贝其中的一个实例, 替换为你新的内核和ramdisk:
vim /boot/grub/menu.lst

比如, 我的menu.lst, 在我添加新的内核信息前的情况:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu

title Fedora Core (2.6.18-1.2798.fc6)
root (hd0,0)
kernel /vmlinuz-2.6.18-1.2798.fc6 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-1.2798.fc6.img

修改后的情况:
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
# initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu

title Fedora Core (2.6.18-custom-2.6.18.2)
root (hd0,0)
kernel /vmlinuz-2.6.18-custom-2.6.18.2 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.18-custom-2.6.18.2.img

title Fedora Core (2.6.31.custom-1)
root (hd0,0)
kernel /vmlinuz-2.6.31.custom-1 ro root=/dev/VolGroup00/LogVol00
initrd /initrd-2.6.31.custom-1.img

(你可以通过下面命令发现正确的vmlinuzinitrd文件:
ls -l /boot
)

第五步:重启系统,在Grub引导菜单中,选择linux-2.6.31.custom-1
Reboot
,重启之后,大功告成,你的新内核已经安装好了。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP