There are different reason where you can you loose or corrupt your partition table of your VMFS volumes: resignature from another system (for example the backup server, if connected in SAN mode), a human mistake (datastore / delete), or maybe some storage issues.
In this case usually the VMFS partition is still there and also the related data: you have “only” to rebuild the right partition table. But this could really simple if you follow the recommended practice to have only one VMFS partition on each disk. In this case you have only to build the configuration for a single partition (with VMFS type) starting from the right offset (VMFS partitions are aligned) and ending on the latest block.
But you may need a different tool depending the type of partition table:
- For legacy MBR disk you have to use fdisk command and is quite simple (especially if you know it for Linux)
- For new GPT disk you have to use partedUtil that is little more tricky and complicated.
Starting from ESXi 5.0 the new GPT format is used by default on all new disks, but if you have a previous VMFS3 this will not necessary be converted to GPT, also if you upgrade it to VMFS5 (for more information see this post). Only when you extend it to more than 2 TB it will be converted to GPT (and of course must be VMFS5 before the extension).
So on ESX/ESXi to version 4.1 you are sure to use MBR disk, on ESXi from version 5.0 you have to check your disk type (you can simple use fdisk -l command).
Recover a lost VMFS partition on a MBR disk
You can use the KB 1002281 (Recovering a lost partition table on a VMFS volume) that explain the required steps:
- Log in to the ESX host service console. For ESXi, see Tech Support Mode for Emergency Support (1003677)
- Run the command:fdisk -l
- Identify the affected disk (you will notice that the partition table is missing on it) and take note of the name (something starting with /dev/disks/…)
- Start fdisk with this command and press Enter:fdisk -u /dev/disks/…
- Create the partition:
- Press n and press Enter to create a new partition.
- Press p and press Enter to select that this is a primary partition.
- Press 1 and press Enter to make the first partition.
- Press 128 and Enter to align the partition to sector 128.
- Press Enter again to retain the default value.
- Change the partition to type fb (VMFS):
- Press t and press Enter. Partition 1 is automatically selected.
- Enter fb and press Enter.
- Press w and press Enter to save.
- Run vmkfstools -V and press Enter to discover the VMFS.
Recover a lost VMFS partition on a GPT disk
The partedUtil is a not interective command so could be a little more complicated. For more information on this command you can see the KB 1036609(Using the partedUtil command line utility on ESXi/ESX).
In order to recover your partition, first you need some information that you can obtain still with fdisk -l
You can notice that the second disk is empty and from this screen you can define both the name of the disk and also the usable sector. To gain this second information you can also query the disk with the partedUtil getUsableSectors
command:
Those number are really important, because to know the usable last sector you have to make the difference between those munbers (in the example 20971520 – 34 = 20971486).
Now you can use partedUtil setptbl
to create your partition and the syntax is:
partedUtil setptbl diskName label "partNum startSector endSector type/guid attr"
The diskName is the one from the fdisk -l output, and the label is quite simple because is just gpt. The complex part is the list of partitions are specified as quoted strings, each of which encapsulates a 5-tuple composed of the partition number, starting sector, ending sector, type ID, and attributes:
- The
startSector
is usually 2048 (the aligment used in VMFS-5).Note: Volumes that are upgraded from VMFS-3 to VMFS-5 continue to have the VMFS partition starting at sector 128, rather than at sector 2048. - The
endSector
is calculated from the difference of the two values that you get frompartedUtil getUsableSectors
.Note: the first number is usually 34 - The partition
type
identifies the purpose of a partition, and may be represented by either a a decimal identifier (for example,251
) or a UUID (for VMFS, AA31E02A400F11DB9590000C2911D1B8). Partitions created on ESXi 5.0 and higher with thegpt
disklabel must be specified using the GUID. - The partition
attribute
is a number which identifies properties of the partition. A common attribute is128 = 0x80
, which indicates that the partition is bootable. Otherwise, most partitions have an attribute value of0
.
So in the previous example, the command to rebuild the missing partition (note that is just for this example: don’t use as-is on your running system) is:
partedUtil setptbl /dev/disks/mpx.vmhba1:C0:T1:L0 gpt "1 2048 20971486 AA31E02A400F11DB9590000C2911D1B8 0"
Caution: There is no facility to undo a partition table change other than creating a new partition table. Ensure that you have a backup before marking any change. Ensure that there is no active I/O to a partition prior to modifying it.