linux内核编译

来源:互联网 发布:淘宝熊家通讯 编辑:程序博客网 时间:2024/05/20 12:52

1,获取内核源码:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.17.8.tar.gz

2,解包并放在一个单独的目录,这里我放在~/linux目录下:

Now move the source code into this directory:
$ mv ~/linux-2.6.17.8.tar.gz ~/linux/
And go into the linux directory:
$ cd ~/linux
$ ls
linux-2.6.17.8.tar.gz
Now that the source code is in the proper directory, uncompress the tree:
$ tar -xzvf linux-2.6.17.8.tar.gz
The screen will be filled with files that are uncompressed, and you will be left with
the following in the linux/ directory:
$ ls
linux-2.6.17.8.tar.gz
linux-2.6.17.8/

3,配置文件处理

解开的内核中是没有,config文件的,可以有几种方法生成:

a,用这个源码提供者的配置方式生成.config

make defconfig  默认为x86结构的配置文件

    顺便有几个命令:

   make mrproper     先调用make clean 清除产生的中间文件,然后还会删除原来的配置文件,这个最好执行以下

   make oldconfig   根据当前的.config(没有的话,这条命令就相当于make config:弹出成千上万个选项让你选),来跟想要编译的内核的一些差异选项让你选

     如果你编译的这个系统与你运行的系统差异不是很大,可以把/boot下的配置文件拷贝到变异目录下,并且改名为.config

b,自己配置,可能又很多,不太适合

make config

c,用界面方式配置

make menuconfig等,注意要安装界面支持软件,如make menuconfig 需要安装ncurses-devel

         如果你编译的这个系统与你运行的系统差异不是很大,可以把/boot下的配置文件拷贝到变异目录下,然后make menuconfig有选项是load这个配置文件

         然后做些许改变就行了-----------------------------强烈推荐这种方式生成配置文件


配置时,模块编译方式:

y Build directly into the kernel.
n Leave entirely out of the kernel.
m Build as a module, to be loaded if needed.
? Print a brief descriptive message and repeat the prompt.

这里的配置选项要尽可能熟悉,只有这样才能编译出自己想要的内核

4,编译

make -j4   后面的j4表示用几个进程来编译,一般为你cpu个数的两倍,太多可能会挂死系统


5,安装

a,安装模块,会安装到/lib/modules/.下去

make modules_install 

b,安装内核及放/boot下的一些文件,如内核,grub.conf 映射表,都是自动的,不会覆盖原来的系统,也就是会组成双系统启动

make install 

     如:

    [root@localhost boot]# ls
drwxr-xr-x. 3 root root     1024 4月  16 10:45 efi
drwxr-xr-x. 2 root root     1024 4月  16 21:17 grub
-rw-------. 1 root root 16238715 4月  16 10:49 initramfs-2.6.32-431.el6.i686.img
-rw-------. 1 root root  5422676 4月  16 21:17 initramfs-2.6.39.img
drwx------. 2 root root    12288 4月  16 10:37 lost+found
-rw-r--r--. 1 root root   190104 11月 22 2013 symvers-2.6.32-431.el6.i686.gz
lrwxrwxrwx. 1 root root       23 4月  16 21:17 System.map -> /boot/System.map-2.6.39
-rw-r--r--. 1 root root  1982877 11月 22 2013 System.map-2.6.32-431.el6.i686
-rw-r--r--. 1 root root  1867541 4月  16 21:17 System.map-2.6.39
-rw-r--r--. 1 root root  1868295 4月  16 21:00 System.map-2.6.39.old

lrwxrwxrwx. 1 root root       20 4月  16 21:17 vmlinuz -> /boot/vmlinuz-2.6.39
-rwxr-xr-x. 1 root root  4002656 11月 22 2013 vmlinuz-2.6.32-431.el6.i686
-rw-r--r--. 1 root root  4197264 4月  16 21:17 vmlinuz-2.6.39

7,重启就ok了


8,注意:

这里最重要的就是编译前的配置文件选项的设置,编译后会跟西游系统的模块表进行比较,看那些模块没有编译,哪些编译了,但是并没有

说编译错误,可以按照下面的来对照:

我个人会根据提示信息打开.config文件来一一比对,看提示是否正确,然后改到自己想要的编译效果。

另外的参考下面,摘抄自http://smilejay.com/2013/11/kernel-install-error-could-not-find-module/


命令行中操作看到的内容如下:

原因分析:在make install时,为了让新内核中不缺少所需module,会先检查当前系统已经加载了的module(lsmod命令可查看),然后对比新安装的内核模块,如果新的内核模块中缺少一些module(和当前lsmod命令的输出做对比),就会报“ERROR: modinfo: could not find module power_meter”这样的错误信息。

具体来说,缺少相应module而报错,大致可分为3种情况:
1. 确实是缺少了某个module,其解决方法是:如果报的module对于你来说是有用,检查编译kernel时的.config文件,加上对应的配置(配为=m),重新编译和安装modules即可;如果你觉得这个module没啥用,大可不必管它了。

2. 新编译的kernel已经将该选项编译进kernel了(.config中选择为=Y),从而不需要生成这个module的.ko文件,系统找不到对应的.ko文件,但是已经在新内核中了,不必理会这个报错。例如,上面的“ERROR: modinfo: could not find module ext4”是因为我将EXT4文件系统模块编译为built-in了,如下:

3. 模块的名称变了,用当前系统lsmod命令查找的模块名称,在新编译的内核中找不到module了。只需要检查确认即可,如这里的“ERROR: modinfo: could not find module power_meter”就是这种类型,检查方式如下:

最后,如果那些错误报的内核模块,你认为不重要或者都经过上面的分析解决后,你就可以忽略这些错误提示了;尽管有这些“ERROR: modinfo: ”错误提示,但是kernel还是被正确安装了的,往下继续操作使用即可。


          




0 0
原创粉丝点击