test Blog
Happy living

ubuntu编译内核实例

老鼠 posted @ 2009年4月01日 00:24 in linux with tags ubuntu 内核 编译 , 3796 阅读

第一步 安装必要的工具

首先要安装必要的包。
包有:libncurses5-devmenuconfig需要的)和essential
sudo apt-get install build-essential kernel-package(内核打包deb的可以不用装手动安装)
sudo apt-get install make
sudo apt-get install gcc
另外,查看系统是否有这样的两个命令
mkinitramfs mkisofs
这两个工具在编译内核时用来生成 *.img文件的。如果没有就需安装。

第二步 下载内核

www.kernel.org下载新内核到/usr/src
我下载的是linux-2.6.24.tar.gz(原来的内核是2.6.20-15-generic)

第三步 编译前的准备

察看当前内核的版本
helight@helight-desktop:/$ uname -a

Linux helight-desktop 2.6.20-15-generic #1 SMP Mon Aug 25 17:32:09 UTC 2008 i686 GNU/Linux

helight@helight-desktop:/$

 

建议最好下载比当前已安装版本高的内核

解压linux-2.6.24.tar.gzlinux-2.6.24
cd /usr/src

sudo tar zxvf linux-2.6.24.tar

cd linux-2.6.24/


第四步 开始编译

cd /usr/src/linux-2.6.24 //以下所有的工作都在/usr/src/linux-2.6.24下完成
sudo make menuconfig //
menuconfig的话还需要Ncurses,或者用
sudo make xconfig

 

sudo make menuconfig //一般是用menuconfig

 

配置完以后保存(系统中保存的一份内核配置文件是在/usr/src/linux-2.6.24下名为.config,你也可以自己在别的地方另存一份)
也可以cp原来在/boot目录下的config-2.6.xx 到当前目录下,在make menuconfig是使用这个配置文件。
sudo make dep     //
也许系统会提示现在不必要进行make dep,那就下一步 2.6.24的我编译就没有使用过。
sudo make clean //
清除旧数据 ,新解压的内核源码就不需要这一步了

sudo make –j2 可以分两个线程来进行编译工作,不过我用make –j4 却发现系统有9make进程在工作。所以这个参数未必起作用。
sudo make bzImage //
编译内核,将保存到/usr/src/linux-2.6.24/arch/i386/boot/
sudo make modules //
编译模块
sudo make modules_install //
安装模块把编译好的模块安装到系统的/lib/modules下

sudo mkinitramfs -o /boot/initrd-2.6.24.img 2.6.24 #根据安装好的模块做镜像后面的参数号是指你的版本号,也就是modules下你安装的文件夹名

此时可能提示找不到这样的一个文件夹“/lib/firmware/2.6.24”,你需要手工创建一个这样的文件夹。

sudo mkdir /lib/firmware/2.6.24
sudo make install //
安装内核

#以上的几个步骤不能乱来要搞清楚各个步骤的实质内容   编译(包括内核和模块)->安装模块->做模块镜像->安装内核顺序不能乱

安装完后/boot下将增加以下几个文件(用ls -l *24*查看)

helight@helight-desktop:/boot$ ls -l *24*

-rw-r–r– 1 root root    85203 2008-03-14 22:24 config-2.6.24

-rw-r–r– 1 root root    85203 2008-03-14 20:23 config-2.6.24.old

-rw-r–r– 1 root root 37968871 2008-03-15 08:31 initrd-2.6.24.img

-rw-r–r– 1 root root 4014080 2008-03-14 22:24 initrd.img-2.6.24

-rw-r–r– 1 root root   932315 2008-03-14 22:24 System.map-2.6.24

-rw-r–r– 1 root root   932315 2008-03-14 20:23 System.map-2.6.24.old

-rw-r–r– 1 root root 1858864 2008-03-14 22:24 vmlinuz-2.6.24

-rw-r–r– 1 root root 1858864 2008-03-14 20:23 vmlinuz-2.6.24.old

helight@helight-desktop:/boot$

/boot/grub/menu.lst中添加一个新的启动项,如我的menu.lst增加了如下一段文字

title             Ubuntu, kernel 2.6.24

root            (hd0,0)

kernel          /boot/vmlinuz-2.6.24root=UUID=d7e2cf74-ebf5-4c78-ac2c-9f85a9809eae ro

initrd          /boot/initrd-2.6.24.img        #UUID是分区的编号,分区表被修改了会变化


从新启动即可。

补充:
make 包括 内核部件和模块部件一起编译
make bzImage 只编译内核#可以在menuconfig后就使用 只编译内核 但是接着要编译 模块不能省
make modules 只编译模块
make modules_install 把编译好的内核安装到/lib/modules/X.x.x下面 XX是你自己定义的版本号
sudo mkinitramfs -o /boot/initrd-2.6.24.img 2.6.24就对 /lib/modules/XX。X下面的模块库进行的一个镜像快照当内核需要没有被编入内核的模块是会去initrd.img找如果启动过程中需要的部 分都在内核中。就不会访问该文件!

内核安装过程中,实际做了三件事:
1.安装modules到/lib/modules下面。
2.复制内核vmlinuz和模块镜像initrd.img到/boot/下
3.在/下面创建vmlinux和initrd两个链接。是方便没法指明路径的引导程序直接到/目录下找到/boot/的启动文件!(grub可以设定路径,不用做链接也可以)
4.在grub里面加入新内核的引导路径!
完!

eDistrict Login 说:
2022年8月01日 15:26

This portal created in order to provide the citizens of Uttar Pradesh with the flexibility and the ability to apply for all types of state and central Government schemes and services in online directly. This has brought all the schemes and services under one umbrella allowing the citizens to easily apply from all the different services where the application form is free to apply through and you can view the status of your application and complete its verification to get your registration confirmation. eDistrict Login In this article, you will learn about e District UP registration, login and how you can apply for different schemes and services then complete their status check and verification as well.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter