From e3c0ec7dd93f63b824db9bc5df999afcadf6afba Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Sun, 20 Dec 2015 13:54:55 +0000 Subject: Add support for converting final image to qcow2 --- bin/vmdebootstrap | 2 ++ doc/overview.rst | 1 + vmdebootstrap/filesystem.py | 14 ++++++++++++++ 3 files changed, 17 insertions(+) diff --git a/bin/vmdebootstrap b/bin/vmdebootstrap index ff30853..b9dc559 100755 --- a/bin/vmdebootstrap +++ b/bin/vmdebootstrap @@ -124,6 +124,7 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth 'included in the image.') self.settings.boolean(['no-acpid'], 'do not install the acpid package', default=False) self.settings.boolean(['no-update-initramfs'], 'Skip running update-initramfs', default=False) + self.settings.boolean(['convert-qcow2'], 'Convert final image to qcow2', default=False) self.settings.boolean(['dry-run'], 'do not build, just test the options', default=False) def process_args(self, args): # pylint: disable=too-many-branches,too-many-statements @@ -266,6 +267,7 @@ class VmDebootstrap(cliapp.Application): # pylint: disable=too-many-public-meth elif self.settings['squash']: filesystem.squash_rootfs() filesystem.chown() + filesystem.convert_image_to_qcow2() except BaseException as e: base.message('EEEK! Something bad happened...') diff --git a/doc/overview.rst b/doc/overview.rst index e2605b7..7347686 100644 --- a/doc/overview.rst +++ b/doc/overview.rst @@ -149,6 +149,7 @@ Options --dry-run Do not build, just test that the options are valid. --no-update-initramfs Skip the call to ``update-initramfs`` for reasons of speed or practicality. + --convert-qcow2 Convert the final raw image to qcow2 format. Configuration files and settings ******************************** diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py index 484371b..f5e6483 100644 --- a/vmdebootstrap/filesystem.py +++ b/vmdebootstrap/filesystem.py @@ -282,3 +282,17 @@ class Filesystem(Base): bootsize = self.settings['esp-size'] / (1024 * 1024) + 1 runcmd(['parted', '-s', self.settings['image'], 'mkpart', 'primary', str(bootsize), extent]) + + def convert_image_to_qcow2(self): + """ + Current images are all prepared as raw + rename to .raw and let the conversion put the + original name back + """ + if not self.settings['convert-qcow2']: + return + self.message('Converting raw image to qcow2') + tmpname = self.settings['image'] + '.raw' + os.rename(self.settings['image'], tmpname) + runcmd(['qemu-img', 'convert', '-O', 'qcow2', + tmpname, self.settings['image']]) -- cgit v1.2.1