内核编译

其他Linux/Unix/BSD/OSX等发行版讨论
wyylling
帖子: 51
注册时间: 2008-01-01 22:30

#2

帖子 wyylling » 2008-04-05 23:59

编译新内核经验总结:(顺便说一句,有很多人很不负责任,从别人那儿转来一篇编译内核的文章就乱发,自己根本就没试过,对与不对自己都不知道,误导别人,这种人啊。。。)
之前也编译过2.6.24的内核,但因为对每个步骤要做的事情,不是很清楚,最终所有的工作全部白费,糊里糊涂的就失败了,我想说的是,自己编译内核,一定要清楚每一个步骤你是在做什么,为什么要这么做,如果都清楚了,那么你肯定能编译成功,现在我们就开始吧

步骤:在www.kernal.org的官网上下载自己需要的内核,解压的步骤就省了吧,这个相信使用linux的人都会
1.我下载的是2.6.24的核,解压后的目录为linux-2.6.24。
cd linux-2.6.24若之前编译过内核,需要用命令
sudo make mrproper 清理一下
2.Now you can start kernel configuration by typing any one of the command:
$ make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
$ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
$ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.

For example make menuconfig command launches following screen:
$ make menuconfig
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.

3.Compile kernel
Start compiling to create a compressed kernel image, enter:
$ make
Start compiling to kernel modules:
$ make modules
Install kernel modules (become a root user, use su command):
$ su -
# make modules_install
4.Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:

System.map-2.6.24
config-2.6.24
vmlinuz-2.6.24
5.Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitrarmfs -o initrd.img-2.6.24 2.6.24
initrd.img-2.6.24 表示initrd images,后一个2.6.24是的位置是在/lib/modules目录下
initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.
6. Modify Grub configuration file - /boot/grub/menu.lst
Open file using vi:
# vi /boot/grub/menu.lst
title kernel 2.6.24 Default
root (hd0,2)
kernel /boot/vmlinuz root=/dev/hdb3 ro
initrd /boot/initrd.img-2.6.24
savedefault
bootRemember to setup correct root=/dev/hdXX device. Save the file. If you think editing and writing all lines by hand is too much for you then try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type command:
# update-grub
若仅仅用命令update-grub在menu.lst不会出现initrd /boot/initrd.img-2.6.24的,若无initrd的映像文件,该内核是不会启动,会出现错误,无法启动新内核。
7.computer and boot into your new kernel
Just issue reboot command:
# reboot
wyylling
帖子: 51
注册时间: 2008-01-01 22:30

#3

帖子 wyylling » 2008-04-06 0:47

系统”菜单 -> 系统管理 -> 联网 -> 选择你的网卡,点击属性,选择DHCP,然后激活。
上网问题
haox2653
帖子: 10
注册时间: 2008-08-18 10:19

ding!!!

#4

帖子 haox2653 » 2008-08-18 10:21

我爱死楼主了,敬佩楼主治学之严谨
haox2653
帖子: 10
注册时间: 2008-08-18 10:19

ding!!

#5

帖子 haox2653 » 2008-08-18 11:10

我是一个linux初学者,你能告诉我你的qq号或邮箱么,我有什么问题好直接请教你。你可以站内信给我!
poet
帖子: 2841
注册时间: 2006-09-11 22:47

Re: ding!!

#6

帖子 poet » 2008-08-18 12:55

haox2653 写了:我是一个linux初学者,你能告诉我你的qq号或邮箱么,我有什么问题好直接请教你。你可以站内信给我!
据我观察:

1。大多数 Linux 高手不用 QQ,他们使用 MSN,google talk 等工具同全世界的人交流。而 QQ 因为只能同中国人交流,往往被弃用。

2。即使有少数用QQ的Linux高手,即使它愿意把QQ号告诉你,他通常也绝对不会喜欢你直接问他问题,有什么问题自己先想办法,或者上论坛,任何人都没有义务一对一的帮你解决问题。
haox2653
帖子: 10
注册时间: 2008-08-18 10:19

......

#7

帖子 haox2653 » 2008-08-18 15:57

在改一个网卡驱动。处次接触linux,许多问题在网上找了答案,看二十个,有十个貌似可行。实践之,只有一两个可行。累啊。。。我也是心急啊,任务压头上
haox2653
帖子: 10
注册时间: 2008-08-18 10:19

......

#8

帖子 haox2653 » 2008-08-18 15:57

在改一个网卡驱动。初次接触linux,许多问题在网上找了答案,看二十个,有十个貌似可行。实践之,只有一两个可行。累啊。。。我也是心急啊,任务压头上
头像
XEUY
帖子: 247
注册时间: 2007-08-20 8:13
联系:

Re:

#9

帖子 XEUY » 2009-01-03 8:54

wyylling 写了:编译新内核经验总结:(顺便说一句,有很多人很不负责任,从别人那儿转来一篇编译内核的文章就乱发,自己根本就没试过,对与不对自己都不知道,误导别人,这种人啊。。。)
之前也编译过2.6.24的内核,但因为对每个步骤要做的事情,不是很清楚,最终所有的工作全部白费,糊里糊涂的就失败了,我想说的是,自己编译内核,一定要清楚每一个步骤你是在做什么,为什么要这么做,如果都清楚了,那么你肯定能编译成功,现在我们就开始吧

