How to recover a runnig KVM machine, but with deleted "/var/lib/vz/images/" files??

JMoreno

Renowned Member
Oct 26, 2011
53
2
73
Dear all,

It may sound crazy but, by mistake, the KVM files in my ProxMox machine under:

/var/lib/vz/images/<VMID>

were manually deleted while the machine was running. The KVM machine is still working smoothly (I can't understand how/why), but I am affraid the KVM machine will die if I restart/stop the machine.

I would appreciate any help in order to recover the corresponding qcow2 files in:

/var/lib/vz/images/<VMID>

Many thanks
PS: Believe me, I am about to suffer a heart-attack.
 
Re: How to recover a runnig KVM machine, but with deleted "/var/lib/vz/images/" files

Thanks for your quick reply.

Let me sumarized what I did after reading your link. Asuming 501 as the VMID I wanted to recover:

Code:
lsof | grep kvm | grep [COLOR=#ff0000]501[/COLOR]

I got:

Code:
...
kvm [COLOR=#0000ff]      275741[/COLOR]     root   [COLOR=#00ff00]13[/COLOR]u      REG              253,2  68719476736   63299585  [COLOR=#008080](deleted)[/COLOR]/var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]1[/COLOR].raw
kvm       [COLOR=#0000ff]275741[/COLOR]     root   [COLOR=#ff8c00]15[/COLOR]u      REG              253,2 274877906944   63299587  [COLOR=#008080](deleted)[/COLOR]/var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]2[/COLOR].raw
kvm       [COLOR=#0000ff]275741[/COLOR]     root   [COLOR=#800080]16[/COLOR]u      REG              253,2 274877906944   63299586  [COLOR=#008080](deleted)[/COLOR]/var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]3[/COLOR].raw
...

With that information, I typed:

Code:
mkdir /var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]
chmod 777 /var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]
cp /proc/[COLOR=#0000ff]275741[/COLOR]/fd/[COLOR=#00ff00]13[/COLOR] /var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]1[/COLOR].raw
cp /proc/[COLOR=#0000ff]275741[/COLOR]/fd/[COLOR=#ff8c00]15[/COLOR] /var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]2[/COLOR].raw
cp /proc/[COLOR=#0000ff]275741[/COLOR]/fd/[COLOR=#800080]16[/COLOR] /var/lib/vz/images/[COLOR=#ff0000]501[/COLOR]/vm-[COLOR=#ff0000]501[/COLOR]-disk-[COLOR=#b22222]3[/COLOR].raw

After these steps:

- I stoped the KVM machine
- Once it stoped, I started the KVM machine again.

I know, it looks like a rainbow arc ;), but it helps understanding where the different values come from.

I can not find words to really thank your help and support in this issue!!
Regards.