VMware Cloud Community
lukftw
Contributor
Contributor

Recover partition table after accidentally use partedUtil on whole disk

I have installed vmware esxi 6.5 and accidentally used partedUtil on the whole disk instead of one partition. On that this I had windows 10 and 600gb of data and now I can't boot the windows. Is there a way to revert the partedUtil action?

This is the command i ran:

partedUtil mklabel /dev/disks/diskid msdos

Tags (2)
Reply
0 Kudos
8 Replies
daphnissov
Immortal
Immortal

What were the exact commands you ran?

Reply
0 Kudos
lukftw
Contributor
Contributor

partedUtil mklabel /dev/disks/diskid msdos

Reply
0 Kudos
daphnissov
Immortal
Immortal

What disk did you run that against? Was it the ESXi boot disk? A secondary drive that was formatted as VMFS? Something else? Normally ESXi will prevent you from changing the disk label when running that command so I'm curious what disk allowed it to be run.

Reply
0 Kudos
lukftw
Contributor
Contributor

I am running Esxi from an Usb Drive so this is primary, the hdd is secondary.

Reply
0 Kudos
daphnissov
Immortal
Immortal

And you ran this against the secondary disk only?

Reply
0 Kudos
lukftw
Contributor
Contributor

Yes

Reply
0 Kudos
daphnissov
Immortal
Immortal

You may be able to recover the partition information provided you haven't made any further changes to the partition map or disk layout.

Look at the current msdos label to get the start and end sectors. Reminder you can get the disks by doing ls -l /vmfs/volumes/disks. The disk in question will be the only one with a single partition identified by a ":1" at the end.

[root@localhost:~] partedUtil getptbl /vmfs/devices/disks/naa.6000c29ba9e2a45bc6e242df17378b3c

msdos

2610 255 63 41943040

In my above example, I've run the same command you did on a single disk that was holding a single VMFS partition (gpt). This changed the label to msdos and effectively wiped the partition map.

If you have the original read-out of the structure before you converted the partition type then good, otherwise we'll assume there is only one partition on the disk and it follows standard practices for the structure.

Here's what a normal table looks like before running your command. Bottom line, from left to right is the partition number, starting sector, ending sector, GUID or identifying type, and attribute.

[root@localhost:~] partedUtil getptbl /vmfs/devices/disks/naa.6000c29ba9e2a45bc6e242df17378b3c

gpt

2610 255 63 41943040

1 2048 41940992 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

Again, assuming you changed nothing and this is a basic VMFS layout, run the following command to change the partition back. I'm not guaranteeing this will work for you or that you will not lose data. Just be clear on that point. Also, I verified these steps on ESXi 6.5 with a single drive supplying a single VMFS datastore formatted as VMFS-5. If you differ from this configuration, again, your mileage may vary.

partedUtil setptbl /vmfs/devices/disks/naa.6000c29ba9e2a45bc6e242df17378b3c gpt "1 2048 xxxx AA31E02A400F11DB9590000C2911D1B8 0"

Above, the "xxxx" is the ending sector for the partition. If you retained the original output when you first ran getptbl, you can reuse that value. Mine from above was 41940992. If you did *not* retain that command, you'll have to assume the default byte offset from the entirety of the disk, and by default on VMFS single-partition layout is 2,048. So take the output from partedUtil getptbl /vmfs/devices/disks/naa.6000c29ba9e2a45bc6e242df17378b3c and subtract 2,048 from the total disk size (41943040 - 2048 = 41940992). This will be the ending sector locator. The portion that reads AA31E02A400F11DB9590000C2911D1B8 you must copy and paste as this is the signifier for VMFS. Use 0 at the end of the string. Enclose all in double quotes as I've shown.

Check the partition table after the command is successful.

[root@localhost:~] partedUtil getptbl /vmfs/devices/disks/naa.6000c29ba9e2a45bc6e242df17378b3c

gpt

2610 255 63 41943040

1 2048 41940992 AA31E02A400F11DB9590000C2911D1B8 vmfs 0

If this was successful, you should now be able to power on your VM.

Reply
0 Kudos
daphnissov
Immortal
Immortal

Does this help? Does it not? Did you try it?

Reply
0 Kudos