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

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


            以前学习的基础知识都忘记了,趁放假回来好好补补基础。今天下午办完签证后,回来重新在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、创建目录,存放内核源码:                

  1. [root@localhost /]# mkdir linux_kernel  
             2、进入该目录,解压下载的linux内核源码:
  1. [root@localhost linux_kernel]# ls  
  2. linux-2.6.29.tar.gz  
  3. [root@localhost linux_kernel]# tar -xvz -f linux-2.6.29.tar.gz   
              3、进入内核源码根目录,清理痕迹:
  1. [root@localhost linux_kernel]# cd linux-2.6.29  
  2. [root@localhost linux-2.6.29]# make distclean  
             4、配置内核。这里使用正在运行的fedora9的配置文件作为此内核的配置文件:
  1. [root@localhost linux-2.6.29]# cp /boot/config-2.6.25-14.fc9.i686 .config  
  2. [root@localhost linux-2.6.29]# make menuconfig  

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

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

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

             9、制作 init ramdisk。

  1. [root@localhost linux_kernel]#
    mkinitramfs -o /boot/initrd.img 2.6.24-16

             10、拷贝内核和制作好的init ramdisk到/boot目录下面。
  1. [root@localhost linux_kernel]# cp /linux_kernel/linux-2.6.29/arch/x86/boot/bzImage  /boot/vmlinuz-2.6.29  
  2. [root@localhost linux_kernel]# cp /linux_kernel/initrd-2.6.29 /boot/  
               注意:vmlinuz-2.6.29可以任意取名,只是下面修改grub的时候,注意名字要一致就行。

              11、修改grub 启动项。

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

               在里面添加:
  1. title xgg's Linux(2.6.29)  
  2.         root (hd0,0)  
  3.         kernel /vmlinuz-2.6.29 ro root=UUID=3f0b3cdc-c7e6-4649-a214-124f469262f4 rhgb quiet  
  4.         initrd /initrd-2.6.29 




或者


menuentry 'Ubuntu,Linux 2.6.32' --class ubuntu --class gnu-linux --class gnu --class os {
        set gfxpayload=$linux_gfx_mode
        insmod part_msdos
        insmod ntfs
        set root='(hd0,msdos6)'
        search --no-floppy --fs-uuid --set=root 66769BE2769BB173
        loopback loop0 /ubuntu/disks/root.disk
        set root=(loop0)
        linux   /boot/vmlinuz-2.6.32  root=UUID=66769BE2769BB173 loop=/ubuntu/disks/root.disk ro   quiet splash vt.handoff=7
        initrd  /boot/initrd.img-2.6.32
}



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




11.删除旧内核文件


1.查看一下内核版本  uname -a

2.查看当前系统下的所有内核版本



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值