From 4729adc5f90682c322e382da3f3115a0c4d44d90 Mon Sep 17 00:00:00 2001 From: Fabian Deutsch Date: Tue, 13 Oct 2015 17:50:51 +0300 Subject: [PATCH] Add support for liveimg-squashfs This patch adds support to build squashfs images which are compatible to anaconda's liveimg directive and dracuts liveimg feature. The feature is pretty simple, as it just reuses the raw diskimage, and strips the disklabel, to retrieve the plain filesystem image. Two open issues: - Stripping the disk label is a pretty hack - Database schema upgrade is missing Signed-off-by: Fabian Deutsch --- builder/kojid | 37 +++++++++++++++++++++++++++++++++++-- cli/koji | 3 ++- docs/schema.sql | 1 + koji.spec | 1 + 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/builder/kojid b/builder/kojid index 7b88252e..d02c4a98 100755 --- a/builder/kojid +++ b/builder/kojid @@ -3066,7 +3066,7 @@ class BaseImageTask(OzImageTask): Some image formats require others to be processed first, which is why we have to do this. raw files in particular may not be kept. """ - supported = ('raw', 'raw-xz', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker', 'vagrant-virtualbox', 'vagrant-libvirt', 'vagrant-vmware-fusion', 'vpc') + supported = ('raw', 'raw-xz', 'liveimg-squashfs', 'vmdk', 'qcow', 'qcow2', 'vdi', 'rhevm-ova', 'vsphere-ova', 'docker', 'vagrant-virtualbox', 'vagrant-libvirt', 'vagrant-vmware-fusion', 'vpc') for f in formats: if f not in supported: raise koji.ApplianceError('Invalid format: %s' % f) @@ -3092,6 +3092,7 @@ class BaseImageTask(OzImageTask): """ fcalls = {'raw': self._buildBase, 'raw-xz': self._buildXZ, + 'liveimg-squashfs': self._buildSquashfs, 'vmdk': self._buildConvert, 'vdi': self._buildConvert, 'qcow': self._buildConvert, @@ -3249,6 +3250,37 @@ class BaseImageTask(OzImageTask): logerror=1) return {'image': newimg} + def _buildSquashfs(self, format): + """ + Use squashfs to wrap a raw disk image into liveimg compatible image. + This can be used by dracut for booting or anaconda to install. + + @args: + format - a string representing the image format, "liveimg-squashfs" + @returns: + a dict with some metadata about the image + """ + newimg = os.path.join(self.workdir, self.imgname + '.squashfs') + fsimg = os.path.join(self.workdir, 'squashfs-root/LiveOS/rootfs.img') + + os.makedirs(os.path.join(self.workdir, 'squashfs-root/LiveOS')) + + cmd = ['/usr/bin/dd', 'conv=sparse', 'bs=1M', + 'skip=1', # FIXME Hack to strip the disklabel + 'if=%s' % self.base_img.base_image.data, + 'of=%s' % fsimg] + conlog = os.path.join(self.workdir, + 'squashfs-dd-%s-%s.log' % (format, self.arch)) + log_output(self.session, cmd[0], cmd, conlog, self.getUploadDir(), + logerror=1) + cmd = ['/usr/sbin/mksquashfs', 'squashfs-root', + newimg, '-comp', 'xz', '-noappend'] + conlog = os.path.join(self.workdir, + 'squashfs-mksquashfs-%s-%s.log' % (format, self.arch)) + log_output(self.session, cmd[0], cmd, conlog, self.getUploadDir(), + logerror=1) + return {'image': newimg} + def _buildOVA(self, format): """ Build an OVA target image. This is a format supported by RHEV and @@ -3453,7 +3485,8 @@ class BaseImageTask(OzImageTask): # upload the results for format in (f for f in self.formats.keys() if self.formats[f]): newimg = images[format]['image'] - if 'ova' in format or format == 'raw-xz': + if ('ova' in format or format == 'raw-xz' or + format == 'liveimg-squashfs'): newname = self.imgname + '.' + format.replace('-', '.') elif 'vagrant' in format: # This embeds the vagrant target and the ".box" format in the name diff --git a/cli/koji b/cli/koji index cf4399ae..c23a9dba 100755 --- a/cli/koji +++ b/cli/koji @@ -5353,7 +5353,8 @@ def handle_image_build(options, session, args): """Create a disk image given an install tree""" formats = ('vmdk', 'qcow', 'qcow2', 'vdi', 'vpc', 'rhevm-ova', 'vsphere-ova', 'vagrant-virtualbox', 'vagrant-libvirt', - 'vagrant-vmware-fusion', 'docker', 'raw-xz') + 'vagrant-vmware-fusion', 'docker', 'raw-xz', + 'liveimg-squashfs') usage = _("usage: %prog image-build [options] " + " [...]") usage += _("\n %prog image-build --config FILE") diff --git a/docs/schema.sql b/docs/schema.sql index 3d57d336..50377a7a 100644 --- a/docs/schema.sql +++ b/docs/schema.sql @@ -769,6 +769,7 @@ insert into archivetypes (name, description, extensions) values ('shell', 'Shell insert into archivetypes (name, description, extensions) values ('rc', 'Resource file', 'rc'); insert into archivetypes (name, description, extensions) values ('wsdl', 'Web Services Description Language', 'wsdl'); insert into archivetypes (name, description, extensions) values ('obr', 'OSGi Bundle Repository', 'obr'); +insert into archivetypes (name, description, extensions) values ('liveimg-squashfs', 'liveimg compatible squashfs image', 'liveimg.squashfs'); -- Do we want to enforce a constraint that a build can only generate one diff --git a/koji.spec b/koji.spec index 63a8f9fc..ace34d7e 100644 --- a/koji.spec +++ b/koji.spec @@ -75,6 +75,7 @@ License: LGPLv2 and GPLv2+ Requires: %{name} = %{version}-%{release} Requires: mock >= 0.9.14 Requires(pre): /usr/sbin/useradd +Requires: squashfs-tools %if %{use_systemd} Requires(post): systemd Requires(preun): systemd