Ubuntu – Recover files from a broken Virtualbox machine .vdi


My Ubuntu 12.04.1 running on virtualbox ran out of space while I was installing software on it and now it is not rebooting. I've got files I need to recover from it. I have the ubuntu64.vdi file on my Windows 7 (host) laptop and I was wondering if there is any way of recovering the files from the vdi file.

In parallel, I generated a fresh 12.04.1 machine on virtualbox in the same laptop, and I'll use that one instead of the borked one.

I can add the borked vdi to the list of disks in the working one. Then I used gnome nautilus to mount the borked disk.

I can find the files in there, but they are about 2 months old. I think this coincides with the last time that I did a virtualbox snapshot of the machine, but not the last time I got a working machine, which was yesterday. Is there any way of mounting the vdi as of yesterday, just before it crashed?


Here is what Virtual Media Manager tells me about my ubuntu64.vdi file:
enter image description here


I copied my ubuntu.vdi to an external USB with plenty of disk space. I tried using Windows to clone it, but got an error:

enter image description here

I tried the same from the working VM via a shared folder of the USB drive, and it started the cloning. Took a good while, but finished successfully:

VBoxManage clonehd ubuntu64.vdi ubuntu64.raw --format RAW

Clone hard disk created in format 'RAW'. UUID: 90f99198-18e1-40ee-85fe-c083dcbb1ac3


After creating the raw file, I run testdisk with Deeper Search, I get a list like this:
enter image description here

Ater Deeper Search has finished, I get a list like this:

enter image description here

But I don't know which one is which snapshot… Any ideas?

Best Answer

Of the command line

In case we use Ubuntu as a host we can convert our .vdi disk to a raw disk with the following command:

VBoxManage clonehd <sourcename> <clone.raw> --format RAW

We can then open testdisk Install testdisk with this file to recover files on the virtual drive's image (also see below):

testdisk <clone.raw>

Of a virtual machine

In case the broken VDI drive image is still registered with Virtual Box we may be able to add this image as a drive to our new virtual machine:

enter image description here

Start your virtual Ubuntu to which we had added the broken .vdi but do not mount the drive.

  1. Create a directory on a mounted partition there to hold the harvested data (e.g. ~/rescued),

  2. Install testdisk Install testdisk on the virtual machine.

  3. Start testdisk from a terminal there:

    sudo testdisk
  4. Choose the appropriate drive to harvest data from (here shown for /sdb) and select [Proceed]

    enter image description here

  5. Choose the appropriate partition layout (usually Intel)

  6. Select [Analyse] - [Quick Search]

  7. Select the partition which contains the data to harvest (here only a single NTFS partition was present):

    enter image description here

  8. Press P to list files on that partiton.

  9. Browse to the directory containing the data. View the filenames to make sure you did choose the right ones.

  10. Select directories or files to harvest using : . All selected files/directories will be marked green:

    enter image description here

  11. Press upper case C to copy all selected directories/files to the rescue directory which will be selected in the next step.

  12. Choose a directory on your Ubuntu VM's mounted partition(s) to hold rescued data:

    enter image description here

  13. Press c to start copying the data from the broken .vdi to our rescue directory in your healthy VM.


  • In case we can not see our files with the [Quick Search] option in 6. we may have to perform a [Deeper Search]. This will also list previous deleted and overwritten partitions. So we need to make sure we select the appropriate partitions where our data reside.

  • If we had taken snapshots of the .vdi we may find these in ~/.VirtualBox/Machines/<Name of Machine>/Snapshots/{###}.vmdkbut whenever we had used the snapshot feature of Virtual Box any changes from a snapshot will be written to a differential file.

    To merge the differential file with the hard drive we need to delete all snapshots (which is probably not what we want as then we could just restore to previous snapshot rather than call for data recovery), or we need to clone the machine's drive using:

    VBoxManage clonehd <name_of_source> <clone>

    Then we bind the clone to our rescue VM as depicted above.

  • Writing to the broken .vdi should only be done after the data was safe as this may further damage the file system.

  • In case our rescue Ubuntu is too small to hold the rescued data we may create another new virtual drive to bind to the VM. This drive then has to be mounted in the VM to be able to save data from testdisk there.

Related Question