DEV Community

Cover image for Minimalistic way to create cloud image from ISO with QEMU
Mikhail
Mikhail

Posted on

Minimalistic way to create cloud image from ISO with QEMU

Install qemu

This snippet for Mac OS, at Linux dists replace brew to apt/apk/yum/pkg

brew install qemu
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Install OS from bootable iso to hdd

In Alpine case:

setup-alpine
exit
Enter fullscreen mode Exit fullscreen mode

Shutdown VM, and

Load installed OS from hdd image

qemu-system-x86_64 -hda hdd10.qcow2
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Voila!
Tommorow we'll upload your custom image hdd10-compressed.qcow2 to cloud using openstack.

Latest comments (2)

Collapse
 
aaliyahdollar profile image
AaliyahDollar

Such useful information is shared with us!!
Make him want me spell

Collapse
 
blueray profile image
Ahmad Ismail

Have been super useful. Thank you.