步骤:在www.kernal.org的官网上下载自己需要的内核,解压的步骤就省了吧,这个相信使用linux的人都会
1.我下载的是2.6.24的核,解压后的目录为linux-2.6.24。
cd linux-2.6.24若之前编译过内核,需要用命令
sudo make mrproper 清理一下
2.Now you can start kernel configuration by typing any one of the command:
$ make menuconfig - Text based color menus, radiolists & dialogs. This option also useful on remote server if you wanna compile kernel remotely.
$ make xconfig - X windows (Qt) based configuration tool, works best under KDE desktop
$ make gconfig - X windows (Gtk) based configuration tool, works best under Gnome Dekstop.

For example make menuconfig command launches following screen:
$ make menuconfig
You have to select different options as per your need. Each configuration option has HELP button associated with it so select help button to get help.

3.Compile kernel
Start compiling to create a compressed kernel image, enter:
$ make
Start compiling to kernel modules:
$ make modules
Install kernel modules (become a root user, use su command):
$ su -
# make modules_install
4.Install kernel
So far we have compiled kernel and installed kernel modules. It is time to install kernel itself.
# make install
It will install three files into /boot directory as well as modification to your kernel grub configuration file:

System.map-2.6.24
config-2.6.24
vmlinuz-2.6.24
5.Create an initrd image
Type the following command at a shell prompt:
# cd /boot
# mkinitrarmfs -o initrd.img-2.6.24 2.6.24
initrd.img-2.6.24 表示initrd images,后一个2.6.24是的位置是在/lib/modules目录下
initrd images contains device driver which needed to load rest of the operating system later on. Not all computer requires initrd, but it is safe to create one.
6. Modify Grub configuration file - /boot/grub/menu.lst
Open file using vi:
# vi /boot/grub/menu.lst
title kernel 2.6.24 Default
root (hd0,2)
kernel /boot/vmlinuz root=/dev/hdb3 ro
initrd /boot/initrd.img-2.6.24
savedefault
bootRemember to setup correct root=/dev/hdXX device. Save the file. If you think editing and writing all lines by hand is too much for you then try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type command:
# update-grub
若仅仅用命令update-grub在menu.lst不会出现initrd /boot/initrd.img-2.6.24的,若无initrd的映像文件,该内核是不会启动,会出现错误,无法启动新内核。
7.computer and boot into your new kernel
Just issue reboot command:
# reboot

学了 二楼好贴! :em11
每天都在起步。。。如同起床
shaoyunfei
帖子: 62
注册时间: 2009-02-20 13:54

Re: 内核编译

#10

帖子 shaoyunfei » 2009-04-06 19:03

我用make bzImage命令好像不行!我看版主是用的make
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 内核编译

#11

帖子 xhy » 2009-04-06 19:14

忍不住还是要说一句,编译自己用的内核,其实完全不用这么复杂
目前负债150多万
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 内核编译

#12

帖子 xhy » 2009-04-06 19:35

节选自kernel源码目录下的 README

代码: 全选

 - Make sure you have no stale .o files and dependencies lying around:

        cd linux
        make mrproper

   You should now have the sources correctly installed.
至此,内核源码已经正确安装了。

代码: 全选

   To configure and build the kernel use:
   cd /usr/src/linux-2.6.N
   make O=/home/name/build/kernel menuconfig
   make O=/home/name/build/kernel
   sudo make O=/home/name/build/kernel modules_install install

   Please note: If the 'O=output/dir' option is used then it must be
   used for all invocations of make.
至此,已经配置编译并且安装好内核了。
目前负债150多万
Devonian
帖子: 13
注册时间: 2008-06-20 15:27

Re: 内核编译

#13

帖子 Devonian » 2010-01-05 15:41

在kubuntu 910下编译内核

使用mkinitramfs生成的initrd.img文件不知道为什么被update-grub命令无视,
总是认不出来,只能自己手动修改grub.cfg,添加上initrd.img后仍然无法启动

有人碰到相同情况吗
def
帖子: 848
注册时间: 2009-07-05 19:36

Re: 内核编译

#14

帖子 def » 2010-01-16 17:41

:em04 编译专用内核方法:

代码: 全选

su
rm /boot/config*   # 必须!!!删除系统自带配置文件,这个是 通用内核 的配置文件
lspci               # 记下其信息,这是你系统的硬件信息
cd 内核路径
make mrproper
make menuconfig   # 注意!!! 有3个驱动必须得编译进[*]内核(不是模块[M])!!! "SCSI disk support","SATA / PATA"中的SATA控制器驱动,文件系统
                  # 其他驱动,比如 PPPoE,声卡,网卡 也要编译进去。
                  # 如果你需要使用QEMU虚拟机,那么 FUSE 也要编译进去。
make
make modules_install
make headers_install
cp arch/x86/boot/bzImage /boot/vmlinuz-compiled
update-grub
上次由 def 在 2010-01-16 17:46,总共编辑 1 次。
delectate
帖子: 18311
注册时间: 2008-01-09 22:41

Re: 内核编译

#15

帖子 delectate » 2010-01-16 17:45

mark掉,然后看看有没有……
回复