From 4729adc5f90682c322e382da3f3115a0c4d44d90 Mon Sep 17 00:00:00 2001 From: Fabian Deutsch Date: Mar 30 2016 16:18:56 +0000 Subject: [PATCH 1/3] 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 --- diff --git a/builder/kojid b/builder/kojid index 7b88252..d02c4a9 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 cf4399a..c23a9db 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 3d57d33..50377a7 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 63a8f9f..ace34d7 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 From e7eb1547cc84118b5232dd2c555e1dc05f085f35 Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mar 30 2016 16:18:56 +0000 Subject: [PATCH 2/3] use rhel-friendly path for dd --- diff --git a/builder/kojid b/builder/kojid index d02c4a9..a12bb55 100755 --- a/builder/kojid +++ b/builder/kojid @@ -3265,7 +3265,7 @@ class BaseImageTask(OzImageTask): os.makedirs(os.path.join(self.workdir, 'squashfs-root/LiveOS')) - cmd = ['/usr/bin/dd', 'conv=sparse', 'bs=1M', + cmd = ['/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] From 6746ce5c136b057cfd952783d816d6b6ea7557dd Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Mar 30 2016 16:18:56 +0000 Subject: [PATCH 3/3] use full path to squashfs-root --- diff --git a/builder/kojid b/builder/kojid index a12bb55..82145a5 100755 --- a/builder/kojid +++ b/builder/kojid @@ -3273,7 +3273,7 @@ class BaseImageTask(OzImageTask): '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', + cmd = ['/usr/sbin/mksquashfs', os.path.join(self.workdir, 'squashfs-root'), newimg, '-comp', 'xz', '-noappend'] conlog = os.path.join(self.workdir, 'squashfs-mksquashfs-%s-%s.log' % (format, self.arch))