VM Disk recovery

mclordo

New Member
Jun 25, 2023
5
1
3
Quick: A VM disk in a ZFS pool has lost its partitions, most likely due to overwriting. Where did I screw up, and what are my options to recover the data/ the whole VM?

What Happened:
My setup consists of a ZFS pool called "Proxmox-ZFS" with two 4TB HDDs mirrored.
1711751142059.png

The VM in question is the 104 with a Win11 installation. The creation worked perfectly and the VM ran without any problems.

Next, I wanted to convert an old laptop into a VM. After creating the VHDX file with disk2vhd, I saved it to /Proxmox-ZFS (mounting of ZFS pool). The reason for this was that my Proxmox host had no space for 313G and since I still had space in the ZFS pool I thought this was not a problem. (I don't know if I already made a mistake here...). But so far all VMs still worked.

Then I created a new VM 103 (previously deleted) , with a new empty hard drive in the "Proxmox-ZFS" pool (Proxmox-ZFS/vm-103-disk-0) sizing 500G. Now I have executed the following command:
Code:
sudo qemu-img convert -p -O raw /Proxmox-ZFS/laptopDrive.VHDX /dev/zvol/Proxmox-ZFS/vm-103-disk-0
The intention was replacing the vm-103-disk-0 with the converted laptop hard disc. At that time, there was probably around 800G of available storage left on the ZFS pool. Since the command took a good amount of time, I left the scenery and when I came back:
VM 101 (previously running) crashed but could be restarted without problems
VM 102 (previously off) can be started without any problems
VM 103 (previously off) boots in secure boot and tries to restore data
VM 104 (previously running) crashed and cannot find a partition when restarting

The big problem is VM 104 which has no partitions anymore. Inspecting the 500G Disk:
Code:
fdisk -l /dev/zvol/Proxmox-ZFS/vm-104-disk-1

1711753167404.png

Code:
kpartx -a /dev/zvol/Proxmox-ZFS/vm-104-disk-1
1711753333245.png

So I'm interested to know at what point I screwed up, as it looks to me as a beginner as if I've overwritten the wrong memory or at a moment in time I ran out of memory in my ZFS Pool.
And of course, I'm even more interested in how to fix it.

Thanks in advance
 
Hi!

"qemu-img" is for "file-based" image tool not "block-device" tool.

Code:
Example:
$> qemu-img convert -p -O raw /Proxmox-ZFS/laptopDrive.VHDX /Proxmox-ZFS/laptopDrive.RAW
$> losetup -f
/dev/loop0

$> losetup /dev/loop0 /Proxmox-ZFS/laptopDrive.RAW
$> dd if=/dev/loop0 of=/dev/zvol/Proxmox-ZFS/vm-103-disk-0

$> losetup -d /dev/loop0

DONE

Recovery:
Did You have snapshot ?
Code:
$> zfs list -t snapshot
If yes, you can restore the previous state, if not thats a problem.
 
Last edited:
  • Like
Reactions: Kingneutron
Thanks for the reply.

"qemu-img" is for "file-based" image tool not "block-device" tool.
Thanks for that clarification. I already knew that you have to mount the VM disk using a loopback device, but thought qemu-img is able to make this transition.

Did You have snapshot ?
Luckily, I got a Snapshot, but I'm afraid to do a rollback because the snapshot is in the same pool and could also be corrupted. My fear is that I will do more harm than good with the rollback. Is that a justified concern? If so, is there a way to use disk recovery tools first?

Read something about TestDisk, but it only lists actual real hard drives on the host to perform actions...
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!