]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Fix the "Unsupported vtoy type unknown" error when boot a VDI file created by Virtual...
authorlongpanda <admin@ventoy.net>
Wed, 12 Feb 2025 15:00:27 +0000 (23:00 +0800)
committerlongpanda <admin@ventoy.net>
Wed, 12 Feb 2025 15:00:27 +0000 (23:00 +0800)
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h
GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c

index d51a33cecd3eb1eb450fb81a12b88ca845d99bbd..64a6ba8d4e5545b5846ec272559c5a722e940370 100644 (file)
@@ -861,7 +861,8 @@ typedef struct vhd_footer_t
     grub_uint8_t     savedst;      // Saved state
 }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)
 
 /** Image signature. */
 #define VDI_IMAGE_SIGNATURE   (0xbeda107f)
index 45ce7c6cbdb1376769d7aa51df730bc3680fa15f..c5839c2c6c6c4b74dccfef1307d57c6ffbc5647d 100644 (file)
@@ -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));
     {
         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");
             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
         {
         }
         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");
         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;
         }
 
             goto end;
         }