From a1fc1430597086550c89d752c36be41e88fdaa5c Mon Sep 17 00:00:00 2001 From: Carlos Meza Date: Fri, 9 Feb 2018 20:52:47 +0000 Subject: [PATCH] compress qcow2 when shrinking --- bootstrapvz/plugins/minimize_size/tasks/shrink.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bootstrapvz/plugins/minimize_size/tasks/shrink.py b/bootstrapvz/plugins/minimize_size/tasks/shrink.py index d568421..225de35 100644 --- a/bootstrapvz/plugins/minimize_size/tasks/shrink.py +++ b/bootstrapvz/plugins/minimize_size/tasks/shrink.py @@ -70,6 +70,10 @@ class ShrinkVolumeWithQemuImg(Task): @classmethod def run(cls, info): tmp_name = os.path.join(info.workspace, 'shrunk.' + info.volume.extension) - log_check_call( - ['qemu-img', 'convert', '-O', info.volume.extension, info.volume.image_path, tmp_name]) + shrink_cmd = ['qemu-img', 'convert', '-O', info.volume.extension, info.volume.image_path, tmp_name] + # Compress QCOW2 image when shrinking + if info.volume.extension == 'qcow2': + # '-c' indicates that target image must be compressed (qcow format only) + shrink_cmd.insert(4, '-c') + log_check_call(shrink_cmd) os.rename(tmp_name, info.volume.image_path)