linux 内核编译安装(CentOS5)
2011-04-13 17:09
489 查看
一、系统环境。
1、CentOS 5 在虚拟机上安装
2、下载新内核源代码,版本:linux-2.6.35-rc1
二、安装过程
1、解压源代码,随便到那个目录,进入解压后的源代码目录,我的为~/linux_kernal/linux-2.6.35-rc1
2、make mrproper :这个目的是清除原先此目录下残留的.config和.o
3、make clean
注:如果是第一次编译,可以省略2、3步骤。
4、配置。
第一种方式:make defconfig:默认配置,听说是linus的配置哦,呵呵。
make allnoconfig : 除必须的选项外, 其它选项一律不选. (常用于嵌入式系统)
第二种方式:make menuconfig:图形界面方式配置,系统将提示你需要安装ncurses-devel包。
yum install ncurses-devel
在第二种方式下,可以使用当前的系统的核心配置(/usr/src/kernels/2.6.18-194.el5-i686/.config)
通过menuconfig菜单里的Load an Alternate Configuration File加载
我的做法是:
(1)cp /usr/src/kernels/2.6.18-194.el5-i686/.config .
(2)make menuconfig-->Load an Alternate Configuration File-->选择.config-->Save an Alternate Configuration File
(3)vim .config
(4)编译时修改.config文件中的“CONFIG_SYSFS_DEPRECATED_V2”,默认该选项为not set,被注释掉的,将其改为y。即修改为“CONFIG_SYSFS_DEPRECATED_V2=y”。
可以避免安装完内核后,出现如下错误,导致无法启动:
mount: could not find filesystem ‘/dev/root’
5、make dep:依赖关系编译
6、make bzImage :编译核心,bz,表示压缩。也可以zImage,但要确保核心较小。
# make bzImage
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
Kernel: arch/x86/boot/bzImage is ready (#2)
提示已经放到了当前目录的arch/x86/boot/bzImage里
7、make modules :编译模块,模块的多少取决于你的配置
8、make modules_install:安装module,这将把上一步构建出来的内核放入一个模块子目录中:/lib/modules/your_kernel_version
9、make install:自动安装。
(1)默认会把rch/x86/boot/bzImage复制到/boot/vmlinuz版本号,例如:vmlinuz-2.6.35-rc1,如果已经安装过同一个版本号的时候,将把前一个重命名为vmlinuz-2.6.35-rc1.old
(2)自动在/boot/grub/grub.conf里加上了启动项,例如:
cat /boot/grub/grub.conf
# 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/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.35-rc1)
root (hd0,0)
kernel /vmlinuz-2.6.35-rc1 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.35-rc1.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.el5.img
(3)建议要把hidde menu注释掉
如此,就完成了内核的编译,我已经按这种方式成功安装。
补充:
.config配置文件(转载自《编译 Linux2.6 内核总结》)
在内核树的根目录中,有一个.config文件,它记录了内核的配置选项,可直接对它进行修改,再运行(若.config不存在,对内核进行配置后会生成它,这种情况下当然不能开始就运行oldconfig). 实际上, 如果你手头有合适的 .config 文件, 可以运行 make oldconfig 直接按 .config 的内容来配置
$ sudo make oldconfig
对内核的配置都是围绕 .config 来展开的. 即便开始 .config 文件不存在, 进行配置后会创造它.
其实可以直接在menuconfig中加载已有的配置文件, 不要将它改名为.config. 否则完成配置, 退出menuconfig时会提示你运行 make mrproper. 上面提到的方法只是比较适合于oldconfig!
1、CentOS 5 在虚拟机上安装
2、下载新内核源代码,版本:linux-2.6.35-rc1
二、安装过程
1、解压源代码,随便到那个目录,进入解压后的源代码目录,我的为~/linux_kernal/linux-2.6.35-rc1
2、make mrproper :这个目的是清除原先此目录下残留的.config和.o
3、make clean
注:如果是第一次编译,可以省略2、3步骤。
4、配置。
第一种方式:make defconfig:默认配置,听说是linus的配置哦,呵呵。
make allnoconfig : 除必须的选项外, 其它选项一律不选. (常用于嵌入式系统)
第二种方式:make menuconfig:图形界面方式配置,系统将提示你需要安装ncurses-devel包。
yum install ncurses-devel
在第二种方式下,可以使用当前的系统的核心配置(/usr/src/kernels/2.6.18-194.el5-i686/.config)
通过menuconfig菜单里的Load an Alternate Configuration File加载
我的做法是:
(1)cp /usr/src/kernels/2.6.18-194.el5-i686/.config .
(2)make menuconfig-->Load an Alternate Configuration File-->选择.config-->Save an Alternate Configuration File
(3)vim .config
(4)编译时修改.config文件中的“CONFIG_SYSFS_DEPRECATED_V2”,默认该选项为not set,被注释掉的,将其改为y。即修改为“CONFIG_SYSFS_DEPRECATED_V2=y”。
可以避免安装完内核后,出现如下错误,导致无法启动:
mount: could not find filesystem ‘/dev/root’
5、make dep:依赖关系编译
6、make bzImage :编译核心,bz,表示压缩。也可以zImage,但要确保核心较小。
# make bzImage
CHK include/linux/version.h
CHK include/generated/utsrelease.h
CALL scripts/checksyscalls.sh
CHK include/generated/compile.h
Kernel: arch/x86/boot/bzImage is ready (#2)
提示已经放到了当前目录的arch/x86/boot/bzImage里
7、make modules :编译模块,模块的多少取决于你的配置
8、make modules_install:安装module,这将把上一步构建出来的内核放入一个模块子目录中:/lib/modules/your_kernel_version
9、make install:自动安装。
(1)默认会把rch/x86/boot/bzImage复制到/boot/vmlinuz版本号,例如:vmlinuz-2.6.35-rc1,如果已经安装过同一个版本号的时候,将把前一个重命名为vmlinuz-2.6.35-rc1.old
(2)自动在/boot/grub/grub.conf里加上了启动项,例如:
cat /boot/grub/grub.conf
# 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/sda2
# initrd /initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.35-rc1)
root (hd0,0)
kernel /vmlinuz-2.6.35-rc1 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.35-rc1.img
title CentOS (2.6.18-194.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-194.el5 ro root=LABEL=/ rhgb quiet
initrd /initrd-2.6.18-194.el5.img
(3)建议要把hidde menu注释掉
如此,就完成了内核的编译,我已经按这种方式成功安装。
补充:
.config配置文件(转载自《编译 Linux2.6 内核总结》)
在内核树的根目录中,有一个.config文件,它记录了内核的配置选项,可直接对它进行修改,再运行(若.config不存在,对内核进行配置后会生成它,这种情况下当然不能开始就运行oldconfig). 实际上, 如果你手头有合适的 .config 文件, 可以运行 make oldconfig 直接按 .config 的内容来配置
$ sudo make oldconfig
对内核的配置都是围绕 .config 来展开的. 即便开始 .config 文件不存在, 进行配置后会创造它.
其实可以直接在menuconfig中加载已有的配置文件, 不要将它改名为.config. 否则完成配置, 退出menuconfig时会提示你运行 make mrproper. 上面提到的方法只是比较适合于oldconfig!
相关文章推荐
- Linux-3.10.1内核编译安装
- Linux内核分析(一)---linux体系简介|内核源码简介|内核配置编译安装
- ubuntu 10.04 编译安装最新版本linux-2.6.34内核
- Linux 2.6内核编译安装全景体验(下)
- CentOS 7 下编译安装 Linux 4.14 内核
- LKU:一套在 Ubuntu/LinuxMint 上编译、安装和更新最新内核的 Shell 脚本
- [Linux] 内核编译安装
- [Kernel] Linux 4.10.0+ 下编译安装内核模块(Hello World为例)
- Linux 内核编译安装
- linux kernel and driver-编译安装内核
- LKU:一套在 Ubuntu/LinuxMint 上编译、安装和更新最新内核的 Shell 脚本
- Linux 内核编译安装
- 嵌入式开发实作(Linux内核编译及安装)
- Linux内核编译与安装-基于linux-2.6.30.6内核
- Linux-4.1.6 内核编译安装(ubuntu)
- VirtualBox虚拟机安装RedHat7.3编译Linux0.01内核
- Ubuntu 10.04 编译安装最新版本Linux-2.6.34内核
- linux 2.6.3x内核源码编译和安装
- Linux 内核学习(一) - 内核编译安装
- 编译和安装linux内核2.6.x,一个简单的内核驱动测试