How to properly use kexec with systemd on CentOS 7?

Matrix asked:

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?

My answer:

This is pretty straightforward.

First stage the kernel to be booted:

kexec -l /boot/vmlinuz-3.10.0-123.6.3.el7.x86_64 \
--initrd=/boot/initramfs-3.10.0-123.6.3.el7.x86_64.img \
--command-line="root=/dev/mapper/centos-root ro vconsole.font=latarcyrheb-sun16 crashkernel=auto  vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8"

These options having been swiped out of the generated grub configuration.

Now tell systemd to do its magic.

systemctl start

A few seconds later, you will be up in your new kernel.

I’ve recently written a distribution-agnostic script to help automate this (bug reports welcome).

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.