Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1nyFwb-0003dM-QI for mharc-grub-devel@gnu.org; Mon, 06 Jun 2022 12:51:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyFwU-0003XG-B1 for grub-devel@gnu.org; Mon, 06 Jun 2022 12:51:02 -0400 Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:37648) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyFwR-0006hS-Iz for grub-devel@gnu.org; Mon, 06 Jun 2022 12:51:02 -0400 Received: by mail-wm1-x330.google.com with SMTP id o37-20020a05600c512500b0039c4ba4c64dso2344729wms.2 for ; Mon, 06 Jun 2022 09:50:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo.ie; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e8MPz851lkY/hb/I+5X0q4qOVcqEGcj+Pb6ZWVw7uJQ=; b=cuMGerD1UIDLTtSwzYzv4YLMPO6YwwfuGd0bndrw8rCtDz3I/KMyrnZhr25FECnn4v ymccbXL5/CqOe4GoUY1lOqtY8H7IgNTGoSBAM/fWb4IGmfZLneMTOYMugDEhab3KnDy/ x8WSWIgD+/5OKGGA1N1oea0XocGB9n98XBzYM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e8MPz851lkY/hb/I+5X0q4qOVcqEGcj+Pb6ZWVw7uJQ=; b=DY6EdOBLbhelLcxCSKtWQ+rduszkHbeKJLo+R7ToB7RIv+1Jfe6XTttVzM5l7sJfOT foU6RFgtudtRg8LS0Tdy9BTFmPdJu3yYtIZ+qEoRK41m5R8bm3Vn9V7APEEzLu0CBYEb dL4belp7kuiw/hL4ZwytdPdn1LRgsSQIugjvfnHohjD80Gn1F0sikHanw3ZnKcgH18gH khHpRNzL21GRN2pLvCRm62crOHpP62x//s29wMkNk8JdZxWYGwj8JtIxVjLDQEkxo56+ fXGzoIWogcrADyihqihTv9hub9o8ptDyzKfvU5VHdQxssczSUx2T4ECLhtM2JD4EdmHV vOPw== X-Gm-Message-State: AOAM531/KUfKENrHfQJ2lRUPl6Lg/2JX9ggKGDsd42lPPgGb2tt9TXWq eJ/v0/Lwr2rvBaED4Rb2U9rmZ8ONdrGTmA== X-Google-Smtp-Source: ABdhPJxg1gBWxABlL4wrxcecwlalsc+sVhykYeGC+wUnTajKW53h2RRsVGe9/wp7EiJ0RsaIEAJkZQ== X-Received: by 2002:a7b:c842:0:b0:394:8d6c:2768 with SMTP id c2-20020a7bc842000000b003948d6c2768mr24040106wml.205.1654534252452; Mon, 06 Jun 2022 09:50:52 -0700 (PDT) Received: from localhost.localdomain (ip-84-203-46-176.broadband.digiweb.ie. [84.203.46.176]) by smtp.gmail.com with ESMTPSA id i19-20020a1c5413000000b0039c457cea21sm8066068wmb.34.2022.06.06.09.50.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 09:50:52 -0700 (PDT) From: Pete Batard To: grub-devel@gnu.org Cc: scdbackup@gmx.net, Pete Batard Subject: [PATCH 3/3] grub-mkrescue: Search by file UUID file rather than partition UUID for EFI boot Date: Mon, 6 Jun 2022 17:50:33 +0100 Message-Id: <20220606165034.811-4-pete@akeo.ie> X-Mailer: git-send-email 2.36.0.windows.1 In-Reply-To: <20220606165034.811-1-pete@akeo.ie> References: <20220606165034.811-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=pete@akeo.ie; helo=mail-wm1-x330.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, T_SCC_BODY_TEXT_LINE=-0.01 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, 06 Jun 2022 16:51:03 -0000 The final piece we need to add file system transposition support for UEFI is to ensure that we can locate the boot media 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 we can then search for. 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..b7a387d8b 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 --fs-uuid --set=root %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