Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp	(revision 39575)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxInternalManage.cpp	(revision 39576)
@@ -218,4 +218,11 @@
           "\n"
         : "",
+        (u64Cmd & USAGE_REPAIRHD)
+        ? "  repairhd [-dry-run]\n"
+          "           [-format VDI|VMDK|VHD|...]\n"
+          "           <filename>\n"
+          "       Tries to repair corrupted disk images\n"
+          "\n"
+        : "",
 #ifdef RT_OS_WINDOWS
         (u64Cmd & USAGE_MODINSTALL)
@@ -595,5 +602,6 @@
 {
     NOREF(pvUser);
-    return RTPrintfV(pszFormat, va);
+    RTPrintfV(pszFormat, va);
+    return RTPrintf("\n");
 }
 
@@ -1921,4 +1929,85 @@
 
 /**
+ * Tries to repair a corrupted hard disk image.
+ *
+ * @returns VBox status code
+ */
+static int CmdRepairHardDisk(int argc, char **argv, ComPtr<IVirtualBox> aVirtualBox, ComPtr<ISession> aSession)
+{
+    Utf8Str image;
+    Utf8Str format;
+    int vrc;
+    bool fDryRun = false;
+    PVBOXHDD pDisk = NULL;
+
+    /* Parse the arguments. */
+    for (int i = 0; i < argc; i++)
+    {
+        if (strcmp(argv[i], "-dry-run") == 0)
+        {
+            fDryRun = true;
+        }
+        else if (strcmp(argv[i], "-format") == 0)
+        {
+            if (argc <= i + 1)
+            {
+                return errorArgument("Missing argument to '%s'", argv[i]);
+            }
+            i++;
+            format = argv[i];
+        }
+        else if (image.isEmpty())
+        {
+            image = argv[i];
+        }
+        else
+        {
+            return errorSyntax(USAGE_REPAIRHD, "Invalid parameter '%s'", argv[i]);
+        }
+    }
+
+    if (image.isEmpty())
+        return errorSyntax(USAGE_REPAIRHD, "Mandatory input image parameter missing");
+
+    PVDINTERFACE     pVDIfs = NULL;
+    VDINTERFACEERROR vdInterfaceError;
+    vdInterfaceError.pfnError     = handleVDError;
+    vdInterfaceError.pfnMessage   = handleVDMessage;
+
+    vrc = VDInterfaceAdd(&vdInterfaceError.Core, "VBoxManage_IError", VDINTERFACETYPE_ERROR,
+                         NULL, sizeof(VDINTERFACEERROR), &pVDIfs);
+    AssertRC(vrc);
+
+    do
+    {
+        /* Try to determine input image format */
+        if (format.isEmpty())
+        {
+            char *pszFormat = NULL;
+            VDTYPE enmSrcType = VDTYPE_INVALID;
+
+            vrc = VDGetFormat(NULL /* pVDIfsDisk */, NULL /* pVDIfsImage */,
+                              image.c_str(), &pszFormat, &enmSrcType);
+            if (RT_FAILURE(vrc) && (vrc != VERR_VD_IMAGE_CORRUPTED))
+            {
+                RTMsgError("No file format specified and autodetect failed - please specify format: %Rrc", vrc);
+                break;
+            }
+            format = pszFormat;
+            RTStrFree(pszFormat);
+        }
+
+        uint32_t fFlags = 0;
+        if (fDryRun)
+            fFlags |= VD_REPAIR_DRY_RUN;
+
+        vrc = VDRepair(pVDIfs, NULL, image.c_str(), format.c_str(), fFlags);
+    }
+    while (0);
+
+    return RT_SUCCESS(vrc) ? 0 : 1;
+}
+
+/**
  * Unloads the necessary driver.
  *
@@ -2213,4 +2302,6 @@
     if (!strcmp(pszCmd, "gueststats"))
         return CmdGuestStats(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
+    if (!strcmp(pszCmd, "repairhd"))
+        return CmdRepairHardDisk(a->argc - 1, &a->argv[1], a->virtualBox, a->session);
 
     /* default: */
Index: /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h
===================================================================
--- /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 39575)
+++ /trunk/src/VBox/Frontends/VBoxManage/VBoxManage.h	(revision 39576)
@@ -100,4 +100,5 @@
 #define USAGE_BANDWIDTHCONTROL      RT_BIT_64(56)
 #define USAGE_GUESTSTATS            RT_BIT_64(57)
+#define USAGE_REPAIRHD              RT_BIT_64(58)
 #define USAGE_ALL                   (~(uint64_t)0)
 /** @} */
