[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v6 0/1] Add support for grub-emu to kexec Linux menu entries
From: |
Robbie Harwood |
Subject: |
[PATCH v6 0/1] Add support for grub-emu to kexec Linux menu entries |
Date: |
Mon, 24 Oct 2022 14:33:49 -0400 |
Address feedback from Daniel's third review (interdiff attached).
Be well,
--Robbie
Raymund Will (1):
Add support for grub-emu to kexec Linux menu entries
docs/grub.texi | 30 ++++--
grub-core/Makefile.am | 1 +
grub-core/Makefile.core.def | 2 +-
grub-core/kern/emu/main.c | 4 +
grub-core/kern/emu/misc.c | 18 +++-
grub-core/loader/emu/linux.c | 178 +++++++++++++++++++++++++++++++++++
include/grub/emu/exec.h | 4 +-
include/grub/emu/hostfile.h | 3 +-
include/grub/emu/misc.h | 3 +
9 files changed, 231 insertions(+), 12 deletions(-)
create mode 100644 grub-core/loader/emu/linux.c
Interdiff against v5:
diff --git a/docs/grub.texi b/docs/grub.texi
index 1463e62e6b..1663a076c0 100644
--- a/docs/grub.texi
+++ b/docs/grub.texi
@@ -1,4 +1,4 @@
-i\input texinfo
+\input texinfo
@c -*-texinfo-*-
@c %**start of header
@setfilename grub.info
@@ -962,11 +962,15 @@ information.
@node Kexec
@subsection Kexec with grub2-emu
-grub2 can be run in userspace by invoking the grub2-emu tool. It will
+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.
+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
diff --git a/grub-core/loader/emu/linux.c b/grub-core/loader/emu/linux.c
index f232f195b3..0cf378a376 100644
--- a/grub-core/loader/emu/linux.c
+++ b/grub-core/loader/emu/linux.c
@@ -38,8 +38,7 @@ grub_linux_boot (void)
{
grub_err_t rc = GRUB_ERR_NONE;
char *initrd_param;
- const char *kexec[] = {"kexec", "-la", kernel_path, boot_cmdline, NULL,
- NULL};
+ const char *kexec[] = {"kexec", "-la", kernel_path, boot_cmdline, NULL,
NULL};
const char *systemctl[] = {"systemctl", "kexec", NULL};
int kexecute = grub_util_get_kexecute ();
@@ -59,7 +58,7 @@ grub_linux_boot (void)
if (kexecute)
rc = grub_util_exec (kexec);
- grub_free(initrd_param);
+ grub_free (initrd_param);
if (rc != GRUB_ERR_NONE)
{
@@ -82,13 +81,12 @@ grub_linux_boot (void)
* WARNING: forcible reset should only be used in read-only environments.
* grub-emu cannot check for these - users beware.
*/
- grub_dprintf ("linux", "Performing 'kexec -e -x'");
- kexec[1] = "-e";
- kexec[2] = "-x";
- kexec[3] = NULL;
+ grub_dprintf ("linux", "Performing 'kexec -ex'");
+ kexec[1] = "-ex";
+ kexec[2] = NULL;
rc = grub_util_exec (kexec);
- if ( rc != GRUB_ERR_NONE )
- grub_fatal (N_("error trying to directly perform 'kexec -e': %d"), rc);
+ if (rc != GRUB_ERR_NONE)
+ grub_fatal (N_("error trying to directly perform 'kexec -ex': %d"), rc);
return rc;
}
@@ -129,7 +127,7 @@ grub_cmd_linux (grub_command_t cmd __attribute__
((unused)), int argc,
if (argc > 1)
{
boot_cmdline = grub_xasprintf ("--command-line=%s", argv[1]);
- for ( i = 2; i < argc; i++ )
+ for (i = 2; i < argc; i++)
{
tempstr = grub_xasprintf ("%s %s", boot_cmdline, argv[i]);
grub_free (boot_cmdline);
@@ -154,7 +152,7 @@ grub_cmd_initrd (grub_command_t cmd __attribute__
((unused)), int argc,
N_("Cannot find initrd file %s"), argv[0]);
grub_free (initrd_path);
- initrd_path = grub_xasprintf("%s", argv[0]);
+ initrd_path = grub_xasprintf ("%s", argv[0]);
/* We are done - mark ourselves as on longer in use. */
grub_dl_unref (my_mod);
@@ -171,9 +169,6 @@ GRUB_MOD_INIT (linux)
cmd_initrd = grub_register_command ("initrd", grub_cmd_initrd, 0,
N_("Load initrd."));
my_mod = mod;
- kernel_path = NULL;
- initrd_path = NULL;
- boot_cmdline = NULL;
}
GRUB_MOD_FINI (linux)
--
2.35.1
- [PATCH v6 0/1] Add support for grub-emu to kexec Linux menu entries,
Robbie Harwood <=