VMDK descriptor file saves the day

I think its fitting to begin this posting with a famous quote by Abraham Lincoln “If I had eight hours to chop down a tree, I’d spend six hours sharpening my ax”

I was in that very position a few days ago, I had to choose between recreating a VM, reinstalling Server 2008, running updates, then installing a key application with minimum down time due to the  accidental deletion of  some key VMware files. After analyzing my issue I decided to research the problem instead of just start chopping away with the obvious solution. In the end I can across the a very useful  KB article from vmware about recreating the vmdk descriptor file which did the trick for me.

Below is an image of the common files you would normally see when browsing a VMware guest data-store, now in my case everything was deleted except the “testsrvr2k8.vmdk” file.

VMware file extensions:

.VMDK — These files are the actual hard disk of the virtual machine itself, and tend to be the largest file within the folder. You can consider the size of this file to be roughly equivalent to the size of either the disk itself (if you’ve chosen to use preallocate disks) or the size of the data currently stored on that disk (if you use grow-able disks i.e thin provisioning).

.NVRAM — Consider this file the BIOS of the virtual machine.

.VMX — With typically one VMX file per folder, this file holds the configuration information for the virtual machine in a text format. Unlike almost all the other files you’ll see, these files can be edited using any text editing program, a process that is actually required for some functionality that is not exposed in the GUI.

.VMXF — This file, in XML format, includes additional information about the virtual machine if it has been added to a team. If a machine has been added to a team and then later removed, this file remains resident. This file can also be opened and read in a text editor.

.VMTM — For virtual machines actively participating in a team, this file stores information about that team membership.

.VMEM — These files, which contain a backup of the VMs paging file, are typically very small or non-existent when the virtual machine is powered off, but grow immediately to the size of configured RAM when the machine is powered on.

.VMSN and .VMSD — When snapshots are created for a virtual machine, these files are created to host the state of the virtual machine. The VMSN file stores the running state of the machine, what you could consider the “delta” between the VMDK at the point of the snapshot and what has been processed up until the present time. The VMSD stores information and metadata about the snapshot itself.

.VMSS — If you’ve suspended the state of your machine, this file contains the suspended state of that machine. These files typically only appear when virtual machines have been suspended.

Overview Steps

To create a virtual machine disk descriptor file:
  1. Identify the size of the flat file in bytes.
  2. Create a new blank virtual disk that is the same size as the original. This serves as a baseline example that is modified in later steps.

    Note: This step is critical to assure proper disk geometry.

  3. Rename the descriptor file (also referred to as a header file) of the newly-created disk to match the name of the original virtual disk.
  4. Modify the contents of the renamed descriptor file to reference the flat file.
  5. Remove the leftover temporary flat file of the newly-created disk, as it is not required.

Detail Steps:

To create a virtual machine disk:

  1. Log in to the terminal of the VMware ESX host.
  2. Navigate to the directory that contains the virtual machine disk with the missing descriptor file using the command:

    cd /vmfs/volumes/myvmfsvolume/mydir

    • If you are using a version of VMware ESXi, you can access and modify files and directories using the VMware vSphere client Datastore Browser or the vifs utility included with the vSphere CLI. For more information, see the section Performing File System Operations in vSphere CLI documentation.
    • If you are using VMware Fusion, the default location for the virtual machine files is <home>/Documents/Virtual Machines.localized/<virtual machine>/ folder where <home> is your home folder, and <virtual machine> is the name of the virtual machine.

  3. Identify the type of SCSI controller the virtual disk is using. You can do this by examining the virtual machine configuration file (.vmx). The controller is identified by the line scsi#.virtualDev, where # is the controller number; there may be more than one controller and controller type attached to the virtual machine. This example uses lsilogic:

    scsi0.present = “true”
    scsi0.sharedBus = “none”
    scsi1.present = “true”
    scsi1.sharedBus = “virtual”
    scsi1.virtualDev = “lsilogic”
  4. Identify and record the exact size of the -flat file using a command similar to:

    # ls -l vmdisk0-flat.vmdk
    -rw——- 1 root root 4294967296 Oct 11 12:30 vmdisk0-flat.vmdk
  5. Use the vmkfstools command to create a new virtual disk:

    # vmkfstools -c 4294967296 -a lsilogic -d thin temp.vmdk This command uses these flags:

    -c <size>  (This is the size of the virtual disk).
    -a <virtual controller> (Whether the virtual disk was configured to work with BusLogic or LSILogic).
    -d thin  (This creates the disk in a thin-provisioned format).

    Note: To save disk space, we create the disk in a thin-provisioned format using the type thin. The resulting flat file then consumes minimal amounts of space (1MB) instead of immediately assuming the capacity specified with the -c switch. The only consequence, however, is the descriptor file contains an extra line that must be removed manually in a later step.

    The files temp.vmdk and temp-flat.vmdk are created as a result.

  6. Delete temp-flat.vmdk, as it is not needed. Run the command:

    # rm temp-flat.vmdk
  7. Rename temp.vmdk to the name that is required to match the orphaned .flat file (or vmdisk0.vmdk, in this example):

    # mv temp.vmdk vmdisk0.vmdk
  8. Edit the descriptor file with a text editor:

    1. Under the Extent Description section, change the name of the .flat file to match the orphaned .flat file you have.
    2. Find and remove the line ddb.thinProvisioned = “1” if the original .vmdk was not a thin disk. If it was, retain this line.
      # Disk DescriptorFile
      createType=”vmfs”# Extent description
      RW 8388608 VMFS “vmdisk0-flat.vmdk”

      # The Disk Data Base

      #DDBddb.virtualHWVersion = “4”
      ddb.geometry.cylinders = “522”
      ddb.geometry.heads = “255”
      ddb.geometry.sectors = “63”
      ddb.adapterType = “lsilogic”

      ddb.thinProvisioned = “1”

      The virtual machine is now ready for power on. Verify your changes before starting the virtual machine.

  • Although these steps are specific to the VMware ESX host’s Service Console (otherwise regarded as the Console OS), they may also be applied to platforms using VMware desktop products such as VMware Server or VMware Workstation. Instead of using the vmkfstools command, use the vmware-vdiskmanager utility. For more information on the Virtual Disk Manager, see the Virtual Disk Manager User’s Guide.
  • When performing these operations on a different platform, you must use the equivalent commands for your platform. For example, move, copy, and del for Microsoft Windows platforms and mv, cp, and rm for Unix, Linux, and Mac OS X platforms.
  • For more information about platform-specific commands, see: DOS versus Linux Commands from the Linux Documentation Project.

Once you are finish the above steps recreate you guest VM and instead of creating a new disk select “Use Existing Disk” and browse to the datastore and select your VMDK file from there. In my case that was testsrvr2k8.vmdk.

All worked well for me however when I turned on my VM it kept rebooting and blue-screening on me, the fix for that was to change the SCSI controller type from “LSI logic SAS” to “LSI Logic Parallel” rebooted and all was well.