kexec使用Unix系统调用exec()的覆盖哲理,它产生一个新的内核覆盖正在运行的内核。这个过程不用启动机器上的固件(firmware),所以可以节省一些重启时间。
因为启动固件需要走查总线和标识设备,节省了这些时间就会加速系统的启动。
知道了这些就解决一下我的系统不能重启的问题吧,如图:
怎么会启动不了呢?
1.grep一下/etc目录
apple@Ubuntu:~$ sudo grep -r kexec /etc
grep: /etc/alternatives/smbstatus.1.gz: No such file or directory
/etc/rc6.d/K18kexec-load:# Provides: kexec-load
/etc/rc6.d/K18kexec-load:# Required-Stop: $remote_fs kexec
/etc/rc6.d/K18kexec-load:# Short-Description: Load kernel image with kexec
/etc/rc6.d/K18kexec-load:test -r /etc/default/kexec && . /etc/default/kexec
/etc/rc6.d/K18kexec-load: test -x /sbin/kexec || exit 0
/etc/rc6.d/K18kexec-load: test “x`cat /sys/kernel/kexec_loaded`y” = “x1y” && exit 0
/etc/rc6.d/K18kexec-load: kexec -l “$KERNEL_IMAGE” –append=”$REAL_APPEND”
/etc/rc6.d/K18kexec-load: kexec -l “$KERNEL_IMAGE” –initrd=”$INITRD” –append=”$REAL_APPEND”
/etc/rc6.d/S85kexec:# Provides: kexec
/etc/rc6.d/S85kexec:# Short-Description: Execute the kexec -e command to reboot system
/etc/rc6.d/S85kexec:test -r /etc/default/kexec && . /etc/default/kexec
/etc/rc6.d/S85kexec: test “x`cat /sys/kernel/kexec_loaded`y” = “x1y” || exit 0
/etc/rc6.d/S85kexec: test -x /sbin/kexec || exit 0
/etc/rc6.d/S85kexec: log_action_msg “Will now restart with kexec”
/etc/rc6.d/S85kexec: kexec -e
/etc/rc6.d/S85kexec: log_failure_msg “kexec failed”
/etc/rc6.d/S60umountroot:# Should-Stop: halt reboot kexec
/etc/init.d/kexec-load:# Provides: kexec-load
/etc/init.d/kexec-load:# Required-Stop: $remote_fs kexec
/etc/init.d/kexec-load:# Short-Description: Load kernel image with kexec
/etc/init.d/kexec-load:test -r /etc/default/kexec && . /etc/default/kexec
/etc/init.d/kexec-load: test -x /sbin/kexec || exit 0
/etc/init.d/kexec-load: test “x`cat /sys/kernel/kexec_loaded`y” = “x1y” && exit 0
/etc/init.d/kexec-load: kexec -l “$KERNEL_IMAGE” –append=”$REAL_APPEND”
/etc/init.d/kexec-load: kexec -l “$KERNEL_IMAGE” –initrd=”$INITRD” –append=”$REAL_APPEND”
/etc/init.d/kexec:# Provides: kexec
/etc/init.d/kexec:# Short-Description: Execute the kexec -e command to reboot system
/etc/init.d/kexec:test -r /etc/default/kexec && . /etc/default/kexec
/etc/init.d/kexec: test “x`cat /sys/kernel/kexec_loaded`y” = “x1y” || exit 0
/etc/init.d/kexec: test -x /sbin/kexec || exit 0
/etc/init.d/kexec: log_action_msg “Will now restart with kexec”
/etc/init.d/kexec: kexec -e
/etc/init.d/kexec: log_failure_msg “kexec failed”
/etc/init.d/umountroot:# Should-Stop: halt reboot kexec
/etc/init.d/kdump:# Short-Description: Load crashkernel image with kexec
/etc/init.d/kdump: test -x /sbin/kexec || exit 0
/etc/init.d/kdump: kexec -p “$KERNEL_IMAGE” –initrd=”$INITRD” –append=”$APPEND”
/etc/rc2.d/S00kdump:# Short-Description: Load crashkernel image with kexec
/etc/rc2.d/S00kdump: test -x /sbin/kexec || exit 0
/etc/rc2.d/S00kdump: kexec -p “$KERNEL_IMAGE” –initrd=”$INITRD” –append=”$APPEND”
/etc/default/kexec:# Defaults for kexec initscript
/etc/default/kexec:# sourced by /etc/init.d/kexec and /etc/init.d/kexec-load
/etc/default/kexec:# Load a kexec kernel (true/false)
/etc/rc0.d/S60umountroot:# Should-Stop: halt reboot kexec
apple@ubuntu:~$
看来系统重启需要借用/etc/init.d/kexec这个脚本
2.查看/etc/default/kexec文件
apple@Ubuntu:~$ cat /etc/init.d/kexec
#! /bin/sh
### BEGIN INIT INFO
# Provides: kexec
# Required-Start:
# Required-Stop: reboot
# X-Stop-After: umountroot
# Default-Start:
# Default-Stop: 6
# Short-Description: Execute the kexec -e command to reboot system
# Description:
### END INIT INFO
PATH=/usr/sbin:/usr/bin:/sbin:/bin
. /lib/lsb/init-functions
test -r /etc/default/kexec && . /etc/default/kexec
do_stop () {
test “x`cat /sys/kernel/kexec_loaded`y” = “x1y” || exit 0
test -x /sbin/kexec || exit 0
log_action_msg “Will now restart with kexec”
kexec -e
log_failure_msg “kexec failed”
}
case “$1” in
start)
# No-op
;;
restart|reload|force-reload)
echo “Error: argument ‘$1’ not supported” >&2
exit 3
;;
stop)
do_stop
;;
*)
echo “Usage: $0 start|stop” >&2
exit 3
;;
esac
exit 0
apple@ubuntu:~$
/etc/init.d/kexec脚本使用了/etc/default/kexec中的配置,查看/etc/default/kexec
apple@ubuntu:/$ cat /etc/default/kexec
# Defaults for kexec initscript
# sourced by /etc/init.d/kexec and /etc/init.d/kexec-load
# Load a kexec kernel (true/false)
LOAD_KEXEC=true
# Kernel and initrd image
KERNEL_IMAGE=”/vmlinuz”
INITRD=”/initrd.img”
# If empty, use current /proc/cmdline
APPEND=””
apple@ubuntu:/$ cat /etc/default/kexec
# Defaults for kexec initscript
# sourced by /etc/init.d/kexec and /etc/init.d/kexec-load
# Load a kexec kernel (true/false)
LOAD_KEXEC=true
# Kernel and initrd image
KERNEL_IMAGE=”/vmlinuz”
INITRD=”/initrd.img”
# If empty, use current /proc/cmdline
APPEND=””
原来这个/etc/default/kexec是配置重启过程中kexec的参数的
3.修改/vmlinuz /initrd.img符号链接,查看这两个符号链接:
lrwxrwxrwx 1 root root 30 Oct 16 00:43 vmlinuz -> /boot/vmlinuz-2.6.28-17-server
lrwxrwxrwx 1 root root 33 Oct 16 00:44 initrd.img -> /boot/initrd.img-2.6.28-17-server
原来装的内核太多了,这两个符号链接链接到错误的内核版本。
修正这个问题内核就可以正常重启了
apple@Ubuntu:/$ sudo rm /vmlinuz
apple@ubuntu:/$ sudo rm /initrd.img
apple@ubuntu:/$ sudo ln -s /boot/vm
vmcoreinfo-2.6.28-11-server vmcoreinfo-2.6.28-3-rt vmlinuz-2.6.28-17-generic vmlinuz-2.6.28-3-rt
vmcoreinfo-2.6.28-17-generic vmlinuz-2.6.28-11-server vmlinuz-2.6.28-17-server
apple@ubuntu:/$ sudo ln -s /boot/vmlinuz-2.6.28-11-server vmlinuz
apple@ubuntu:/$ sudo ln -s /boot/initrd.img-2.6.28-11-server initrd.img
apple@ubuntu:/$