Recovering Deleted VMFS Datastore on VMware ESXi/vSphere |

Let’s look at the issue when your VMFS datastore connected to ESXi host/vSphere is deleted, lost, or damaged. This can happen, for example, due to a human error when a VMware administrator accidentally deleted the VMFS datastore or the disk/LUN containing the VMFS partition was disabled/lost due to errors on your storage/backup device. In this article, we will show how to manually recover partition table on disk with VMFS Datastore.

Suppose, a VMware administrator got selected by mistake delete Instead unmount And removed a VMFS datastore.

delete vmfs datastore on vmware esxi

First of all don’t panic. Do not recreate the VMFS datastore from the vSphere interface or do any other thing that may be able to overwrite data from the previous VMFS partition on your disk (LUN).

Open the vCenter client interface, go to Storage -> Devices, and find the disk/LUN with the VMFS datastore already connected in the list. get full path of disk (with identifier). In my screenshot, it is:


get vmfs datastore path

Enable SSH on your ESXi host on which the target LUN is available and connect to it using the SSH client (I’m using the built-in Windows SSH client).

Make sure the partition table exists on the device:

partedUtil getptbl /vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565
The command returns that there is a GPT on the disk/LUN.

1305 255 63 20971520

partedUtil getptbl get partition table

You should then find the first and last block of the VMFS partition on the disk.

To display a summary of all partitions available from the ESXi host and find the first block of a deleted VMFS partition, run the script below in the ESXi cli:

offset="128 2048"; for dev in `esxcfg-scsidevs -l | grep "Console Device:" | awk {'print $3'}`; do disk=$dev; echo $disk; partedUtil getptbl $disk; { for i in `echo $offset`; do echo "Checking offset found at $i:"; hexdump -n4 -s $((0x100000+(512*$i))) $disk; hexdump -n4 -s $((0x1300000+(512*$i))) $disk; hexdump -C -n 128 -s $((0x130001d + (512*$i))) $disk; done; } | grep -B 1 -A 5 d00d; echo "---------------------"; done

get vmfs partition information

In this example, we have displayed information about the deleted partition (TestVMFS) and obtained the number of the first block of the partition: 2048,

Now we need to get the last block of the VMFS partition on disk:

partedUtil getUsableSectors /vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565

vmfs getting partition last block

In our example, it is 20971486,

If the command “returns”Unknown partition table on disk“Error, set the GPT partition label manually:

partedUtil mklabel /vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565 gpt

Then get a partition table GUID for the VMFS partition. it is always AA31E02A400F11DB9590000C2911D1B8,

You can display all possible partition table GUIDs using this command:

partedUtil showGuids

VMFS Partition GUID

This means you have to use another gpt GUID for a vSAN datastore.

So we’ve got the following information:

  • loon id — naa.60003ff44dc75adc87daa4e08f467565
  • start block – 2048
  • end block – 2097148
  • GPT Guide – AA31E02A400F11DB9590000C2911D1B8

Then create a partition table on the disk using the information you got:

partedUtil setptbl /vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565 gpt "1 2048 20971486 AA31E02A400F11DB9590000C2911D1B8 0"

recreate partition table on vmfs drive

Check the partition on the disk again and make sure the VMFS partition is now visible:

partedUtil getptbl /vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565

vmfs partition check esxi cli

Now you need to mount the VMFS datastore:

vmkfstools -V
esxcli storage core adapter rescan --all

esxcli storage core adapter rescan

Go to vSphere Client and make sure the VMFS datastore you deleted by mistake is visible. You can mount it on a VMware ESXi host or access it from a Linux or Windows host.

mount vmfs datastore in esxi vsphere client

All files, including ISO images and virtual machine files, are available on the restored VMFS datastore.

Browse files on vmware vmfs datastore

This guide is relevant for VMware ESXi/vSphere 6.0, 6.5 and 7.0.

Leave a Comment