From f7e6bbc70c65db9f6f5da5abc4ae57bd689da91c Mon Sep 17 00:00:00 2001 From: longpanda Date: Wed, 12 Feb 2025 23:00:27 +0800 Subject: [PATCH] Fix the "Unsupported vtoy type unknown" error when boot a VDI file created by VirtualBox 7.x --- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 3 ++- .../grub-2.04/grub-core/ventoy/ventoy_vhd.c | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index d51a33ce..64a6ba8d 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -861,7 +861,8 @@ typedef struct vhd_footer_t grub_uint8_t savedst; // Saved state }vhd_footer_t; -#define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n" +#define VDI_IMAGE_FILE_INFO "<<< Oracle VM VirtualBox Disk Image >>>\n" +#define VDI_IMAGE_FILE_INFO2 "<<< Oracle VirtualBox Disk Image >>>\n" /** Image signature. */ #define VDI_IMAGE_SIGNATURE (0xbeda107f) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c index 45ce7c6c..c5839c2c 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c @@ -536,12 +536,25 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char * { grub_file_seek(file, 0); grub_file_read(file, &vdihdr, sizeof(vdihdr)); - if (vdihdr.u32Signature == VDI_IMAGE_SIGNATURE && - grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO, grub_strlen(VDI_IMAGE_FILE_INFO)) == 0) + if (vdihdr.u32Signature == VDI_IMAGE_SIGNATURE) { - offset = 2 * 1048576; - g_img_trim_head_secnum = offset / 512; grub_snprintf(type, sizeof(type), "vdi"); + if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO, grub_strlen(VDI_IMAGE_FILE_INFO)) == 0) + { + offset = 2 * 1048576; + g_img_trim_head_secnum = offset / 512; + debug("VDI V1\n"); + } + else if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO2, grub_strlen(VDI_IMAGE_FILE_INFO2)) == 0) + { + offset = 2 * 1048576; + g_img_trim_head_secnum = offset / 512; + debug("VDI V2\n"); + } + else + { + debug("invalid file info <%s>\n", vdihdr.szFileInfo); + } } else { @@ -568,7 +581,7 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char * if (gpt->MBR.Byte55 != 0x55 || gpt->MBR.ByteAA != 0xAA) { grub_env_set(args[1], "unknown"); - debug("invalid mbr signature: 0x%x 0x%x\n", gpt->MBR.Byte55, gpt->MBR.ByteAA); + debug("invalid mbr signature: 0x%x 0x%x offset=%d\n", gpt->MBR.Byte55, gpt->MBR.ByteAA, offset); goto end; }