如何编译linux版本

如何编译linux版本,第1张

1、下载内核文件如:linux-2.4.18-3.tar.gz拷贝到/usr/src目录并解压缩。

# cd /usr/src

# tar zvxf linux-2.4.18-3.tar.gz

2、进入解压目录。(/usr/src/linux-2.4.18-3,视文件名而定)

# cd /usr/src/linux-2.4.18-3

# make mrproper

# make xconfig

3、进行选译,自己设定个性化的内核。完后点“save and exit”

4、进行编译

# make dep

# make clean

# make bzImage (I要大写哟)

5、编译模块。

# make modules

# make modules_install

# depmod -a

6、编译完成,开始替换文件。

# cd /boot

# rm System.map

# rm vmlinuz

# mv /usr/src/linux-2.4.18-3/System.map System.map

# mv /usr/src/linux-2.4.18-3/arch/i386/boot/bzImage vmlinux

7.修改开机设定。

GRUB是 /boot/grub/grub.conf文件 lilo是/etc/lilo.conf文件

可以用命令

# mkinitrd /boot/initrd-2.4.18-3.img 2.4.18-3来生成initrd文件。

用GRUB来举例子说。(红色部分)

# 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,7)

# kernel /vmlinuz-version ro root=/dev/hda10

# initrd /initrd-version.img

#boot=/dev/hda

default=1

timeout=5

splashimage=(hd0,7)/grub/splash.xpm.gz

title Red Hat Linux (2.4.18-3)

root (hd0,7)

kernel /vmlinuz-2.4.18-3 ro root=/dev/hda10

initrd /initrd-2.4.18-3.img

title win xp

rootnoverify (hd0,0)

chainloader +1

重启计算机,完工。

附加说明:

内核编译好后在以下几个位置的。

1。bzImage文件 /usr/src/linux-2.4.18-3/arch/i386/boot目录

2。外挂模块 /usr/src/linux-2.4.18-3/arch/i386/lib目录

3。已安装的模块文件 /lib/modules/2.4.18-3目录

1、首先在linux下判断是否安装gcc编译器,直接执行:gcc -v,判断是否安装gcc。

2、然后需要在代码框内写一个简单的C源程序。

3、在程序中使用了C语言中的数学开方函数,sqrt(),所以需要引入math.h头文件。

4、写完源程序之后,我们对其进行编译,如果使用通常的编译语句,【gcc math.c -o math】进行编译,会出现错误;大概的意思就是不认识sqrt这个东西。

5、所以需要使用正确的命令:【gcc math.c -lm -o math】;这样才能编译正确。

首先uname

-r看一下你当前的linux内核版本

1、linux的源码是在/usr/src这个目录下,此目录有你电脑上各个版本的linux内核源代码,用uname

-r命令可以查看你当前使用的是哪套内核,你把你下载的内核源码也保存到这个目录之下。

2、配置内核

make

menuconfig,根据你的需要来进行选择,设置完保存之后会在当前目录下生成.config配置文件,以后的编译会根据这个来有选择的编译。

3、编译,依次执行make、make

bzImage、make

modules、make

modules

4、安装,make

install

5、.创建系统启动映像,到

/boot

目录下,执行

mkinitramfs

-o

initrd.img-2.6.36

2.6.36

6、修改启动项,因为你在启动的时候会出现多个内核供你选择,此事要选择你刚编译的那个版本,如果你的电脑没有等待时间,就会进入默认的,默认的那个取决于

/boot/grub/grub.cfg

文件的设置,找到if

[

"${linux_gfx_mode}"

!=

"text"

]这行,他的第一个就是你默认启动的那个内核,如果你刚编译的内核是在下面,就把代表这个内核的几行代码移到第一位如:

menuentry

'Ubuntu,

with

Linux

3.2.0-35-generic'

--class

ubuntu

--class

gnu-linux

--class

gnu

--class

os

{

recordfail

gfxmode

$linux_gfx_mode

insmod

gzio

insmod

part_msdos

insmod

ext2

set

root='(hd0,msdos1)'

search

--no-floppy

--fs-uuid

--set=root

9961c170-2566-41ac-8155-18f231c1bea5

linux/boot/vmlinuz-3.2.0-35-generic

root=UUID=9961c170-2566-41ac-8155-18f231c1bea5

ro

quiet

splash

$vt_handoff

initrd/boot/initrd.img-3.2.0-35-generic

}

当然你也可以修改

set

default="0"来决定用哪个,看看你的内核在第几位,default就填几,不过我用过这种方法,貌似不好用。

重启过后你编译的内核源码就成功地运行了,如果出现问题,比如鼠标不能用,usb不识别等问题就好好查查你的make

menuconfig这一步,改好后就万事ok了。

最后再用uname

-r看看你的linux内核版本。是不是你刚下的那个呢!有没有成就感?

打字不易,如满意,望采纳。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/yw/7355106.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-04-04
下一篇2023-04-04

发表评论

登录后才能评论

评论列表(0条)

    保存