Recovering an Accidentally Deleted VMFS Datastore in VMware ESXi or vSphere
Your VMFS datastore attached to an ESXi host or vSphere For example, when a VMware administrator accidentally removes it, or when a disk/LUN with a VMFS partition is disabled/lost due to errors in your storage/backup device, it accidentally chooses Erase instead of Unmount and deletes a VMFS datastore. Let's process the scenario he removed.
First of all, don't panic. Do not rebuild the VMFS datastore from the vSphere interface, do not upload files, or do anything that could overwrite the data on the previous VMFS partition on your disk (LUN).
As you can see I accidentally deleted 19.75 GB of Lun space, the storage appears to be empty
Enable SSH on your ESXi host with the deleted LUN and connect with an SSH Tool
SSH
partedUtil getptbl /vmfs/devices/disks/mpx.vmhba0:C0:T1:L0 gpt 2610 255 63 41943040 [root@esxi7:~] #The command has returned that there is a GPT on the disk/LUN.
Next, you need to get the first and last block of the VMFS partition on the disk.
Run the following script in the cli to view a summary of all partitions found on the ESXi host and find the first block of the deleted VMFS partition:
SSH
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
Now we need to disk the last block of the VMFS partition:
partedUtil getUsableSectors /vmfs/devices/disks/mpx.vmhba0:C0:T1:L0 # 34 41943006 # [root@esxi7:~]
If the command returns the error “Unknown partition table on disk”, manually set the GPT partition label:
partedUtil mklabel /vmfs/devices/disks/mpx.vmhba0:C0:T1:L0 gpt
Then get a partition table GUID for the VMFS partition. It is always AA31E02A400F11DB9590000C2911D1B8
partedUtil showGuids #You can view all possible partition table GUIDs using this command:
Then create a partition table on the disk using the information you have:
partedUtil setptbl /vmfs/devices/disks/mpx.vmhba0:C0:T1:L0 gpt "1 2048 41943006 AA31E02A400F11DB9590000C2911D1B8 0" #gpt #0 0 0 0
Check the partitions on the disk again and make sure the VMFS partition is now visible: **Alanim_Data
partedUtil getptbl /vmfs/devices/disks/mpx.vmhba0:C0:T1:L0 # gpt # 2610 255 63 41943040 # 1 2048 20971486 AA31E02A400F11DB9590000C2911D1B8 vmfs 0
Now let's mount the VMFS datastore:
vmkfstools -V esxcli storage core adapter rescan --all
Go to the vSphere client and you will see that the accidentally deleted VMFS datastore has been loaded. You can mount it to the VMware ESXi host manually or via the CLI:
Or Mount Command:
esxcli storage filesystem list
esxcli storage filesystem mount -l Alanim_Data #esxcli storage filesystem unmount -l Alanim_Data
Saygılarımla. – Best regards.