Contents
How do I shrink a QEMU image?
Resizing KVM qcow2 images
- Shut down the virtual machine.
- Resize the image with qemu-img resize image.qcow2 +SIZE. where SIZE is the size (e.g. 10G for 10 gibibytes).
- Boot into an external live OS and resize the partition. The easiest way to do this is to use a GParted live image and virt-manager to connect to the VM.
How do I create a KVM image?
Create the image
- Create an empty instance. First you must create a file that describes your minimal instance, which is a JSON file like the following.
- Copy in required files (OS, SDC VM tools, etc.)
- Boot the instance.
- Connect to the instance.
- Prepare the instance.
- Finalize the image.
How big of an image can I shrink?
Shrink the image to the size you want it to be. Remember, this has to be bigger than the total size of the Windows partitions on the disk. So, if there’s a 1GB partition and a 30GB partition, it’s probably safe to shrink the image down to 32GB to be safe.
How to shrink IMG file created with DD?
In order to shrink the image, GParted is going to be used along the first part of the answer. GParted operates on devices, not simple files like images. This is why we first need to create a device for the image. We do this using the loopback-functionality of Linux.
How to get rid of sparse image file?
Once the command errors out (this may take a while depending on your disk image size and physical disk speed) delete the file. Shutdown the guest and follow the steps below under All OS’s.
How much disk space can a sparse image file use?
Sparse disk image files allow you to over allocate virtual disk space – this means that you could allocate 5 virtual machines 100GB of disk space, even if you only have 300GB of physical disk space. If all the guests need 100% of their 100GB disk space then you will have a problem.