Install qemu
This snippet for Mac OS, at Linux dists replace brew to apt/apk/yum/pkg
brew install qemu
Create empty hard disk raw image
Specify explicit image format (couse choosing qcow2 is minimal result image size), 1-st argument image name and 2-nd arg size.
qemu-img create -f qcow2 raw_hdd_10.qcow2 10G
Create virtual machine
After qemu-system- you can press tab and choose your cpu architecture, in my case is -x86_64. Then specify -boot disk d (it's cdrom), -cdrom image path and main hdd (-hda) image path.
qemu-system-x86_64 -boot d -cdrom ~/Downloads/alpine-virt-3.13.2-x86_64.iso -hda hdd10.qcow2
Install OS from bootable iso to hdd
In Alpine case:
setup-alpine
exit
Shutdown VM, and
Load installed OS from hdd image
qemu-system-x86_64 -hda hdd10.qcow2
Now you can make any your custom changes in OS.
At finally..
Filling nulls all free space for better compress hdd image, showing count nulled blocks (-v), From root mount point /
fstrim -v /
exit
Compress resulted image
Specify input -f and output -O image format, compression flag -c, then input and output image paths (they may be equal, if you don't need backup)
qemu-img convert -f qcow2 -O qcow2 -c hdd10.qcow2 hdd10-compressed.qcow2
Voila!
Tommorow we'll upload your custom image hdd10-compressed.qcow2 to cloud using openstack.
Top comments (2)
Have been super useful. Thank you.
Such useful information is shared with us!!
Make him want me spell