Resizing KVM Qcow2 Images - Maublog
Resizing KVM Qcow2 Images - Maublog
blog
;
code
a
contact
Resizing KVM
qcow2 images
While expanding qcow2 images is easy, nding an easy way to shrink them was not.
Recently, my Matrix VM ran out of disk space, while my miscellaneous hosting VM had way
too much space.
Since resizing images is often useful, I decided to make a fairly simple tutorial on how to
expand and shrink the images.
Expanding images
This is fairly straightforward. Due to the design of qcow2 images, you don’t even need to
have the disk space available right away.
3. 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.
Shrinking images
This is a bit more di cult. You will also need to have disk space to t both images at the
same time. For example, you want to resize a 100gb allocation to 50gb, your current image
shows 60gb used from outside (the qcow2 image) and has 30gb actually used inside. For
the change, you’ll need to have 50gb space for the resized image and 60gb for the existing
image, so 110gb total.
2. If you managed to resize the partition from within the virtual machine (and thus didn’t shut
it down already for resizing), shut it down now.
where NEW_SIZE is the size (50G for the example at the start).
4. Resize the image by copying the old image into the new one.
If the image created in the previous step is larger than the combined partitions on the old
image, virt-resize will inform you of a surplus and create a new partition. You can still
terminate the process without data loss and go back to step #3 to create a smaller image.
If the image is smaller than the partitions, virt-resize will fail and inform you how much
space needs to be added. In this case, you must create a larger image in step #3.
5. Start your VM. There may be some disk errors related to the stored block lengths. fsck
should be able to automatically x them.
If virt-resize created an extra partition, you can now use a partition editor to delete it and
add the space to another partition.
6. Once you have veri ed that the VM is working as expected, you can safely remove the old
image.
Tutorial
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
△ ▽ • Reply • Share ›