Another easily fixed issue for a VM is if you have a lost or corrupted header file for the virtual disk of a VM. When this happens the virtual disk won't be accessible. Typical senarios include
- The virtual machine disk is missing when viewing the virtual machine folder from a datastore browser
- You can see the –flat.vmdk file does exist when connected to the host via command line
- The .vmdk descriptor file for the virtual machines disk does not exist or is corrupted
- When powering on a virtual machine you see a File not found error
For example, a 10GB disk has a 10GB .vmdk file. These content files have -flat appended to the name of the virtual machine, like virtualDisk-flat.vmdk. The descriptive file of this set is virtualDisk.vmdk.
So to resolve this problem:
1. Identify the size of the -flat file.
2. Create a new blank virtual disk that is the same size as the original. Note: This step is critical to assure proper disk geometry.
3. Rename the descriptor of the new disk to match the name of the original virtual disk.
4. Edit the descriptor to change the reference to the -flat file.
5. Remove the leftover temporary -flat file as it is not needed.
The steps in detail are as follows:
1. Log in to the console of the ESX host.
2. Run this command to go to the directory that contains the virtual disk with the missing header/descriptor file:
cd /vmfs/volumes/myvmfsvolume/mydir
Note: If you are using ESXi, you can move, copy, change and delete directories and files using the vSphere client datastore browser, or the vifs utility which comes with the vSphere CLI. For more information, see the Performing File System Operations with vifs section of the vSphere CLI documentation.
3. Identify the kind 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 can be more than one controller attached to the virtual machine so make sure to identify which controller the disk you are working on is attached to.
This example uses lsilogic:
scsi0.present = "true"scsi0.sharedBus = "none"scsi1.present = "true"scsi1.sharedBus = "virtual"scsi1.virtualDev = "lsilogic"
Note: If you are using ESXi, you can download, view, edit and upload files using the vSphere Client datastore browser or the vifs utility which comes with the vSphere API. The file can be viewed or edited using your preferred text editor. For more information, see the Performing File System Operations with vifs section of the vSphere CLI documentation.
4. Run this command to identify and record the exact size of the flat file:
# ls -l vmdisk0-flat.vmdk
-rw------- 1 root root 4294967296 Oct 11 12:30 vmdisk0-flat.vmdk
5. Run the vmkfstools command to create a new virtual disk.
# vmkfstools -c 4294967296 -a lsilogic temp.vmdk
This command uses the following flags:
-c
-a
If you are short on disk space, you can create the temporary disk as type thin. The associated -flat file consumes almost no space (1Mb) instead of the amount specified with -c (as we are not keeping the new -flat file, this is not a problem). The consequence is that the header file will contain an extra line that must be removed manually. The command looks like this:
# vmkfstools -c 4294967296 -d thin -a lsilogic temp.vmdk
The files temp.vmdk and temp-flat.vmdk are created as a result.
Note: If you are using ESXi, you can run the vmkfstools utility remotely using the vSphere CLI. For more information, see the vmkfstools Command Syntax section of the vSphere CLI documentation.
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 ( vmdisk0.vmdk in this example):
# mv temp.vmdk vmdisk0.vmdk
8. Edit the descriptor file with a text editor:
Find the line with RW ####### VMFS and change the name of the -flat to match the orphaned -flat file you have.
RW 8388608 VMFS "vmdisk0-flat.vmdk"
Find the line with ddb.thinProvisioned (if -d thin was used and the original was not a thin disk) and remove it:
ddb.thinProvisioned = "1"
The virtual machine is now ready for power on.
Note: If you are using ESXi, you can download, view, edit and upload files using the vSphere Client datastore browser or the vifs utility which comes with the vSphere API. The file can be edited using your preferred text editor. For more information about the usage of the vifs utility, see the vSphere CLI documentation.
Again this information was original taken from a KB article or forum discussion which I have saved to a my own documentation.
No comments:
Post a Comment