Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1on2H4-0000lj-Ri for mharc-grub-devel@gnu.org; Mon, 24 Oct 2022 14:34:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on2Gy-0000lE-2s for grub-devel@gnu.org; Mon, 24 Oct 2022 14:34:04 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1on2Gw-0000vz-9g for grub-devel@gnu.org; Mon, 24 Oct 2022 14:34:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666636440; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=g5DwOVfrZZAMiNPP2DSiqp6QCvB42lugzvRkd9rTSsM=; b=PnK9V+i9zVdyAqeOiGuG06jrPTc89ebbfFtjOIvTwatYwJ/bxG5aavgp32LrmyY2RqdXs3 bBlSxkDuTMavfVCc0SlQ/yBv49XC/QtwJuixEfyODTPuqCcHWt0NB4tQAZHZDaZboOpqZb uvA3uZBhsJDpjlZJqIkBCZaA1GJLN9c= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-298-mQrXSiZUO1K21Y0dal0fMg-1; Mon, 24 Oct 2022 14:33:57 -0400 X-MC-Unique: mQrXSiZUO1K21Y0dal0fMg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C4DA5833AEF; Mon, 24 Oct 2022 18:33:56 +0000 (UTC) Received: from eesha.redhat.com (unknown [10.22.18.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5ED5935429; Mon, 24 Oct 2022 18:33:56 +0000 (UTC) From: Robbie Harwood To: grub-devel@gnu.org Cc: Robbie Harwood , dkiper@net-space.pl, xxc3ncoredxx@gmail.com Subject: [PATCH v6 0/1] Add support for grub-emu to kexec Linux menu entries Date: Mon, 24 Oct 2022 14:33:49 -0400 Message-Id: <20221024183350.72329-1-rharwood@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Received-SPF: pass client-ip=170.10.133.124; envelope-from=rharwood@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Oct 2022 18:34:04 -0000 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