我想用kexec来加速我的CentOS 7机器的重启.如何以与现有关机/重启系统目标完美集成的方式实现这一目标?这样做的正确(官方)方法是什么?
我找到了一种方法来制作一个运行良好的kexec加载脚本并将在grub中加载默认内核,这意味着它应该在内核更新后加载新内核.
原文链接:https://www.f2er.com/centos/373956.htmlFile: /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