Shortening reboot times with kexec - TAM Tip
Hi all,
I just thought I'd share this great performance tip from one of our Technical Account Managers (TAMs):
Have you ever been fustrated by long reboot times when doing things like testing with different kernels, configurations, and so on?
The system just takes too long to restart in the BIOS!
Here comes kexec to the rescue!
How does that work? First you load the kernel that you want to boot and keep it in memory. You can just load it and leave it ready to restart. When your system is told to restart, after stopping and unmounting stuff, instead of restarting and going to BIOS tests, init will call kexec and start the kernel load, shortening your reboot time.
How to use it:
A. Specifying a specific kernel, initrd & cmdline:
# kexec -l /boot/vmlinuz- --initrd=/boot/ \
--append=$cmdline
B. Using current kernel:
B.1) For RHEL5:
# cmdline=`cat /proc/cmdline` ; krnl=`uname -r` ; \
kexec -l /boot/vmlinuz-$krnl --initrd=/boot/initrd-"$krnl".img \
--append=$cmdlineB.2) For RHEL6:
# krnl=`uname -r` ; kexec -l /boot/vmlinuz-$krnl \
--initrd=/boot/initramfs-"$krnl".img --reuse-cmdline
C. And then, restart your system:
# reboot
Just after the system shuts down, the new kernel will be immediately loaded!
If you've got any useful tips, don't hesitate to share them with the community!
Responses
Ok, so that's amazingly useful - especially for hardware-based hosts. Our HP DL servers take upwards of 15 minutes to reboot when you factor in all the POSTing type activities that the standard BIOS settings do. This cuts off a good 10+ minutes from that kind of reboot.
Thanks a lot for the tip!
Hi David, thanks for sharing this tip to us! I find it is very useful in my environment with HP ProLiant Servers.
For the RHEL 6 in step B.2, I got the error of "kexec: option '--reuse=' is ambiguous when I executed it. I think it should be --reuse-cmdline instead. Just want to share my experience with the group.
Example:
# krnl=`uname -r` ; kexec -l /boot/vmlinuz-$krnl --initrd=/boot/initramfs-"$krnl".img --reuse-cmdline
Startup time should be faster than now, but it will depend on the system configuration, and which services are started.
Using recent Fedora releases and systemd, some people have gotten their boot times down to under 10 seconds. But, they use SSDs to speed disk access, disable most services, and don't use lvm.
All of those things lessen boot times, but there is value in lvm, and on a server I typically need to run quite a few services.
The steps listed for RHEL5 could present a problem. Make sure to use quotes properly so kexec's append option sees the full kernel cmdline instead of just the first argument, e.g.:
kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initrd-$(uname -r).img --append="$(</proc/cmdline)"
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
