From cb91fa3c78a8003f092fd034dd3c5c0f230a1a85 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 25 Jul 2019 09:57:43 -0700 Subject: [PATCH] livemedia-creator: Add support for a squashfs only runtime image Normally the runtime image is an ext4 filesystem image that is compressed with squashfs. dracut now supports setting up an overlayfs when it detects a bare filesystem tree inside the squashfs. This commit adds support for a --squashfs-only option which places the root tree directly in the squashfs.img --- src/pylorax/cmdline.py | 2 ++ src/pylorax/creator.py | 58 +++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/pylorax/cmdline.py b/src/pylorax/cmdline.py index f37d2a17..8388e8ee 100644 --- a/src/pylorax/cmdline.py +++ b/src/pylorax/cmdline.py @@ -303,6 +303,8 @@ def lmc_parser(dracut_default=""): parser.add_argument("--releasever", default="29", help="substituted for @VERSION@ in bootloader config files") parser.add_argument("--volid", default=None, help="volume id") + parser.add_argument("--squashfs-only", action="store_true", default=False, + help="Use a plain squashfs filesystem for the runtime.") parser.add_argument("--squashfs_args", help="additional squashfs args") parser.add_argument("--timeout", default=None, type=int, diff --git a/src/pylorax/creator.py b/src/pylorax/creator.py index c004f34a..54ac6c1d 100644 --- a/src/pylorax/creator.py +++ b/src/pylorax/creator.py @@ -202,9 +202,15 @@ def make_runtime(opts, mount_dir, work_dir, size=None): rb = RuntimeBuilder(product, arch, fake_dbo) compression, compressargs = squashfs_args(opts) - log.info("Creating runtime") - rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size, - compression=compression, compressargs=compressargs) + + if opts.squashfs_only: + log.info("Creating a squashfs only runtime") + rb.create_squashfs_runtime(joinpaths(work_dir, RUNTIME), size=size, + compression=compression, compressargs=compressargs) + else: + log.info("Creating a squashfs+ext4 runtime") + rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size, + compression=compression, compressargs=compressargs) def rebuild_initrds_for_live(opts, sys_root_dir, results_dir): @@ -418,25 +424,41 @@ def make_squashfs(opts, disk_img, work_dir): out any deleted blocks to make it compress better. If this fails for any reason it will return False and log the error. """ - # Make sure free blocks are actually zeroed so it will compress - rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", disk_img]) - if rc != 0: - log.error("Problem zeroing free blocks of %s", disk_img) - return False - - liveos_dir = joinpaths(work_dir, "runtime/LiveOS") - os.makedirs(liveos_dir) os.makedirs(os.path.dirname(joinpaths(work_dir, RUNTIME))) + if opts.squashfs_only: + log.info("Creating a squashfs only runtime") + liveos_dir = joinpaths(work_dir, "runtime") + os.makedirs(liveos_dir) + with Mount(disk_img, opts="loop", mnt=liveos_dir): + compression, compressargs = squashfs_args(opts) + rc = mksquashfs(liveos_dir, joinpaths(work_dir, RUNTIME), compression, compressargs) + else: + log.info("Creating a squashfs+ext4 runtime") + # Make sure free blocks are actually zeroed so it will compress + rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", disk_img]) + if rc != 0: + log.error("Problem zeroing free blocks of %s", disk_img) + return False - rc = execWithRedirect("/bin/ln", [disk_img, joinpaths(liveos_dir, "rootfs.img")]) - if rc != 0: - shutil.copy2(disk_img, joinpaths(liveos_dir, "rootfs.img")) + liveos_dir = joinpaths(work_dir, "runtime/LiveOS") + os.makedirs(liveos_dir) - compression, compressargs = squashfs_args(opts) - mksquashfs(joinpaths(work_dir, "runtime"), - joinpaths(work_dir, RUNTIME), compression, compressargs) + # Try to hardlink the rootfs file first, fall back top copying it + rc = execWithRedirect("/bin/ln", [disk_img, joinpaths(liveos_dir, "rootfs.img")]) + if rc != 0: + shutil.copy2(disk_img, joinpaths(liveos_dir, "rootfs.img")) + + compression, compressargs = squashfs_args(opts) + rc = mksquashfs(joinpaths(work_dir, "runtime"), joinpaths(work_dir, RUNTIME), compression, compressargs) + + # Cleanup the runtime directory remove(joinpaths(work_dir, "runtime")) - return True + + if rc: + log.error("Problem running mksquashfs: rc=%d", rc) + return False + else: + return True def calculate_disk_size(opts, ks): """ Calculate the disk size from the kickstart