Hi,

The attached patch adds a new option '-rawdiskimage' to the createrawvmdk
command. With this option, raw disk images can be used directly without
loopback devices. I think this is useful for users who wants to run the same
disk images on different virtual machine software. I tested on Ubuntu Linux,
but I hope this simple patch works on other environments too.

This patch is under the MIT license.

Hideki EIRAKU
Index: src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
===================================================================
--- src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp	(revision 37671)
+++ src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp	(working copy)
@@ -177,7 +177,7 @@
         (u64Cmd & USAGE_CREATERAWVMDK)
         ? "  createrawvmdk -filename <filename> -rawdisk <diskname>\n"
           "                [-partitions <list of partition numbers> [-mbr <filename>] ]\n"
-          "                [-relative]\n"
+          "                [-relative] [-rawdiskimage]\n"
           "       Creates a new VMDK image which gives access to an entite host disk (if\n"
           "       the parameter -partitions is not specified) or some partitions of a\n"
           "       host disk. If access to individual partitions is granted, then the\n"
@@ -923,6 +923,7 @@
     Utf8Str rawdisk;
     const char *pszPartitions = NULL;
     bool fRelative = false;
+    bool fRawDiskImage = false;
 
     uint64_t cbSize = 0;
     PVBOXHDD pDisk = NULL;
@@ -968,6 +969,10 @@
             i++;
             pszPartitions = argv[i];
         }
+        else if (strcmp(argv[i], "-rawdiskimage") == 0)
+        {
+            fRawDiskImage = true;
+        }
 #if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
         else if (strcmp(argv[i], "-relative") == 0)
         {
@@ -995,6 +1000,16 @@
         RTMsgError("Cannot open the raw disk '%s': %Rrc", rawdisk.c_str(), vrc);
         goto out;
     }
+    if (fRawDiskImage)
+    {
+        vrc = RTFileGetSize(hRawFile, &cbSize);
+        if (RT_FAILURE(vrc))
+        {
+            RTMsgError("Cannot get the size of the raw disk image '%s': %Rrc", rawdisk.c_str(), vrc);
+            goto out;
+        }
+        goto rawdiskimage;
+    }
 
 #ifdef RT_OS_WINDOWS
     /* Windows NT has no IOCTL_DISK_GET_LENGTH_INFORMATION ioctl. This was
@@ -1162,6 +1177,7 @@
     }
 #endif
 
+rawdiskimage:
     /* Check whether cbSize is actually sensible. */
     if (!cbSize || cbSize % 512)
     {
_______________________________________________
vbox-dev mailing list
[email protected]
http://vbox.innotek.de/mailman/listinfo/vbox-dev

Reply via email to