Reputation: 53
I use a tool named virt-sparsify to free disk space a qcow2 image file occupies.
It works and the file becomes a sparse file.
root@ubuntu:/test# ls -lsh test.qcow2
8.7G -rw-r--r-- 1 root root 15G Jan 19 11:05 test.qcow2
As shown above, the disk size allocated for the file is smaller than its actual size. It means there are “holes” in the file. Now I want to remove these holes inside it. Does anyone know how to achieve this purpose?
Upvotes: 1
Views: 2109
Reputation: 151
You can't really "take away" the sparse flag. Tools try to help by keeping the flag alive e.g. cp when copying.
You can easily get a non-sparse version of that file via
cp --sparse=never test.qcow2 test-nosparse.qcow2
The same way you can make a partially zeroed out file a sparse file
cp --sparse=always file.qcow2 file-sparse.qcow2
See "sparse" in man cp
Upvotes: 1