Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Virtualization / VMWare / Recovering a Deleted VMFS Datastore on VMware ESXi/vSphere

September 15, 2022 VirtualizationVMWare

Recovering a Deleted VMFS Datastore on VMware ESXi/vSphere

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

Suppose, a VMware administrator accidentally selected Delete instead of Unmount and removed a VMFS datastore.

You cannot unmount/delete a VMFS datastore that is in use, or if VMs or VMs with invalid (unknown) states are registered on it.

delete vmfs datastore on vmware esxi

First of all, don’t panic. Do not re-create the VMFS datastore from the vSphere interface again or do any other things that are able to overwrite data from the previous VMFS partition on your disk (LUN).

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

/vmfs/devices/disks/naa.60003ff44dc75adc87daa4e08f467565

In this example, I’m using an iSCSI VMFS datastore running on Windows Server (iSCSI target).

vmfs datastore get path

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

Make sure that the partition table exists on the device:

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

gpt
1305 255 63 20971520

partedUtil getptbl get partition table

Then you must get the first and the 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 the 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 info

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

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

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

getting vmfs partition last block

In our example, it is 20971486.

If the command returns the “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 that you have to use another gpt GUID for a vSAN datastore.

So we have got the following information:

  • LUN ID — naa.60003ff44dc75adc87daa4e08f467565
  • Start Block – 2048
  • End Block – 2097148
  • GPT GUID – AA31E02A400F11DB9590000C2911D1B8

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

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

re-create partition table on vmfs drive

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

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

check vmfs partition 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 the vSphere client and make sure that the accidentally deleted VMFS datastore appears. You can mount it on the VMware ESXi host or access it from 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

Previously, we showed how to use partedUtil to create a VMFS datastore on a USB flash drive and increase the size of the VMFS datastore using the command line tools. Learn more about how to use partedUtil to manage partition table in ESXi here: https://kb.vmware.com/s/article/1036609.

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

11 comments
1
Facebook Twitter Google + Pinterest
previous post
Using PowerShell Behind a Proxy Server
next post
How to Install Microsoft Teams Client on Linux

Related Reading

Reset Root Password in VMware ESXi

October 12, 2023

How to Fix ‘An Operating System Wasn’t Found’...

July 14, 2023

Unmounting an NFS Datastore from VMware ESXi

April 21, 2023

How to Increase Virtual Machine Disk Size in...

April 6, 2023

How to Install Free VMware Hypervisor (ESXi)

January 24, 2023

11 comments

John October 28, 2022 - 1:53 pm

I can’t thank the author enough for taking the time to craft this very detailed, easy to follow article. It saved us a world of hurt in the form of a long recovery outage. We followed the steps and the sense of relief when the VMFS volumes ‘re-appeared’ during an array migration gone wrong was palpable. Raise a glass to the author THANK-YOU.

Reply
Jens December 22, 2022 - 10:29 am

Is this still relevant at all when you have recreated a data store and vmdk? I panicked an recreated one to mount it to a VM and use some recovery software to see if anything could be recovered, but the description here seems way better.

I’m afraid I messed it up so that this guide isn’t relevant anymore..

Reply
admin January 9, 2023 - 4:09 am

It looks like you have already overwritten the VMFS partition structure and files on the disk, so this guide is not for your case

Reply
Kubo January 4, 2023 - 10:50 am

Thanks a lot, successfully recovered 3 datastores

Reply
Tony February 6, 2023 - 5:28 pm

You are a legend! Thanks you 100x’s! You’re guide was perfect!

Reply
Hank February 13, 2023 - 9:24 am

非常感謝您,很祥細的教學。
不過我卡在兩行指令:
vmkfstools -V
esxcli storage core adapter rescan –all
該指令對我沒有作用,替換成下列指令已成功。
esxcli storage vmfs snapshot list
esxcli storage vmfs snapshot mount -u [UUID]

Reply
sergio April 12, 2023 - 4:57 pm

ty bro!
GOD BLESS YOU ALL!!!

Reply
johndoe153 May 2, 2023 - 8:26 am

THX !!!!1

Reply
serg June 5, 2023 - 4:34 am

You cab use vSphere On-disk Metadata Analyzer (VOMA) to scan the VMFS volume metadata and highlights any inconsistencie

Reply
PC2023 November 15, 2023 - 8:59 pm

Any ideas on why the final setptbl command would fail with this..?

> 0 0 0 0
> 1 2048 2000409230 AA31E02A400F11DB9590000C2911D1B8 0
> Error: Read-only file system during write on /dev/disks/t10.NVMe____Samsung_SSD_970_PRO_1TB_________________AEAEB49155382500
> SetPtableGpt: Unable to commit to disk

The vSphere host is not in maintenance mode, and I get the same error after a reboot
THanks

Reply
serg November 16, 2023 - 12:03 pm

First, check the SMART status of the drive:
esxcli storage core device smart get -d drivename

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Adding Drivers into VMWare ESXi Installation Image
  • How to Fix ‘An Operating System Wasn’t Found’ Error on Windows
  • Shrinking VMDK Virtual Disk Size on VMWare ESXi
  • How to Access VMFS Datastore from Linux, Windows, or ESXi
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install and Configure Free Hyper-V Server 2019/2016
  • Updating Windows VM Templates on VMWare with PowerShell
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top