问题原文
原帖链接 · Matrix · CC BY-SA 3.0
I want to use kexec to speed up reboots of my CentOS 7 machine. How can I do that in a way that nicely integrates with existing shutdown/reboot systemd targets? What's the proper (official) way to do this?
已采纳解答
原帖链接 · Matrix · CC BY-SA 3.0
I figured out a way to make a kexec loading script that works well and will load the default kernel in grub, meaning it should load the new kernel after a kernel update.
File: /usr/bin/kexec-load
#!/usr/bin/env bash
GRUBBY_FILE="/var/log/grubby"
TMP=$(mktemp)
# Command "grubby --default-kernel" has a bug/feature that fsyncs
# after writting each line to a debug log file, making it slow (several seconds).
# Workaround is to write to /dev/null instead.
if [ -e $GRUBBY_FILE ]
then rm -f $GRUBBY_FILE
fi
ln -s /dev/null $GRUBBY_FILE
KERNEL_IMG=$(grubby --default-kernel)
unlink $GRUBBY_FILE
# Get the detailed information of the default kernel (as seen by grub)
# This will create a temporary file in /tmp
grubby --info=$KERNEL_IMG | grep -v title > $TMP
source $TMP
rm $TMP
# Simple log to see if this script gets executed
date --rfc-3339=seconds >> /var/log/kexec
# Load (prepare) the kernel for execution
kexec -l $kernel --initrd=$initrd --command-line="root=$root $args"
File: /etc/systemd/system/kexec-load.service
[Unit]
Description=loads the kernel
Documentation=man:kexec(8)
DefaultDependencies=no
Before=shutdown.target umount.target final.target
[Service]
Type=oneshot
ExecStart=/usr/bin/kexec-load
[Install]
WantedBy=kexec.target
$ chmod +x /usr/bin/kexec-load
$ systemctl enable kexec-load.service
$ systemctl kexec
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
