x86平台下linux配置编译与启动

来源:互联网 发布:学尤克里里下什么软件 编辑:程序博客网 时间:2024/04/26 22:53

            以前学习的基础知识都忘记了,趁放假回来好好补补基础。今天下午办完签证后,回来重新在x86平台上面配置编译了一下linux内核,并且设置启动。所有的工作是在虚拟机下面进行的。

下面首先谈谈理论上编译配置内核需要用哪些步骤:

            1、首先肯定是在www.linux.org上面下载自己需要的linux内核版本啊。建议到官方下载,不要下载经过别人裁剪过的内核。

            2、解压缩。下载的时候可以下载经过gzip压缩的,也可以选择经过bzip2压缩的。经过gzip压缩的用:tar -xvz -f 来解压缩;经过bzip压缩的用:tar -xvj -f来解压缩。
            3、清理。下载后,最好清理下 。这里介绍三个清理命令:

                           make clean :remove all generate files but config files;

                           make mrproper:remove all generate files include config files;
                           make distclean:mrproper and remove editor backup and patch files

             4、配置。配置,有四个配置命令,下面分别说明:
                           make config:交互式文本配置。

                           make menuconfig:菜单式配置。一般选取这个配置。

                           make xconfig:只能在有xwindow的情况下配置,在纯粹命令行界面的时候不能够使用,而上面两个配置能够使用。

                    一般配置选项有很多,使用make menuconfig后,会在内核的根目录下面生成.config的配置文件。我们可以选取一个已经配置好的.config文件,修改这个文件即可。

            5、编译内核。编译内核的命令有:

                          make zImage :在x86平台下,只能够编译生成小于512K的内核;

                           make bzImage:没有大小的限制。

            6、编译内核模块。编译内核模块的命令:

                           make modules

                     之所以要编译内核模块,是因为在配置选项里面的那些选择“M”的,只编译,没有连接;而“*”既要编译也要连接,最后生成zImage。都是以内核模块的形式加载到内核的。

            7、安装内核模块。安装内核模块命令:

                          make modules_install

            8、制作init ramdisk。制作ramdisk的命令:

                          mkinitrd  initrd-$Version $Version 其中第二个$Version为内核的实际版本。

                    initramdisk作用:提供一种让内核可以简单实用ramdisk的能力。这些能力包括:格式化一个ramdisk、加载文件系统到ramdisk、将ramdisk作为根文件系统

            9、安装内核。

                   由于Linux系统启动时候,会从/boot目录下来寻找文件与init ramdisk,所以需要将编译好的内核和init ramdisk复制到/boot目录下;

                   为了让grub在启动时能提供一项我们自己制作的linux内核的选择项,需要修改grub配置文件。


下面列出自己编译和配置内核的步骤:
           1、创建目录,存放内核源码:                

[root@localhost /]# mkdir linux_kernel
             2、进入该目录,解压下载的linux内核源码:

[root@localhost linux_kernel]# lslinux-2.6.29.tar.gz[root@localhost linux_kernel]# tar -xvz -f linux-2.6.29.tar.gz 
              3、进入内核源码根目录,清理痕迹:

[root@localhost linux_kernel]# cd linux-2.6.29[root@localhost linux-2.6.29]# make distclean
             4、配置内核。这里使用正在运行的fedora9的配置文件作为此内核的配置文件:

[root@localhost linux-2.6.29]# cp /boot/config-2.6.25-14.fc9.i686 .config[root@localhost linux-2.6.29]# make menuconfig

              5、按照配置文件的说明手册对文件进行配置。

              6、编译内核。编译完成后,生成的内核位于:/arch/x86/boot目录下。

[root@localhost linux-2.6.29]# make bzImage
              7、编译好内核后,就可以编译模块了。

[root@localhost linux-2.6.29]# make modules
              8、编译好模块后,就可以安装模块了。

[root@localhost linux-2.6.29]# make modules_install
                 完成安装后,编译好的内核模块会从内核源代码目录拷贝至/lib/modules下面。

             9、制作 init ramdisk。

[root@localhost linux_kernel]# mkinitrd initrd-2.6.29 2.6.29
             10、拷贝内核和制作好的init ramdisk到/boot目录下面。

[root@localhost linux_kernel]# cp /linux_kernel/linux-2.6.29/arch/x86/boot/bzImage  /boot/vmlinuz-2.6.29[root@localhost linux_kernel]# cp /linux_kernel/initrd-2.6.29 /boot/
               注意:vmlinuz-2.6.29可以任意取名,只是下面修改grub的时候,注意名字要一致就行。

              11、修改grub 启动项。

[root@localhost linux_kernel]# vi /etc/grub.conf 

               在里面添加:

title xgg's Linux(2.6.29)        root (hd0,0)        kernel /vmlinuz-2.6.29 ro root=UUID=3f0b3cdc-c7e6-4649-a214-124f469262f4 rhgb quiet        initrd /initrd-2.6.29

       到此为止,就已经完成了linux内核的编译、配置了,很简单的。下次启动的时候就会出现双启动项。           










             


                                                

原创粉丝点击