Deleted image of running vm

twister666

New Member
May 11, 2011
14
0
1
Montreal, Quebec, Canada
Hello everyone!

By accident I deleted a image of a running vm. The vm folder is empty but my vm been running for past month and a half and no trouble. Now I need to restart the server and worry if I restart will lose the vm. Is there a way to get back the image file or there is no way?

Thanks
 
Hello everyone!

By accident I deleted a image of a running vm. The vm folder is empty but my vm been running for past month and a half and no trouble. Now I need to restart the server and worry if I restart will lose the vm. Is there a way to get back the image file or there is no way?

Thanks

Hi,
don't restart or stop the VM!! Then is you disk-file lost.

Linux mark the file as deleted, but since a process have open the file for writing, it's still excist.

Look with lsof to find the file??

Udo
 
Hi,
don't restart or stop the VM!! Then is you disk-file lost.

Linux mark the file as deleted, but since a process have open the file for writing, it's still excist.

Look with lsof to find the file??

Udo
Here a short discription. In this case the VM-disk of VM 101 was deleted:
Code:
# lsof | grep 101
...
kvm       3649       root   18u      REG              253,2 2147483648     524290  (deleted)/var/lib/vz/images/101/vm-101-disk-1.raw
...
Importand is the pid (3649) and the filediscriptor (18)
do an copy (before that, it's a good idea to stop important services with open files inside the VM, like databases)
Code:
cp /proc/3649/fd/18 /var/lib/vz/images/101/vm-101-disk-1.raw.sav
Voila, the disk-file (of an open-VM!) is copied back.

I would test the copied file with an dummy-VM before i shutdown the original VM!

Udo
 
Here a short discription. In this case the VM-disk of VM 101 was deleted:
Code:
# lsof | grep 101
...
kvm       3649       root   18u      REG              253,2 2147483648     524290  (deleted)/var/lib/vz/images/101/vm-101-disk-1.raw
...
Importand is the pid (3649) and the filediscriptor (18)
do an copy (before that, it's a good idea to stop important services with open files inside the VM, like databases)
Code:
cp /proc/3649/fd/18 /var/lib/vz/images/101/vm-101-disk-1.raw.sav
Voila, the disk-file (of an open-VM!) is copied back.

I would test the copied file with an dummy-VM before i shutdown the original VM!

Udo

Thanks
Very useful
 
Here a short discription. In this case the VM-disk of VM 101 was deleted:
Code:
# lsof | grep 101
...
kvm       3649       root   18u      REG              253,2 2147483648     524290  (deleted)/var/lib/vz/images/101/vm-101-disk-1.raw
...
Importand is the pid (3649) and the filediscriptor (18)
do an copy (before that, it's a good idea to stop important services with open files inside the VM, like databases)
Code:
cp /proc/3649/fd/18 /var/lib/vz/images/101/vm-101-disk-1.raw.sav
Voila, the disk-file (of an open-VM!) is copied back.

I would test the copied file with an dummy-VM before i shutdown the original VM!

Udo
Years later, you still saved my day!
Thanks very much!
 
Question on this post. If the VM is deleted by accident and the VM is stopped is there a way to recover?
If you deleted the image of a stopped vm (or stopped it afterwards) AFAIK there is no simple way to recover, best recover from backup
 
Thank you, stil very useful in 2021.

Still have no idea how 2 KVM disks were deleted.

P.
 
Hello.
I just created an account just to write thank you for this very brilliant way to save the .qcow2 file.
Mike
 
  • Like
Reactions: udo