Sergey Nivens - Fotolia

How do you recreate a missing VMDK descriptor file?

The descriptor file plays an essential role in a virtual machine disk file, pointing to the larger data file and other VMDK information. So, what do you do when it goes missing?

It's a good idea to make sure you understand the anatomy of a VMware VM. Let's go over the basics: Though there...

are many types of VMware VM files, the primary three are .nvram files, .vmx files and virtual machine disk files. The .nvram file contains the VM’s BIOS state for reboots, the .vmx file contains configuration info and hardware settings, and the virtual machine disk file consists of a large data file and a small text descriptor file. We're most interested in the virtual machine disk file.

You can have more than one virtual machine disk file (VMDK) in a VM; for example, a VM can have both an operating disk and a data disk. The maximum number of disks you can have on a VM is 15 per virtual SCSI controller. You're allowed four SCSI controllers -- though one or two is common practice -- which means you can have a total of 60 virtual disks. Traditionally, virtual disks are given a name that matches the VM, followed by a .VMDK extension. Figure A shows a VM with two virtual disks.

VM with two virtual disks.
Figure A. A VM with two virtual disks.

If you look at the VMDKs in Figure A, you'll notice that there are files with the VM name and with the _1 suffix (WinFS01.vmdk and WinFS01_1.vmdk, respectively). It is customary to attach a suffix of _1, _2 and so on to additional disks. If you look even more closely, you'll also notice that for both disks there is a similar file ending with a -flat suffix. These are the files that contain the actual data. The file titled "<vmname>.vmdk" is the descriptor file, which describes the geometry of the virtual disk. This is the file I'll be showing you how to recreate should it go missing.

The first step to recreating the descriptor file is to restore it from a previous backup. If you don't have a previous backup from which to restore, you can create a new disk with the same specifications, and then use that new descriptor file to point to the original data disk, titled "flat.vmdk."

To do this, access your ESXi host via the Secure Shell. Then, find the size of the flat.vmdk file in your VM folder on the data store. You can use the ls -l command to find the exact number of bytes.

With this information, use the vmkfstools command, shown in Figure B, to create a new disk with the same size:

vmkfstools -c <size in bytes> tempdisk.vmdk

Vmkfstools command.
Figure B. Run the vmkfstools command.

You can add the parameter -d thin to this command to create a thin-provisioned disk. Doing so is faster and consumes less disk space. Just make sure that the new disk descriptor matches the format of the original disk. If it was originally thick-provisioned, then you're done. If it was thin-provisioned, use the -d thin parameter or add this line to the descriptor file: ddb.thinProvisioned = "1".

Next, open the tempdisk.vmdk file and change the name of the temporary flat-file to that of the original flat-file from the missing descriptor file. When that's done, use the mv command to replace the name of the temporary VMDK file with that of the missing descriptor file. Remove the remaining unnecessary temp-flat file with the rm command, and you're done.

When that is done, rename the temporary .vmdk to the name of the missing descriptor file -- with the mv command -- and you're done. Also, remove the remaining unnecessary temp-flat file with the rm command.

To verify whether the .vmdk file and the -flat.vmdk form a consistent pair, you can run the vmkfstools command with the -e parameter, as shown in Figure C.

vmkfstools verifies a consistent pair
Figure C. Verify a consistent pair with the vmkfstools command.

Next Steps

Requirements for creating a VMDK file larger than 2 TB

Tips for copying VMDK files

Can you use snapshots to revive VMDK files?

Dig Deeper on VMware ESXi, vSphere and vCenter

Virtual Desktop
Data Center
Cloud Computing