Skip to content

Instantly share code, notes, and snippets.

@smurugap
Last active February 14, 2023 14:09
Show Gist options
  • Save smurugap/357e705944e14af0799884cb0effac6c to your computer and use it in GitHub Desktop.
Save smurugap/357e705944e14af0799884cb0effac6c to your computer and use it in GitHub Desktop.
Source: https://albertomolina.wordpress.com/2016/12/02/shrinking-qcow2-images/
virt-df -h image.raw
Filesystem Size Used Available Use%
image.raw:/dev/sda1 1.9G 1020M 837M 52%
guestfish
><fs> add image.raw
><fs> run
><fs> list-filesystems
/dev/sda1: ext4
><fs> e2fsck-f /dev/sda1
><fs> resize2fs-size /dev/sda1 1500M
><fs> e2fsck-f /dev/sda1
><fs> quit
virt-df -h image.raw
Filesystem Size Used Available Use%
image.raw:/dev/sda1 1.4G 1020M 333M 71%
root@a2s42:/var/lib/libvirt/images# qemu-img resize -f raw image.raw 1.5G
Image resized.
root@a2s42:/var/lib/libvirt/images# qemu-img info image.raw
image: image.raw
file format: raw
virtual size: 1.5G (1610612736 bytes)
disk size: 1.5G
Other sources:
https://jtechboard.blogspot.com/2017/11/openstack-shrink-image-virtual-disk-size.html
https://gist.github.com/cojocar/163d2a37f99519ad0a40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment