ubuntu 12.04.2内核编译f方法

ubuntu 12.04.2内核是linux 3.5.0-23,其实升级到最新版本3.5.0也没什么很大意义,主要是集成了一些新的驱动和一些普通用户用不到的功能,所以基本上本文纯属折腾,但不要随便升级当班设备啊!好了,不废话了,我们开始...........
下载必要的工具
# apt-get install libncurses-dev kernel-package bzip2 make ncurses-dev fakeroot module-init-tools patch

sudo apt-get install libqt3-headers libqt3-mt-dev

sudo apt-get install libqt3-compat-headers

首先是准备条件:

①、有一台装有ubuntu 12.04的机器

②、先移步到http://www.kernel.org/下载linux稳定版内核

③、拥有root权限

④、并将下载好的内核解压到/usr/src下,使用命令如下:

        #tar jxvf   linux-3.5.0.tar.bz2

       这样你就可以得到一个名叫linux-3.5.0

好,现在一切都准备好了,接下来就开始配置,编译,安装新内核吧!

1, 进入刚才的文件夹 /usr/src/linux-3.5.0,输入命令:

     $ make mrproper

     该命令的功能在于清除当前目录下残留的.config和.o文件,这些文件一般是以前编译时未清理而残留的。而对于第一次编译的代码来说,不存在这些残留文件,所以可以略过此步,但是如果该源代码以前被编译过,那么强烈建议执行此命令,否则后面可能会出现未知的问题。

2, 配置编译选项

        sudo  cp   cp /boot/config-3.5.0-23-generic  ./.config

3,确定依赖性

    根据以往的经验,这一步是必须的,但是这次编译的时候,系统提醒我没必须要执行这个命令:

    make dep

    如果用现有的.config文件,这里会有很多内核新增加的驱动和功能让你确认是否编入内核中,这个你就自己看着输入y/n/m/?吧!

4,清除编译中间文件

    输入命令:make clean

5,生成新内核

    就是把配置过程中,我们选中编入内核中的程序编译链接生产linux内核,输入命令:

    make bzImage

6,生成modules

    和上步差不多,就是把配置过程中,我们选中编成modules的程序编译链接成modules,输入命令:

    make modules

7,安装modules

    就是把刚才编译生产的modules拷到系统文件夹下,以供新内核调用。输入命令:

    make modules_install

    一切都自动做好了。

8,建立要载入ramdisk的映像文件

    如果linux系统安装在scsi磁盘上,这步是必须的,否则可以跳过。我的linux是装在vmware上的,用的是虚拟的scsi磁盘,所以必须 要这一步。输入命令:

   mkinitramfs -o /boot/initrd-linux3.5.0.img 

   如果你的linux不是ubuntu,而是其他的发行版本,那么使用的命令可能不是mkinitramfs,而是mkinitrd,但功能和用法类似。

9,按装内核

   输入命令:make install

   此时系统会把linux内核的镜像文件还有System.map考入到/boot下,然后会自动生成引导菜单。

10, 配置grub引导程序

       既然新的内核编译并安装好了,那么我们要配置系统的引导程序用新内核正确引导,这一步我的是自动添加的,如果没有自动添加进去就自动动手修改添加吧。对象是/boot/grub/grub.cfg,首先用chmod更改该文件的只读属性。然后参照里面的已有内容添加一个新启动项,我的新启动项是:


menuentry 'Ubuntu,Linux 3.5.0' --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 ee7c3a4d-5305-46b1-807e-fa9f39a5d13e

        linux        /boot/vmlinuz-3.5.0 root=UUID=ee7c3a4d-5305-46b1-807e-fa9f39a5d13e ro   quiet splash $vt_handoff

        initrd        /boot/initrd.img-3.5.0

}

menuentry 'Ubuntu,Linux 3.5.0 (恢复模式)' --class ubuntu --class gnu-linux --class gnu --class os {

        recordfail

        insmod gzio

        insmod part_msdos

        insmod ext2

        set root='(hd0,msdos1)'

        search --no-floppy --fs-uuid --set=root ee7c3a4d-5305-46b1-807e-fa9f39a5d13e

        echo        '载入 Linux 3.5.0 ...'

        linux        /boot/vmlinuz-3.5.0 root=UUID=ee7c3a4d-5305-46b1-807e-fa9f39a5d13e ro recovery nomodeset

        echo        '载入初始化内存盘...'

        initrd        /boot/initrd.img-3.5.0

}

submenu "Previous Linux versions" {

menuentry 'Ubuntu,Linux 3.2.0-24-generic-pae' --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 ee7c3a4d-5305-46b1-807e-fa9f39a5d13e

        linux        /boot/vmlinuz-3.2.0-24-generic-pae root=UUID=ee7c3a4d-5305-46b1-807e-fa9f39a5d13e ro   quiet splash $vt_handoff

        initrd        /boot/initrd.img-3.2.0-24-generic-pae

}

menuentry 'Ubuntu,Linux 3.2.0-24-generic-pae (恢复模式)' --class ubuntu --class gnu-linux --class gnu --class os {

        recordfail

        insmod gzio

        insmod part_msdos

        insmod ext2

        set root='(hd0,msdos1)'

        search --no-floppy --fs-uuid --set=root ee7c3a4d-5305-46b1-807e-fa9f39a5d13e

        echo        '载入 Linux 3.2.0-24-generic-pae ...'

        linux        /boot/vmlinuz-3.2.0-24-generic-pae root=UUID=ee7c3a4d-5305-46b1-807e-fa9f39a5d13e ro recovery nomodeset

        echo        '载入初始化内存盘...'

        initrd        /boot/initrd.img-3.2.0-24-generic-pae

}

    默认是从新内核镜像启动系统。

    万事ok,敲下reboot,系统启动后,从grub菜单中选中新内核引导linux,怎么样,系统启动的鼓声响了吧!

    进入后用uname -a看看是否新内核。

11、删除旧内核文件


1,查看一下当前内核版本:uname -a
2.查看一下当前系统内的所有内核文件:dpkg --get-selections|grep linux
3.删除内核文件:
sudo apt-get remove linux-image-3.2.0-24*sudo apt-get remove linux-headers-3.2.0-24*或(删除当前版本之外的所有内核)sudo apt-get purge ~ilinux-image-.*\(\!`uname -r`\)
4.另外一条命令:
sudo aptitude purge ~ilinux-image-*\(\!'uname -r'\)
这样就成功删除了,重启一下看看是不是没有那些没用的内核启动项了。

完工

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值