loader: Add support for grub-emu to kexec Linux menu entries

The GRUB emulator is used as a debugging utility but it could also be
used as a user-space bootloader if there is support to boot an operating
system.

The Linux kernel is already able to (re)boot another kernel via the
kexec boot mechanism. So the grub-emu tool could rely on this feature
and have linux and initrd commands that are used to pass a kernel,
initramfs image and command line parameters to kexec for booting
a selected menu entry.

By default the systemctl kexec option is used so systemd can shutdown
all of the running services before doing a reboot using kexec. But if
this is not present, it can fall back to executing the kexec user-space
tool directly. The ability to force a kexec-reboot when systemctl kexec
fails must only be used in controlled environments to avoid possible
filesystem corruption and data loss.

Signed-off-by: Raymund Will <rw@suse.com>
Signed-off-by: John Jolly <jjolly@suse.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Raymund Will authored and Daniel Kiper committed 2022-11-14 17:13:24 +01:00
1 parent 62037e01b2
commit e364307f6a
9 files changed
+231 -12

No files matched your search

+22 -8
View File
@@ -923,17 +923,17 @@ magic.
@node General boot methods
@section How to boot operating systems
GRUB has two distinct boot methods. One of the two is to load an
operating system directly, and the other is to chain-load another boot
loader which then will load an operating system actually. Generally
speaking, the former is more desirable, because you don't need to
install or maintain other boot loaders and GRUB is flexible enough to
load an operating system from an arbitrary disk/partition. However,
the latter is sometimes required, since GRUB doesn't support all the
existing operating systems natively.
GRUB has three distinct boot methods: loading an operating system
directly, using kexec from userspace, and chainloading another
bootloader. Generally speaking, the first two are more desirable
because you don't need to install or maintain other boot loaders and
GRUB is flexible enough to load an operating system from an arbitrary
disk/partition. However, chainloading is sometimes required, as GRUB
doesn't support all existing operating systems natively.
@menu
* Loading an operating system directly::
* Kexec::
* Chain-loading::
@end menu
@@ -959,6 +959,20 @@ use more complicated instructions. @xref{DOS/Windows}, for more
information.
@node Kexec
@subsection Kexec with grub2-emu
GRUB can be run in userspace by invoking the grub2-emu tool. It will
read all configuration scripts as if booting directly (see @xref{Loading
an operating system directly}). With the @code{--kexec} flag, and
kexec(8) support from the operating system, the @command{linux} command
will directly boot the target image. For systems that lack working
systemctl(1) support for kexec, passing the @code{--kexec} flag twice
will fallback to invoking kexec(8) directly; note however that this
fallback may be unsafe outside read-only environments, as it does not
invoke shutdown machinery.
@node Chain-loading
@subsection Chain-loading an OS