summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Williams <codehelp@debian.org>2015-12-20 13:54:55 +0000
committerNeil Williams <codehelp@debian.org>2015-12-20 13:54:55 +0000
commite3c0ec7dd93f63b824db9bc5df999afcadf6afba (patch)
tree65c17e609df2075ae0d15ab6ed79efa5b273932a
parent44755d660520eade161bee83d665888fa57cdb56 (diff)
downloadvmdebootstrap-e3c0ec7dd93f63b824db9bc5df999afcadf6afba.tar.gz
Add support for converting final image to qcow2
-rwxr-xr-xbin/vmdebootstrap2
-rw-r--r--doc/overview.rst1
-rw-r--r--vmdebootstrap/filesystem.py14
3 files changed, 17 insertions, 0 deletions
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']])