码迷,mamicode.com
首页 > 系统相关 > 详细

Linux系统的快速启动机制(内核切换) 【转】

时间:2015-11-11 19:20:57      阅读:315      评论:0      收藏:0      [点我收藏+]

标签:

转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=26807463&id=4187846

 

快速启动机制:允许通过已经运行的Linux内核的上下文启动另一个Linux内核,不需要经过BIOS。BIOS可能会消耗很多时间,特别是带有众多数量的外设的大型服务器。这种办法可以为经常启动机器的开发者节省很多时间。

1.使用该机制要满足两个基本条件
1)内核版本必需为2.6.13以上,因为自该版本起,linux内核中加入了kexec system call模块。
2)系统需要安装 kexec-tools工具,提供用户空间的kexec命令。
    $sudo apt-get install kexec-tools

2.如何配置快速启动机制
1)确定正在运行的内核是否已经选中支持kexec system call
    $grep -F CONFIG_KEXEC /boot/config-`uname -r`
如果返回值是CONFIG_KEXEC=y,则表示支持。如果是CONFIG_KEXEC=n,则需要重新编译内核,将该项选为y。
2)配置内核
    $sudo make menuconfig,
    #进入Processor type and features ,然后在kexec system call选项处按y即可。
3)编译内核 
    $sudo make 
4)把内核装到/lib/modules/下
    $sudo make modules_install
5)执行该命令后,会在/boot/下生成内核映像和文件系统
    $sudo make install
在sudo make install后,/boot/grub/grub.cfg文件已经被更新,显示如下:
menuentry ‘Ubuntu,Linux 3.2.0-60-generic‘ --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    gfxmode $linux_gfx_mode
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root=‘(hd0,msdos7)‘
    search --no-floppy --fs-uuid --set=root 7883ab54-521c-444d-b59f-32c08a843e3a
    linux    /boot/vmlinuz-3.2.0-60-generic root=UUID=7883ab54-521c-444d-b59f-32c08a843e3a ro   crashkernel=384M-2G:64M,2G-:128M quiet splash $vt_handoff
    initrd    /boot/initrd.img-3.2.0-60-generic
}
menuentry ‘Ubuntu, with Linux 3.2.0-60-generic (recovery mode)‘ --class ubuntu --class gnu-linux --class gnu --class os {
    recordfail
    insmod gzio
    insmod part_msdos
    insmod ext2
    set root=‘(hd0,msdos7)‘
    search --no-floppy --fs-uuid --set=root 7883ab54-521c-444d-b59f-32c08a843e3a
    echo    ‘载入 Linux 3.2.0-60-generic ...‘
    linux    /boot/vmlinuz-3.2.0-60-generic root=UUID=7883ab54-521c-444d-b59f-32c08a843e3a ro recovery nomodeset 
    echo    ‘载入初始化内存盘...‘
    initrd    /boot/initrd.img-3.2.0-60-generic
}

3.kexec装载内核的语法如下:
kexec -l --append="" --initrd=
说明:
是要重新启动后的内核文件
是要传递到新内核的命令行参数。为确保合法值传递到重新启动的内核,安全方法是传递/proc/cmdline的内容。
是新内核使用的文件系统
例如:
原内核映像(正在运行的内核)/boot/vmlinuz-3.2.0-24-generic
原文件系统(正在运行的文件系统)/boot/initrd.img-3.2.0-24-generic
新内核映像(要加载的内核)/boot/vmlinuz-3.2.0-60-generic
新文件系统(要加载的文件系统)/boot/initrd.img-3.2.0-60-generic
1)装载内核的命令:
    $sudo kexec -l /boot/vmlinuz-3.2.0-60-generic --append="`cat /proc/cmdline`" --initrd=/boot/initrd.img-3.2.0-60-generic
2)重启已装载的内核:
    $sudo kexec -e
系统将立即重新启动。不同于正常的重新启动过程,在重新启动之前,kexec 不去执行彻底停止系统。需要您在尝试进行 kexec 重新启动之前去杀死所有应用程序并加载文件系统。

4.补充
新加载的内核可以是当前内核本身/boot/vmlinuz-3.2.0-24-generic,这样可以不停的加载切换。如果加载的是没有编入kexec system call的内核,那么切换之后就不能再次切换了,因为正在运行的内核不支持kexec。

Linux系统的快速启动机制(内核切换) 【转】

标签:

原文地址:http://www.cnblogs.com/sky-heaven/p/4956725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!