[Fedora-livecd-list] Patch to allow specifying a compressor when running livecd-creator

Bruno Wolff III bruno at wolff.to
Mon Jun 14 04:53:10 UTC 2010


I have attached a patch that allows specifying a compressor to use when
running livecd-creator.

I'd like some review to make sure it looks sane.

Assuming it looks good, I'd like to see it get into rawhide soon as either
an update to 031 or as 032.

I made the patch versus the head of the master branch, but it applied
cleanly to the 031 source from the F13 srpm.

I have done some testing and it seems to work reasonably and images using
zlib boot. (Images using lzma can be looked at for size, but won't boot.)
By getting it into rawhide now we can make sure the fallback after making
lzma the default is just making zlib the default again. (Just to be clear,
zlib is the default with this patch.)
-------------- next part --------------
diff --git a/docs/livecd-creator.pod b/docs/livecd-creator.pod
index b275e65..880ae19 100644
--- a/docs/livecd-creator.pod
+++ b/docs/livecd-creator.pod
@@ -40,6 +40,13 @@ Add packages to an existing live CD iso9660 image.
 
 Defines the file system label. The default is based on the configuration name.
 
+=item --compression-type=COMPRESSOR
+
+Specify a compressor recognized by mksquashfs. The default is zlib. lzma
+currently requires a custom kernel to produce a functional image. If zlib
+is used, the -comp option is not passed to mksquashfs to allow the use of
+older versions of mksquashfs.
+
 =back
 
 =head1 SYSTEM DIRECTORY OPTIONS
diff --git a/imgcreate/fs.py b/imgcreate/fs.py
index f5eed39..142ecd2 100644
--- a/imgcreate/fs.py
+++ b/imgcreate/fs.py
@@ -40,8 +40,12 @@ def makedirs(dirname):
         if err != errno.EEXIST:
             raise
 
-def mksquashfs(in_img, out_img):
-    args = ["/sbin/mksquashfs", in_img, out_img]
+def mksquashfs(in_img, out_img, compress_type):
+# Allow zlib to work for older versions of mksquashfs
+    if compress_type == "zlib":
+        args = ["/sbin/mksquashfs", in_img, out_img]
+    else:
+        args = ["/sbin/mksquashfs", in_img, out_img, "-comp", compress_type]
 
     if not sys.stdout.isatty():
         args.append("-no-progress")
@@ -553,7 +557,7 @@ class DeviceMapperSnapshot(object):
         except ValueError:
             raise SnapshotError("Failed to parse dmsetup status: " + out)
 
-def create_image_minimizer(path, image, target_size = None):
+def create_image_minimizer(path, image, compress_type, target_size = None):
     """
     Builds a copy-on-write image which can be used to
     create a device-mapper snapshot of an image where
@@ -591,7 +595,7 @@ def create_image_minimizer(path, image, target_size = None):
 
     cowloop.truncate(cow_used)
 
-    mksquashfs(cowloop.lofile, path)
+    mksquashfs(cowloop.lofile, path, compress_type)
 
     os.unlink(cowloop.lofile)
 
diff --git a/imgcreate/live.py b/imgcreate/live.py
index 856cce8..4f3bdd3 100644
--- a/imgcreate/live.py
+++ b/imgcreate/live.py
@@ -46,6 +46,9 @@ class LiveImageCreatorBase(LoopImageCreator):
         """
         LoopImageCreator.__init__(self, *args)
 
+        self.compress_type = "zlib"
+        """mksquashfs compressor to use."""
+
         self.skip_compression = False
         """Controls whether to use squashfs to compress the image."""
 
@@ -294,7 +297,7 @@ class LiveImageCreatorBase(LoopImageCreator):
             self._resparse()
 
             if not self.skip_minimize:
-                create_image_minimizer(self.__isodir + "/LiveOS/osmin.img", self._image)
+                create_image_minimizer(self.__isodir + "/LiveOS/osmin.img", self._image, self.compress_type)
 
             if self.skip_compression:
                 shutil.move(self._image, self.__isodir + "/LiveOS/ext3fs.img")
@@ -307,7 +310,8 @@ class LiveImageCreatorBase(LoopImageCreator):
                             os.path.join(os.path.dirname(self._image),
                                          "LiveOS", "ext3fs.img"))
                 mksquashfs(os.path.dirname(self._image),
-                           self.__isodir + "/LiveOS/squashfs.img")
+                           self.__isodir + "/LiveOS/squashfs.img",
+                           self.compress_type)
                 if os.stat(self.__isodir + "/LiveOS/squashfs.img").st_size >= 4*1024*1024*1024:
                     self._isofstype = "udf"
                     logging.warn("Switching to UDF due to size of LiveOS/squashfs.img")
diff --git a/tools/livecd-creator b/tools/livecd-creator
index 39f7478..79fc944 100755
--- a/tools/livecd-creator
+++ b/tools/livecd-creator
@@ -41,6 +41,9 @@ def parse_options(args):
                       help="Add packages to an existing live CD iso9660 image.")
     imgopt.add_option("-f", "--fslabel", type="string", dest="fs_label",
                       help="File system label (default based on config name)")
+    imgopt.add_option("", "--compression-type", type="string", dest="compress_type",
+                      help="Compression type recognized by mksquashfs (default zlib, lzma needs custom kernel)",
+                      default="zlib")
     parser.add_option_group(imgopt)
 
     # options related to the config of your system
@@ -113,6 +116,7 @@ def main():
 
     creator = imgcreate.LiveImageCreator(ks, name, fs_label)
     creator.tmpdir = os.path.abspath(options.tmpdir)
+    creator.compress_type = options.compress_type
     creator.skip_compression = options.skip_compression
     creator.skip_minimize = options.skip_minimize
     if options.cachedir:


More information about the livecd mailing list