Two cases:
1.If making hdd image using dd and copy it trough nfs to another server:
mount -o ro,remount /
dd if=/dev/sda bs=64K | gzip -c > /share/test.img.gz
then after gunzip I get 20Gb (for ex.) file, filled w/zeroes at the end:
du -h /md/share/test.img
21G /md/share/test.img
2. If I create empty image using dd:
dd if=/dev/zero of=/md/share/test2.img bs=1024k seek=20480 count=0
I got:
du -h /md/share/test2.img
0 /md/share/test2.img
ls -lah /md/share/test2.img
-rw-r--r-- 1 root root 20G Aug 2 14:46 /md/share/test2.img
After mounting this to guest, I can use all 20G in any way I want, and IMG size is always equal it's actual contents, without any "zeroes" eating my array space.
Question: how I can reduce disk image size for case 1?
Answer: if dd supports conv=sparse
attribute, it must be used in addition to tar --sparse
. If not, update coreutils
and try it again. Else install package libguestfs-tools
and run virt-sparcify /md/share/test.img /md/share/test_sparse.img