14

利用kexec快速切换内核

 3 years ago
source link: http://abcdxyzk.github.io/blog/2014/04/23/kernel-kexec-setup/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

利用kexec快速切换内核

2014-04-23 15:35:00

kexec是一个用于在当前系统下快速切换到另一个内核的一种办法,它采用了一定的机制略过了硬件的初始化,所以切换速度会很快。

自2.6.13以后,Linux内核就已经自置了kexec,而Debian采用的内核已经是2.6.26,而且默认就支持kexec,所以在Debian下我们只要安装kexec-tools就行了。

$ yum install kexec-tools
$ sudo apt-get install kexec-tools

安装好以后,就可以开始加载其他的内核了。
先看看我有哪些内核可以用:

$ ls /boot/vmlinuz-2.6.26-1-*
/boot/vmlinuz-2.6.26-1-amd64         
/boot/vmlinuz-2.6.26-1-vserver-amd64

好多好多,再看看当前的内核

$ uname -r
2.6.26-1-vserver-amd64

好了,现在我打算切换到2.6.26-1-amd64去:
记得,需要root权限的

$ sudo -s

先要用kexec加载它,先看看该追加哪些参数

$ cat /boot/grub/menu.lst | grep 2.6.26-1-amd64
title Debian GNU/Linux, kernel 2.6.26-1-amd64
kernel /vmlinuz-2.6.26-1-amd64 root=/dev/sda1 ro
initrd /initrd.img-2.6.26-1-amd64

找到了,对照上面开始用kexec加载了

$ kexec -l /boot/vmlinuz-2.6.26-1-amd64 --initrd=/boot/initrd.img-2.6.26-1-amd64 --append="root=/dev/sda1 ro"

加载以后并不直接执行哦,所以我们要执行一下才会切换

$ kexec -e

不要紧张,等一下下就好了,起来以后还会提示登录的
看看我的效果:

$ uname -r
2.6.26-1-amd64

切换到我想要的内核了


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK