I am trying to reduce image size using dd conv=sparse, but no matter what I do, the image size is still huge.
I have a CentOS image which is around 136GB. The main reason it being so big is that it has a 128GB swap.
When I ran du -sh, this is the output
# du -sh centos_raw.img
2.0G centos_raw.img
So what I have attempted to do is to use virt-sparsify to reduce it. Here are the results:
# virt-sparsify centos_raw.img centos_raw_sparse.img
[ 0.2] Create overlay file in /tmp to protect source disk
[ 0.2] Examine source disk
- 25% [###############################################----------------------------------------------------------------------------------------------------------------------------------------------] --:--
100% [#############################################################################################################################################################################################] 00:00
[ 32.1] Fill free space in /dev/sda2 with zero
100% [#############################################################################################################################################################################################] 00:00
[ 43.5] Clearing Linux swap on /dev/sda3
100% [#############################################################################################################################################################################################] 00:00
[ 955.3] Fill free space in /dev/sda4 with zero
100% [#############################################################################################################################################################################################] 00:00
[1054.3] Copy to destination and make sparse
[1068.3] Sparsify operation completed with no errors.
virt-sparsify: Before deleting the old disk, carefully check that the
target disk boots and works correctly.
However, the size is still the same. It is still 136GB.
When I ran du -sh again, the size did get reduced.
# du -sh centos_raw_sparse.img
1.3G centos_raw_sparse.img
I am planning to use this image to use for openstack baremetal image, and the image is really big to transferred through the network