Disk images for virtual machines in VMWare products are stored in 2 files: disk description and data.
In filesystem virtual machine partition stored as 2 files:
- disk file image: linux-flat.vmdk
- disk file config: linux.vmdk
So in situation when you accidentally removed linux.vmdk (when you’re connected with SSH) or it’s broken, you can restore your disk drive image and mount it to another virtual machine.
To restore image you should do next steps (example is for ESXi installation as the most common for me).
Step 1: Connect to ESXi host machine with SSH
You need to connect to your ssh server and change folder to one where you’ve files for your virtual machine.
# cd /vmfs/volumes/ssd3/linux
#
Step 2: Find out interface type
Open file with extention .vmx and find bus id of broken drive. Then grep data for this bus id:
scsi0.present = "true"
scsi0.sharedBus = "none"
scsi1.present = "true"
scsi1.sharedBus = "virtual"
scsi1.virtualDev = "lsilogic"
Let’s imagine we need to restore drive connected to scsi1.
Step 3: Find disk size
# ls -l linux-flat.vmdk
-rw------- 1 root root 4294967296 Oct 11 12:30 linux-flat.vmdk
Step 4: Create temporary partition
Create temporary partition with same size and type with vmkfstools:
# vmkfstools -c 4294967296 -a lsilogic -d thin temp.vmdk
In example we used next options:
- -c - define disk size
- -a - define controller type for broken partition
- -d thin - we’ll create partition without reservation of disk space
Step 5: Rename temporary partition config
We need to remove temporary data file and rename partition config file to name of our broken partition:
# rm temp-flat.vmdk
# mv temp.vmdk linux.vmdk
Step 6: Edit partition config file
Open with vi file linux.vmdk, find line:
RW 8388608 VMFS "temp-flat.vmdk"
and replace it with:
RW 8388608 VMFS "linux-flat.vmdk"
Then save changes and exit from vi.
Step 7: Check partition
After that we need to check partition for errors with internal ESXi tools:
## For ESXi 5.0/5.1
# vmkfstools -e filename.vmdk
For a complete chain, you see output similar to:
Disk chain is consistent
For a broken chain, you will see a summary of the snapshot chain and then an output similar to:
Disk chain is not consistent : The parent virtual disk has been modified since the child was created. The content ID of the parent virtual disk does not match the corresponding parent content ID in the child (18)
## For ESXi 3,5⁄4.x
# vmkfstools -q filename.vmdk
For a complete chain, you see output similar to:
filename.vmdk is not an rdm
For a broken chain, you see output similar to:
Failed to open 'test-000001.vmdk' : The parent virtual disk has been modified since the child was created (18)
Step 8: Starting virtual machine
Now virtual machine should start without any problems.