-2

Does anyone has such experience that you accidentally delete the used disk image when virtual machine is running?

I would expect that the virtual machine will fail immediate, but, surprisingly, it still running perfectly. I have tried to execute many I/O commands and even create very large files by "dd" which are totally more larger then the vm's memory size. But it is still live.

Can anyone explain why?

Server info: ubuntu 12.04 with KVM and libvirt installed from default repo. VM's disk image is qcow2 format.

user1817188
  • 183
  • 1
  • 8
  • I am not sure how to make the question more clearly. After I got the answer I know it is nothing about virtual machine, but the linux file system. Maybe some other guy who do not familiar in file system may have similar question as this. – user1817188 Jul 09 '13 at 01:39

2 Answers2

7

Deleting a file does not actually delete the file, it reduces the number of names pointing to an inode. If both the number of names and the number of open file descriptors to the file reach 0, the data gets deleted.

So if you delete a file that's still open by some application, that application can still happily use that file. Only when the last file descriptor gets closed, the file gets deleted (and then you'll see the used space is reclaimed again).

arjarj
  • 2,981
  • 1
  • 16
  • 10
5

When you delete a file that has an open file descriptor, it's not actually deleted until the file descriptor is closed. You can probably find that file using lsof | grep deleted command.

Try this if you want to undelete the file: http://www.serverwatch.com/tutorials/article.php/3822816/Recovering-Deleted-Files-With-lsof.htm

martian111
  • 381
  • 1
  • 6