Hello again, I've tested this patch on BIOS x86 (on a vm) and x86_64 EFI. Surely it does extra work, plenty of checks and string allocations are not needed at all, because it skips only calls that write files into grubdir or platdir (not macppcdir nor efidir).
What do you think? Refactoring the main method may help clarify the flow (checks for the actual hardware/partition configuration -> write files into grub's directory for boot, including early-boot related files -> platform dependant installation), but I'd like to hear some comments on the minimal change before moving code around. Happy hacking! Miguel
>From 1c6dd7b456d9efc6fdd30cc5c170817cddb361ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?= <rosen644...@gmail.com> Date: Mon, 28 Oct 2019 09:56:06 +0100 Subject: [PATCH 2/2] install: Add only-platform-installation option. * util/grub-install.c (only_platform_installation): New variable. (unnamed enum): Add OPTION_ONLY_PLATFORM_INSTALLATION. (argp_parser)<OPTION_NO_NVRAM, OPTION_NO_BOOTSECTOR>: Add check. <OPTION_ONLY_PLATFORM_INSTALLATION>: New case. (options): Add only-platform-installation option. (main): Do not write into grubdir and platdir when only-platform-installation option is seleted. --- util/grub-install.c | 105 ++++++++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 39 deletions(-) diff --git a/util/grub-install.c b/util/grub-install.c index 8f84bf8cd..2b446717e 100644 --- a/util/grub-install.c +++ b/util/grub-install.c @@ -79,6 +79,7 @@ static char *label_color; static char *label_bgcolor; static char *product_version; static int add_rs_codes = 1; +static int only_platform_installation = 0; enum { @@ -109,7 +110,8 @@ enum OPTION_LABEL_FONT, OPTION_LABEL_COLOR, OPTION_LABEL_BGCOLOR, - OPTION_PRODUCT_VERSION + OPTION_PRODUCT_VERSION, + OPTION_ONLY_PLATFORM_INSTALLATION }; static int fs_probe = 1; @@ -197,6 +199,9 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; case OPTION_NO_NVRAM: + if (only_platform_installation) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); update_nvram = 0; return 0; @@ -217,6 +222,9 @@ argp_parser (int key, char *arg, struct argp_state *state) return 0; case OPTION_NO_BOOTSECTOR: + if (only_platform_installation) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); install_bootsector = 0; return 0; @@ -233,6 +241,13 @@ argp_parser (int key, char *arg, struct argp_state *state) bootloader_id = xstrdup (arg); return 0; + case OPTION_ONLY_PLATFORM_INSTALLATION: + if (!install_bootsector && !update_nvram) + grub_util_error ("%s", _("Option --only-platform-installation is " + "incompatible with --no-bootsector/nvram.")); + only_platform_installation = 1; + return 0; + case ARGP_KEY_ARG: if (install_device) grub_util_error ("%s", _("More than one install device?")); @@ -275,6 +290,8 @@ static struct argp_option options[] = { {"disk-module", OPTION_DISK_MODULE, N_("MODULE"), 0, N_("disk module to use (biosdisk or native). " "This option is only available on BIOS target."), 2}, + {"only-platform-installation", OPTION_ONLY_PLATFORM_INSTALLATION, 0, 0, + N_("only perform the platform-dependant installation."), 0}, {"no-nvram", OPTION_NO_NVRAM, 0, 0, N_("don't update the `boot-device'/`Boot*' NVRAM variables. " "This option is only available on EFI and IEEE1275 targets."), 2}, @@ -533,7 +550,8 @@ probe_cryptodisk_uuid (grub_disk_t disk) free (list); list = tmp; } - if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID) + if (disk->dev->id == GRUB_DISK_DEVICE_CRYPTODISK_ID + && !only_platform_installation) { const char *uuid = grub_util_cryptodisk_get_uuid (disk); if (!load_cfg_f) @@ -1247,11 +1265,12 @@ main (int argc, char *argv[]) } } - grub_install_copy_files (grub_install_source_directory, - grubdir, platform); + if (!only_platform_installation) + grub_install_copy_files (grub_install_source_directory, + grubdir, platform); char *envfile = grub_util_path_concat (2, grubdir, "grubenv"); - if (!grub_util_is_regular (envfile)) + if (!grub_util_is_regular (envfile) && !only_platform_installation) grub_util_create_envblk_file (envfile); size_t ndev = 0; @@ -1343,9 +1362,10 @@ main (int argc, char *argv[]) load_cfg = grub_util_path_concat (2, platdir, "load.cfg"); - grub_util_unlink (load_cfg); + if (!only_platform_installation) + grub_util_unlink (load_cfg); - if (debug_image && debug_image[0]) + if (debug_image && debug_image[0] && !only_platform_installation) { load_cfg_f = grub_util_fopen (load_cfg, "wb"); have_load_cfg = 1; @@ -1375,7 +1395,7 @@ main (int argc, char *argv[]) } } - if (!have_abstractions) + if (!have_abstractions && !only_platform_installation) { if ((disk_module && grub_strcmp (disk_module, "biosdisk") != 0) || grub_drives[1] @@ -1418,8 +1438,9 @@ main (int argc, char *argv[]) grub_util_error (_("Can't create file: %s"), strerror (errno)); fclose (flf); relfl = grub_make_system_path_relative_to_its_root (fl); - fprintf (load_cfg_f, "search.file %s root ", - relfl); + if (!only_platform_installation) + fprintf (load_cfg_f, "search.file %s root ", + relfl); grub_install_push_module ("search_fs_file"); } for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, @@ -1534,7 +1555,7 @@ main (int argc, char *argv[]) prefix_drive = xasprintf ("(%s)", p); } } - else + else if (!only_platform_installation) { if (config.is_cryptodisk_enabled) { @@ -1628,44 +1649,48 @@ main (int argc, char *argv[]) core_name); char *prefix = xasprintf ("%s%s", prefix_drive ? : "", relative_grubdir); - grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, - /*prefix */ prefix, - /* output */ imgfile, - /* memdisk */ NULL, - have_load_cfg ? load_cfg : NULL, - /* image target */ mkimage_target, 0); + if (!only_platform_installation) + grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, + /*prefix */ prefix, + /* output */ imgfile, + /* memdisk */ NULL, + have_load_cfg ? load_cfg : NULL, + /* image target */ mkimage_target, 0); /* Backward-compatibility kludges. */ switch (platform) { case GRUB_INSTALL_PLATFORM_MIPSEL_LOONGSON: - { - char *dst = grub_util_path_concat (2, bootdir, "grub.elf"); - grub_install_copy_file (imgfile, dst, 1); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, bootdir, "grub.elf"); + grub_install_copy_file (imgfile, dst, 1); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_I386_IEEE1275: case GRUB_INSTALL_PLATFORM_POWERPC_IEEE1275: - { - char *dst = grub_util_path_concat (2, grubdir, "grub"); - grub_install_copy_file (imgfile, dst, 1); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, grubdir, "grub"); + grub_install_copy_file (imgfile, dst, 1); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_I386_EFI: case GRUB_INSTALL_PLATFORM_X86_64_EFI: - { - char *dst = grub_util_path_concat (2, platdir, "grub.efi"); - grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, - /* prefix */ "", - /* output */ dst, - /* memdisk */ NULL, - have_load_cfg ? load_cfg : NULL, - /* image target */ mkimage_target, 0); - free (dst); - } + if (!only_platform_installation) + { + char *dst = grub_util_path_concat (2, platdir, "grub.efi"); + grub_install_make_image_wrap (/* source dir */ grub_install_source_directory, + /* prefix */ "", + /* output */ dst, + /* memdisk */ NULL, + have_load_cfg ? load_cfg : NULL, + /* image target */ mkimage_target, 0); + free (dst); + } break; case GRUB_INSTALL_PLATFORM_ARM_EFI: case GRUB_INSTALL_PLATFORM_ARM64_EFI: @@ -1703,7 +1728,8 @@ main (int argc, char *argv[]) "boot.img"); char *boot_img = grub_util_path_concat (2, platdir, "boot.img"); - grub_install_copy_file (boot_img_src, boot_img, 1); + if (!only_platform_installation) + grub_install_copy_file (boot_img_src, boot_img, 1); grub_util_info ("%sgrub-bios-setup %s %s %s %s %s --directory='%s' --device-map='%s' '%s'", /* TRANSLATORS: This is a prefix in the log to indicate that usually @@ -1732,7 +1758,8 @@ main (int argc, char *argv[]) "boot.img"); char *boot_img = grub_util_path_concat (2, platdir, "boot.img"); - grub_install_copy_file (boot_img_src, boot_img, 1); + if (!only_platform_installation) + grub_install_copy_file (boot_img_src, boot_img, 1); grub_util_info ("%sgrub-sparc64-setup %s %s %s %s --directory='%s' --device-map='%s' '%s'", install_bootsector ? "" : "NOT RUNNING: ", -- 2.23.0
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel