Ubuntu下编译x86 linux

1、下载kernel,地址:

http://www.kernel.org/

我这里下的是linux-2.6.32.59

 

2、解压:
         #tar -xvf linux-2.6.32.59.tar.bz2

 

3、清理内核中间文件,及配置文件

         #cdlinux-2.6.32.59

         #makedistclean

(备注:make clean可以清除中间文件,但不能清除配置文件)

 

4、拷贝当前系统的一个配置文件作为默认config

        #cp /boot/config-2.6.32-28-generic .config

 

5、配置内核,

        #make menuconfig

(备注:如果不想修改什么,可以直接保存退出)

 

6、编译内核

        #make bzImage

(先喝杯茶,等一会吧,最后生成的映像文件是arch/x86/boot/bzImage)

 

7、编译内核模块

         #makemodules

        

8、安装内核模块

         #makemodules_install

         (备注:完成后模块代码会被拷贝至/lib/modules/目录下,这里是/lib/modules/2.6.32.59)

 

9、制作根文件系统

         #cd..

         #mkinitramfs-o initrd-2.6.32-59 2.6.32.59

         (备注:完成后会在当前目录下生成一个initrd-2.6.32的映像文件)

 

10、由于系统启动时会从/boot目录下寻找内核文件与initramdisk,所以要把bzImage和initrd-2.6.32-59到/boot下相应的目录里

         #cplinux-2.6.32.59/arch/x86/boot/bzImage /boot/vmlinuz-2.6.32-59

         #cpinitrd-2.6.32-59 /boot/

 

11、修改grub文件,以便让系统启动时显示我们的系统

         #chmod+w /boot/grub/grub.cfg

         #gedit/boot/grub/grub.cfg

在### BEGIN /etc/grub.d/10_linux ###增加以下启动项内容:

menuentry 'Ubuntu, with Linux 2.6.32-59'--class ubuntu --class gnu-linux --class gnu --class os {

         recordfail

         insmodext2

         setroot='(hd0,1)'

         search--no-floppy --fs-uuid --set cbd297b9-f68d-4c49-8029-165d69a49c90

         linux /boot/vmlinuz-2.6.32-59root=UUID=cbd297b9-f68d-4c49-8029-165d69a49c90 ro   quiet splash

         initrd         /boot/initrd-2.6.32-59

}

作为对比,这里给出原启动项:

menuentry 'Ubuntu, with Linux2.6.32-28-generic' --class ubuntu --class gnu-linux --class gnu --class os {

         recordfail

         insmodext2

         setroot='(hd0,1)'

         search--no-floppy --fs-uuid --set cbd297b9-f68d-4c49-8029-165d69a49c90

         linux /boot/vmlinuz-2.6.32-28-genericroot=UUID=cbd297b9-f68d-4c49-8029-165d69a49c90 ro   quiet splash

         initrd         /boot/initrd.img-2.6.32-28-generic

}

可以看到,这里只是改动了启动名称以及linux和initrd的路

 

#gedit/etc/grub.d/30_os-prober

把下面三个set timeout=0都改为set timeout=10(否则启动的时候不会显示出内核选项)

found_other_os=

 

adjust_timeout () {

  if[ "x${found_other_os}" = "x" ] ; then

   if [ "x${GRUB_HIDDEN_TIMEOUT}" != "x" ] ; then

     if [ "x${GRUB_HIDDEN_TIMEOUT_QUIET}" = "xtrue" ] ;then

         verbose=

     else

         verbose="--verbose"

     fi

 

     if [ "x${GRUB_HIDDEN_TIMEOUT}" = "x0" ] ; then

         cat<<EOF

if [ \${timeout} != -1 ]; then

  ifkeystatus; then

   if keystatus --shift; then

     set timeout=-1

   else

     set timeout=0

   fi

 else

   if sleep$verbose --interruptible 3 ; then

     set timeout=0

   fi

  fi

fi

EOF

     else

         cat<< EOF

if [ \${timeout} != -1 ]; then

  ifsleep$verbose --interruptible ${GRUB_HIDDEN_TIMEOUT} ; then

   set timeout=0

  fi

fi

 

         # update-grub

         更新一下启动配置

 

12、搞定,重启测试一下,看到新的内核选项,说明成功了~~

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值