Chinaunix首页 | 论坛 | 博客
  • 博客访问: 393441
  • 博文数量: 63
  • 博客积分: 3142
  • 博客等级: 中校
  • 技术积分: 838
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-06 13:35
文章分类

全部博文(63)

文章存档

2011年(2)

2010年(114)

2009年(3)

我的朋友

分类: LINUX

2010-07-16 16:12:42

(一)Debian下编译内核
在Debian下编译内核比较简单。首先需要安装一些必要的软件包:
$ sudo apt-get install kernel-package ncurses-dev fakeroot wget bzip2 make patch
我在编译过程中总是出现错误"lguest.c:34:18: error: zlib.h: No such file or directory",后来发现还缺一个软件包zlib1g-dev,所以我还是把这一步加上吧。
$ sudo apt-get install zlib1g-dev

切换到/usr/src目录下
$ cd /usr/src
下载新的内核源码可以上。我下的版本是2.6.28.7。
$ sudo wget
$ sudo tar -xjf linux-2.6.28.7.tar.bz2
$ cd linux-2.6.28.7/

为了节省时间,请执行以下命令从现有内核中获得配置:
$ sudo make oldconfig
执行完此条命令后,会根据新老内核的差异情况,询问你一些问题,如果不确定的话请都是
用默认(直接按回车)。

接下来执行以下命令来配置内核(这个过程比较麻烦,不清楚的就别修改):
$ sudo make menuconfig
如果你的Debian有X的话,也可以使用 make xconfig 来进行内核的配置。

然后执行以下命令来生成新的内核*.deb包
$ sudo make-kpkg clean
$ sudo fakeroot make-kpkg --initrd --append-to-version=-pcghost --revision=1.0 kernel_image
如果生成过程中出现错误,请执行sudo make clean 后,用sudo make menuconfig 重新配>置内核。一般都是仔细看错误信息,找到出错的模块,然后将其去除。

编译成功了就回上级目录
$ cd ..
已经可以看到编译的新内核包了linux-image-2.6.28.7-pcghost_1.0_i386.deb
现在执行以下命令安装新内核
$ sudo dpkg -i linux-image-2.6.28.7-pcghost_1.0_i386.deb
接着Debian会安装新内核并更新Grub的配置文件。重启就可以看到启动菜单中增加了2.6.28.7的启动选项,你可以选择使用新内核,也可以继续用以前的内核。
(二)多个内核之间的切换
提醒:你的新内核要想支持内核切换,在内核配置中"Processor type and features ---> "的子菜单项"kexec system call"必须选择"Y"。
"kexec is a system call that implements the ability to shutdown your current kernel, and to start another kernel. It is like a reboot but it is independent of the system firmware.   And like a reboot , you can start any kernel with it, not just Linux."

我们首先需要安装一个工具:
$ sudo apt-get install kexec-tools

现在看看我的系统中安装了哪些内核
$ ls /boot/vmlinuz*
/boot/vmlinuz-2.6.26-1-686   /boot/vmlinuz-2.6.28.7-pcghost

再来看看当前所用内核
$ sudo uname -r
2.6.28.7-pcghost

我现在想切换到2.6.26-1-686
记得,需要root权限
$ sudo -s
现在用kexec来加载2.6.26-1-686
看看挂载需要追加的参数
#cat /boot/grub/menu.lst | grep 2.6.26-1-686
title           Debian GNU/Linux, kernel 2.6.26-1-686
kernel          /vmlinuz-2.6.26-1-686 root=UUID=2519bdef-60b5-421f-b99b-b78c3b5bfc27 ro
initrd          /initrd.img-2.6.26-1-686
title           Debian GNU/Linux, kernel 2.6.26-1-686 (single-user mode)
kernel          /vmlinuz-2.6.26-1-686 root=UUID=2519bdef-60b5-421f-b99b-b78c3b5bfc27 ro single
initrd          /initrd.img-2.6.26-1-686
# kexec -l /boot/vmlinuz-2.6.26-1-686 --initrd /boot/initrd.img-2.6.26-1-686 --append="root=UUID=2519bdef-60b5-421f-b99b-b78c3b5bfc27 ro"

加载后,执行以下命令就可以了
# kexec -e
切换完成后可以执行sudo uname -a查看当前使用的内核。

I just upgraded my Debian5 workstation to 2.6.31. While doing so I stumbled over this:

cc -m32 -Wall -Wmissing-declarations -Wmissing-prototypes -O3 -I../../include -I../../arch/x86/include -U_FORTIFY_SOURCE lguest.c -o lguest
lguest.c:21:25: error: sys/eventfd.h: No such file or directory
lguest.c: In function ‘create_thread’:
lguest.c:1021: warning: implicit declaration of function ‘eventfd’
make: *** [lguest] Error 1

This is apparenty due to the old libc-dev package that Lenny comes with. Since libc isn’t exactly a good candidate for a selective upgrade I helped myself with simply editing Documentation/lguest/Makefile and changing:

all: lguest

to

all:

So lguest wont be build anymore. After that make-kpkg binary-arch worked as usual.
I’m also happy to report that my still works on 2.6.31.

#5 — lguest fails to built

State Resolved
Version: 2.6.31-zen
Area Zen-Stable Releases/GIT
Issue type Bug
Severity Medium
Submitted by oshiri
Submitted on Nov 01, 2009
Responsible
Target release:
Last modified on Nov 02, 2009 by Brandon Berhent
make[1]: Leaving directory `/usr/src/linux-2.6-zen'
/usr/bin/make ARCH=i386 \
                 -C Documentation/lguest
make[1]: Entering directory `/usr/src/linux-2.6-zen/Documentation/lguest'
cc -m32 -Wall -Wmissing-declarations -Wmissing-prototypes -O3 -I../../include -I../../arch/x86/include -U_FORTIFY_SOURCE lguest.c -o lguest
lguest.c:21:25: error: sys/eventfd.h: No such file or directory
lguest.c: In function ‘create_thread’:
lguest.c:1021: warning: implicit declaration of function ‘eventfd’
make[1]: *** [lguest] Error 1
make[1]: Leaving directory `/usr/src/linux-2.6-zen/Documentation/lguest'
make: *** [debian/stamp/build/kernel] Error 2
Added by oshiri on Nov 01, 2009 11:44 PM
It's not a bug after all.
It's Debian's Lenny libc problem that caused the error.
Thanks.
Added by Brandon Berhent on Nov 02, 2009 01:16 AM
Issue state: UnconfirmedResolved
Yes, this is simply debian's libc being too old, a couple of reads:

/msg00034.html" rel="nofollow">[…]/msg00034.html

Just do as the link says. He's correct as to the cause. lenny has an older version of libc6 and the dev file does not include the eventfd.h file. Upgrading libc6 is NOT an option if you want to continue running lenny.

That leaves you with two choices.
1) Upgrade the entire system to testing
2) Remove the option that compiles that particular module (which is what he did). Since what is actually compiled here is a
demonstration utility "lguest" which runs a Linux guest
(this has to do with virtualization) you probably won't even notice it's gone :)

The solution is very straightforward, just as he said. Within your kernel source tree find the file: Documentation/lguest/Makefile

Open that file in a text editor and change the line that reads all: lguest and simply remove the word "lguest".

Actually you do have a 3rd option. Grab the pre-compiled kernel from unstable and install that. (or you can grab a kernel)


参考文献:
(1)
(2)Linux Kernel Configuration Archive
(3)Linux 2.6.19.x 内核编译配置选项简介
(4)

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