Kexec: Difference between revisions
m (→Usage: And AFAIK it can't be reliably scripted... But...) |
(Automagic kexec!) |
||
Line 5: | Line 5: | ||
==Usage== | ==Usage== | ||
On a typical Alpine setup, it can be used | ===Manually=== | ||
On a typical Alpine setup, it can be used via: | |||
{{Cmd|# kexec -l /boot/vmlinuz-edge --initrd \ | {{Cmd|# kexec -l /boot/vmlinuz-edge --initrd \ | ||
Line 14: | Line 15: | ||
There are no Alpine-specific considerations for Kexec. Please review the man page and existing references below for more details. This page is deliberately kept short in order to avoid duplicating existing documentation. | There are no Alpine-specific considerations for Kexec. Please review the man page and existing references below for more details. This page is deliberately kept short in order to avoid duplicating existing documentation. | ||
===Automatically on every reboot/shutdown=== | |||
kexec can be set to run automatically for faster rebooting. This is very useful on servers. | |||
First create two openrc services and edit the <code>BOOTPART</code>, <code>KERNEL</code>, and <code>INITRD</code> variables if not using the defaults: | |||
{{cat|/etc/init.d/kexec-load|<nowiki>#!/sbin/openrc-run | |||
description="kexec for faster reboot" | |||
# Define defaults | |||
: "${BOOTPART:=/boot}" | |||
: "${KERNEL:=vmlinuz-edge}" | |||
: "${INITRD:=initramfs-edge}" | |||
depend() { | |||
need localmount | |||
} | |||
start() { | |||
: | |||
} | |||
stop() { | |||
ebegin "kexec: loading kernel for faster reboot" | |||
kexec -l "${BOOTPART}/${KERNEL}" \ | |||
--initrd "${BOOTPART}/${INITRD}" \ | |||
--reuse-cmdline | |||
ewend $? Failed. | |||
}</nowiki>}} | |||
{{cat|/etc/init.d/kexec-exec|<nowiki>#! /sbin/openrc-run | |||
description="kexec for faster reboot" | |||
depend() { | |||
after killprocs savecache mount-ro | |||
} | |||
start() { | |||
ebegin "Using kexec for faster reboot" | |||
kexec -e | |||
ewend $? No kernel loaded. | |||
return 0 | |||
}</nowiki>}} | |||
Now give these services execute permission and assign them to the appropriate runlevels: | |||
{{cmd|chmod a+x /etc/init.d/kexec-load | |||
chmod a+x /etc/init.d/kexec-exec | |||
rc-update add kexec-load default | |||
rc-update add kexec-exec shutdown}} | |||
Reboot and enjoy! | |||
{{Note|With both of the above service enabled, it's difficult to poweroff the system as it will reboot unless an unsafe shutdown with <code>poweroff -f</code> is used... To get around this temporarily disable either one of the services (e.g. <code>rc-update del kexec-load default</code>)}} | |||
== See also == | == See also == | ||
Revision as of 18:47, 5 September 2023
Kexec is a system call that enables loading and booting into another kernel. This is useful for faster reboots that skip the BIOS or UEFI initialisation process.
Installing kexec-tools
The userspace tools required to use it can be installed via
apk add kexec-tools kexec-tools-doc
The tools are not available on all flavors of Alpine, additionally not all kernels are compiled with the kexec syscall enabled. You will most likely want to check your /boot/config-* file for CONFIG_KEXEC=y
Usage
Manually
On a typical Alpine setup, it can be used via:
# kexec -l /boot/vmlinuz-edge --initrd \ /boot/initramfs-edge --reuse-cmdline \ && openrc shutdown # kexec -e
There are no Alpine-specific considerations for Kexec. Please review the man page and existing references below for more details. This page is deliberately kept short in order to avoid duplicating existing documentation.
Automatically on every reboot/shutdown
kexec can be set to run automatically for faster rebooting. This is very useful on servers.
First create two openrc services and edit the BOOTPART
, KERNEL
, and INITRD
variables if not using the defaults:
Contents of /etc/init.d/kexec-load
Contents of /etc/init.d/kexec-exec
Now give these services execute permission and assign them to the appropriate runlevels:
chmod a+x /etc/init.d/kexec-load chmod a+x /etc/init.d/kexec-exec rc-update add kexec-load default rc-update add kexec-exec shutdown
Reboot and enjoy!
poweroff -f
is used... To get around this temporarily disable either one of the services (e.g. rc-update del kexec-load default
)