Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In Windows 7, I set up another Windows 7 VM in VirtualBox. It worked great. Then, I needed to increase the vhd HD size. So, I used VBoxManage utility to do that with the following comment:

VBoxManage modifyhd "c:\VMs\Win7.vhd" --resize 30000

Then, I tried to run the VM again but it cannot be booted and gives me the following error:

FATAL: No bootable medium found! System halted.

Then, I tried to see what is going on inside the VHD and try to attach it inside Device Management and it says It cannot be attached because The file or directory is corrupted and unreadable.

Any idea what went wrong here and how can I save my VM inside that VHD file?

share|improve this question
    
I just had exactly the same problem and I couldn't find any useful solution online so I started analysing the VHD by hand according to Microsoft's documentation. Currently it seems there's bug in modifyhd's implementation where it didn't adjust the offset to data blocks after it has expanded the block allocation table. I need to do some more expriments to verify this. –  billc.cn Sep 21 '12 at 22:43
    
On VirtualBox 4.3.10, I resized a .vhd file. It looks like not only did it not adjust the block allocation table pointers, but it expanded the block allocation table into the first block of data, overwriting my MBR and partition table.. Don't use VirtualBox to resize .vhd files! –  Aaron Aug 29 at 19:50

5 Answers 5

up vote 7 down vote accepted

Unfortunately the VirtualBox documentation for the VBoxManage --resize option is misleading. You cannot just increase the size of the disk image and have everything work properly. The disk partition information within the image has to be adjusted so that the guest operating system knows the layout of the "drive" the disk image is simulating. You accomplish this adjustment by downloading a bootable CD image that has a partition editor on it and booting the VM onto that CD. You then use the partition editor to adjust the disk image's partitions to use the added space.

There's a nice writeup of the procedure here; just skip to step 4.

share|improve this answer
    
Well, that's a bummer. This means that I've just thrown away the 3 hours of work. Thanks for the info. –  tugberk May 9 '12 at 17:49
2  
I followed the nice writeup (after I resized my vhd and couldn't boot from it), and GParted didn't show any partitions on the harddrive, only 50 gigs of unallocated space. Does that mean modifyhd screwed up the drive beyond repair? –  GSerg Feb 5 '13 at 16:15

I had the same issue

  1. create new VHD with desired size
  2. Use clonhd to copy from old vhd to new vhd

Reference : http://tips.kaali.co.uk/2012/03/16/expand-or-increase-the-size-of-virtual-box-vdi-dis/

share|improve this answer

I had the same problem and I managed to retrieve the data using the GParted LiveCD

  1. Create new VHD to receive the copied data (create partitions and format)
  2. Download the GParted LiveCD and boot on VirtualBox
  3. Select Device -> Attempt Data Rescue
  4. Click OK and after the Scan click View (this will mount /tmp/gparted-roview-XXXXXX)
  5. On the terminal, mount the second VHD (sudo mount /dev/sdb1 /mnt)
  6. Copy the files (sudo cp -R /tmp/gparted-roview-XXXXXX/* /mnt

After that you can shutdown the Virtual Machine and mount the VHD on Windows Device Manager.

share|improve this answer

It's worth to note, that I got the exact same problem, which was due to that I issued the command modifyhd while the guest was running. The official documentation says nothing about, that you have to delete snapshots first and the that guest should have been stopped.

My plan was to resize the disk while the machine was running because I've got a dynamic volume which could also be increased on the fly. However, this was a bad idea as I rebooted the machine to get the full disk size I was left in the dark with a corrupt image, which I couldn't restore even not with testdisk. Testdisk finds the partitions but the filesystem is badly damaged and cannot be repaired.

So be advised:

  1. Merge all Snapshots into the Base Image
  2. Shut down the Guest OS

I've repeated the procedure on my machine with a backup image and the guest os being powered off, this works well.

share|improve this answer

I was able to recover an image that was broken by this bug. Unlike Edison the gparted live image did not find anything. Here's what I did:

  • First, since apparently VBox support for VHD is buggy and terrible, begin by converting the VHD to a VDI with VBoxManage clonehd foo.vhd --format vdi foo.vdi. When I skipped this step, I could recover files from the image but it would "break itself" again after a few reboots. I'm guessing the bug really screws up the VHD file in a way that later I/O "re-breaks" it... VBox doesn't seem to have these issues with VDI so I gave up on VHD.

  • Boot into WinPE, the Windows Preinstallation Environment. How to do this could be an article unto itself. If you are not familiar with this here's a shortcut: Boot from a Windows Setup DVD (Vista or higher) and hit shift-F10 once the GUI comes up, it will give you a command prompt.

  • Download testdisk, find a way to get it onto your WinPE image (or a simple USB stick would work), and run it from the WinPE environment. (Note: WinPE lacks WOW64, the 32-bit compatibility layer for 32-bit apps. Therefore my 64-bit WinPE setup needed the 64-bit testdisk binary.)

  • Testdisk found the partitions and restored them.

  • At this point the files were recovered but the bootloader failed for several issues. First I used diskpart to mark the partition as active (list disk, sel disk <disk number>, sel par 0, active). Got further, wouldn't boot. Went back into WinPE and deleted \boot, then ran bcdboot C:\windows /s C: to reinstall the bootloader.

  • At the end I ran chkdisk /R to be sure the image was ok. Took a few hours, didn't find any issues.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.