0

I have more than 30 qemu-kvm process open with different images. Their images where accidentally deleted. I searched and i found out that as the file is still open in a process. It can be still recovered. So i have followed this https://unix.stackexchange.com/questions/297475/accidentally-removed-a-libvirt-image-file-can-i-recreate-it. I stopped the process. Copied the file /proc/pid/fd/19 using dd command.

Here the issue begins.

I copied the file and restored it then restarted the process and now i recovered the file. The whole issue is that when i copy the open descriptor with dd command it takes alot of space. "It shouldn't take any space because after coping it, I kill the process so the descriptor is deleted only the copied file exists so the storage should be the same". I have tried the same accepted answer in a different process. But i used cp command not dd. It didn't take any space after killing the process. Now i want to know where did my space go. I did the restore for more than 20 process with dd command and now my disk is full and i can't do it for the rest of processes. I want to free up the space that dd command took and i will use cp with the rest of processes as it works for me better than dd and it doesn't take any space.

Mr Pro
  • 3
  • It could be the original was a sparse file, that is, it is marked as taking up X space when in reality, it's X/2. But when you copy it from the fd, the sparseness if gone and you copy the full X size. – Bib Aug 07 '21 at 18:25
  • @Bib Thank you, That looks correct. I will try to use virt-sparsify to reclaim the space. – Mr Pro Aug 07 '21 at 18:36
  • I'll make it an answer then. – Bib Aug 07 '21 at 18:39
  • 1
    I wrote a cp (to be prefered over dd) as well as a dd entry in this answer: https://unix.stackexchange.com/questions/657566/write-an-image-to-disk-but-do-not-write-sectors-containing-all-zeroes-in-the-sou/657593#657593 . Look also for fallocate --dig-holes. Of course here the target is a file. – A.B Aug 07 '21 at 18:42

1 Answers1

2

It could be the original was a sparse file, that is, it is marked as taking up X space when in reality, it's less than X. But when you copy it from the fd, the sparseness is gone and you copy the full X size.

Stephen Kitt
  • 434,908
Bib
  • 2,380