Skip to content

Instantly share code, notes, and snippets.

@Spenser309
Created February 9, 2017 01:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Spenser309/2ec1358b03e2f7beaf07e77f3f680589 to your computer and use it in GitHub Desktop.
Save Spenser309/2ec1358b03e2f7beaf07e77f3f680589 to your computer and use it in GitHub Desktop.
Example of how to resize and recompress a disk image for openstack
$ openstack --os-identity-api-version=3 image save --file <filename> <image name>
$ virt-df -h -a <filename> # shows used/free disk space
$ guestfish -a <filename> <<EOF
run
list-filesystems # informational only
e2fsck-f /dev/sda1
resize2fs-size /dev/sda1 <size>G
exit
EOF
$ qemu-img create -f qcow2 <filename>.qcow2 <size>.2G # Add 200MB as padding
$ virt-resize --resize /dev/sda1=<size>G --no-extra-partition <filename> <filename>.qcow2
$ qemu-img convert -O qcow2 -c <filename>.qcow2 <filename>.qcow2c
$ virt-df -h -a <filename>.qcow2c # validate changes
$ openstack --os-identity-api-version=3 image create --disk-format=qcow2 --min-disk=<size+1>G --file <filename>.qcow2c <image name>
@ariesyous
Copy link

Have you found that using the -c option actually results in a much smaller disk? I've done some internal testing and found conversions move super fast without the -c flag, but the resulting file is definitely larger. What format is it being compressed in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment