Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oycPR-0000HW-0i for mharc-grub-devel@gnu.org; Fri, 25 Nov 2022 12:22:41 -0500 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 1oycPP-0000D3-GB for grub-devel@gnu.org; Fri, 25 Nov 2022 12:22:39 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oycPM-0001EP-BV for grub-devel@gnu.org; Fri, 25 Nov 2022 12:22:39 -0500 Received: by mail-wr1-x432.google.com with SMTP id b12so7766256wrn.2 for ; Fri, 25 Nov 2022 09:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo.ie; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rKGRMPT3yaGFSX5t29ttM3w9aXhWo2JBzJeEHCG3Qv8=; b=P3IQPDEpn32I2AbWyq5NTlB+DJmEYFm5tsdsm9bTP5yxG5djvj+7AURU0RhyskKgt1 E12CpVibG2OR6lA5FC6yvZlnRT4pEEybRWHhO8l8nlRwLnbTX7XyVGPHpSPL9FwHYQwW DEWpj1AkkWoWC/qB1Fb/5v3tV0svKo08bJyDs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rKGRMPT3yaGFSX5t29ttM3w9aXhWo2JBzJeEHCG3Qv8=; b=WpoKEas0Yxo6KHEdmFYUmfbwHRCDXbbMoe6F41Dh6VvaFK3gpD63/ttkGkobtw0TJC NVIn4exqs00gLz4oWtx6qMWYhVxzwTBzEQAROAZ4oyM5dFF1IfsrO9toc1SlZWFoMME0 2ZiPut72uAJPsBozz/YVmLIIx6zljxY03B4HewlJ/kL/oLQ1P5MLmat4ZzlY7oXo/Uxv 6wC4Ufn7szdQulWE0/hm157dgrYv5n9YrrVZi1obVIJK0sSMpS9xa7bwbX4+QezTWCTF k7WZ3RcxAuYaLOCBkKTwM4M8xUbb03TGzzasVXeDTDkLc2cmfJ2W45PbGnCwqogAPt4F ZsPg== X-Gm-Message-State: ANoB5plwi01smWCvKHm9/kSGazbBZGIJnvmpL3HtccVwGe28oFVF08Ax 0fTmtD4x+EU+kkdaEsLBuviMK9XMYLFP2mBv X-Google-Smtp-Source: AA0mqf5gZzpfE7OTz+XprNOHAWoBtjCvw+Ir/FI++YdKvVZUVAGtKTjSyOXt/Eej3qg6rx2JojvV/g== X-Received: by 2002:a5d:65ce:0:b0:241:e1c3:caaa with SMTP id e14-20020a5d65ce000000b00241e1c3caaamr12209873wrw.458.1669396955016; Fri, 25 Nov 2022 09:22:35 -0800 (PST) Received: from localhost.localdomain (ip-84-203-35-79.broadband.digiweb.ie. [84.203.35.79]) by smtp.gmail.com with ESMTPSA id u13-20020a5d514d000000b002365b759b65sm4166324wrt.86.2022.11.25.09.22.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 09:22:34 -0800 (PST) From: Pete Batard To: grub-devel@gnu.org Cc: Pete Batard Subject: [PATCH v2 3/3] grub-mkrescue: Search by file UUID file rather than partition UUID for EFI boot Date: Fri, 25 Nov 2022 17:22:17 +0000 Message-Id: <20221125172217.936-4-pete@akeo.ie> X-Mailer: git-send-email 2.36.0.windows.1 In-Reply-To: <20221125172217.936-1-pete@akeo.ie> References: <20221125172217.936-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=pete@akeo.ie; helo=mail-wr1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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: Fri, 25 Nov 2022 17:22:39 -0000 The final piece needed to add UEFI file system transposition support is to ensure the boot media can be located regardless of how the boot partition was instantiated. Especially, we do not want to be reliant on brittle partition UUIDs, as these only work if a boot media is duplicated at the block level and not at the file system level. To accomplish this for EFI boot, we now create a UUID file in a .disk/ directory, that can then be searched for. Note: The switch from make_image_fwdisk_abs() to make_image_abs() is needed in order to use the search functionality. Signed-off-by: Pete Batard --- util/grub-mkrescue.c | 47 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c index 4596f0ea7..fcb72609b 100644 --- a/util/grub-mkrescue.c +++ b/util/grub-mkrescue.c @@ -261,7 +261,26 @@ make_image_abs (enum grub_install_plat plat, load_cfg = grub_util_make_temporary_file (); load_cfg_f = grub_util_fopen (load_cfg, "wb"); - fprintf (load_cfg_f, "search --fs-uuid --set=root %s\n", iso_uuid); + /* + * A UEFI bootable media should support file system transposition (e.g. extracting + * an ISO9660 content to a FAT32 media that was formatted by the user). Therefore, + * for EFI platforms, we search for a specific UUID file rather than a partition UUID. + */ + switch (plat) + { + case GRUB_INSTALL_PLATFORM_I386_EFI: + case GRUB_INSTALL_PLATFORM_X86_64_EFI: + case GRUB_INSTALL_PLATFORM_IA64_EFI: + case GRUB_INSTALL_PLATFORM_ARM_EFI: + case GRUB_INSTALL_PLATFORM_ARM64_EFI: + case GRUB_INSTALL_PLATFORM_RISCV32_EFI: + case GRUB_INSTALL_PLATFORM_RISCV64_EFI: + fprintf (load_cfg_f, "search --set=root --file /.disk/%s.uuid\n", iso_uuid); + break; + default: + fprintf (load_cfg_f, "search --set=root --fs-uuid %s\n", iso_uuid); + break; + } fprintf (load_cfg_f, "set prefix=(${root})/boot/grub\n"); write_part (load_cfg_f, source_dirs[plat]); @@ -745,10 +764,11 @@ main (int argc, char *argv[]) || source_dirs[GRUB_INSTALL_PLATFORM_RISCV32_EFI] || source_dirs[GRUB_INSTALL_PLATFORM_RISCV64_EFI]) { + FILE *f; char *efidir_efi = grub_util_path_concat (2, iso9660_dir, "efi"); char *efidir_efi_boot = grub_util_path_concat (3, iso9660_dir, "efi", "boot"); char *imgname, *img32, *img64, *img_mac = NULL; - char *efiimgfat; + char *efiimgfat, *iso_uuid_file, *diskdir, *diskdir_uuid; grub_install_mkdir_p (efidir_efi_boot); grub_install_push_module ("part_gpt"); @@ -757,36 +777,47 @@ main (int argc, char *argv[]) /* Many modern UEFI systems also have native support for NTFS */ grub_install_push_module ("ntfs"); + /* Create a '.disk/.uuid' file that can be used to locate the boot media. */ + diskdir = grub_util_path_concat (2, iso9660_dir, ".disk"); + grub_install_mkdir_p (diskdir); + iso_uuid_file = xasprintf ("%s.uuid", iso_uuid); + diskdir_uuid = grub_util_path_concat (2, diskdir, iso_uuid_file); + f = grub_util_fopen (diskdir_uuid, "wb"); + fclose (f); + free (iso_uuid_file); + free (diskdir_uuid); + free (diskdir); + imgname = grub_util_path_concat (2, efidir_efi_boot, "bootia64.efi"); make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_IA64_EFI, "ia64-efi", imgname); free (imgname); grub_install_push_module ("part_apple"); img64 = grub_util_path_concat (2, efidir_efi_boot, "bootx64.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", img64); + make_image_abs (GRUB_INSTALL_PLATFORM_X86_64_EFI, "x86_64-efi", img64); grub_install_pop_module (); grub_install_push_module ("part_apple"); img32 = grub_util_path_concat (2, efidir_efi_boot, "bootia32.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", img32); + make_image_abs (GRUB_INSTALL_PLATFORM_I386_EFI, "i386-efi", img32); grub_install_pop_module (); imgname = grub_util_path_concat (2, efidir_efi_boot, "bootarm.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi", imgname); + make_image_abs (GRUB_INSTALL_PLATFORM_ARM_EFI, "arm-efi", imgname); free (imgname); imgname = grub_util_path_concat (2, efidir_efi_boot, "bootaa64.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_ARM64_EFI, "arm64-efi", + make_image_abs (GRUB_INSTALL_PLATFORM_ARM64_EFI, "arm64-efi", imgname); free (imgname); imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv32.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi", + make_image_abs (GRUB_INSTALL_PLATFORM_RISCV32_EFI, "riscv32-efi", imgname); free (imgname); imgname = grub_util_path_concat (2, efidir_efi_boot, "bootriscv64.efi"); - make_image_fwdisk_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi", + make_image_abs (GRUB_INSTALL_PLATFORM_RISCV64_EFI, "riscv64-efi", imgname); free (imgname); -- 2.36.0.windows.1