mksquashfs: Catch errors with mksquashfs and report them

The host system can run out of space while running mksquashfs, and while
this is logged to program.log it isn't detected by lorax or
livemedia-creator so it will continue running, possibly reporting
unrelated errors and causing confusion.

This adds checks for the return status when calling mksquashfs, logs it
to the log, and either exits or raises an error immediately.
This commit is contained in:
Brian C. Lane 2020-05-07 14:35:37 -07:00
parent b97dea0450
commit f83ae2fed3
3 changed files with 31 additions and 17 deletions

View File

@ -319,14 +319,18 @@ class Lorax(BaseLoraxClass):
logger.info("no BCJ filter for arch %s", self.arch.basearch)
if squashfs_only:
# Create an ext4 rootfs.img and compress it with squashfs
rb.create_squashfs_runtime(joinpaths(installroot,runtime),
rc = rb.create_squashfs_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
else:
# Create an ext4 rootfs.img and compress it with squashfs
rb.create_ext4_runtime(joinpaths(installroot,runtime),
rc = rb.create_ext4_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
if rc != 0:
logger.error("rootfs.img creation failed. See program.log")
sys.exit(1)
rb.finished()
logger.info("preparing to build output tree and boot images")

View File

@ -205,6 +205,8 @@ def make_runtime(opts, mount_dir, work_dir, size=None):
:param str mount_dir: Directory tree to compress
:param str work_dir: Output compressed image to work_dir+images/install.img
:param int size: Size of disk image, in GiB
:returns: rc of squashfs creation
:rtype: int
"""
kernel_arch = get_arch(mount_dir)
@ -221,11 +223,11 @@ def make_runtime(opts, mount_dir, work_dir, size=None):
if opts.squashfs_only:
log.info("Creating a squashfs only runtime")
rb.create_squashfs_runtime(joinpaths(work_dir, RUNTIME), size=size,
return 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,
return rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size,
compression=compression, compressargs=compressargs)
@ -573,7 +575,10 @@ def make_live_images(opts, work_dir, disk_img):
add_pxe_args = []
live_image_name = "live-rootfs.squashfs.img"
compression, compressargs = squashfs_args(opts)
mksquashfs(squashfs_root_dir, joinpaths(work_dir, live_image_name), compression, compressargs)
rc = mksquashfs(squashfs_root_dir, joinpaths(work_dir, live_image_name), compression, compressargs)
if rc != 0:
log.error("mksquashfs failed to create %s", live_image_name)
return None
log.info("Rebuilding initramfs for live")
with Mount(rootfs_img, opts="loop") as mnt_dir:
@ -691,9 +696,10 @@ def run_creator(opts, cancel_func=None):
# Create iso from a filesystem image
disk_img = opts.fs_image or disk_img
with Mount(disk_img, opts="loop") as mount_dir:
# TODO check rc
make_runtime(opts, mount_dir, work_dir, calculate_disk_size(opts, ks)/1024.0)
rc = make_runtime(opts, mount_dir, work_dir, calculate_disk_size(opts, ks)/1024.0)
if rc != 0:
log.error("make_runtime failed with rc = %d. See program.log", rc)
raise RuntimeError("make_runtime failed with rc = %d" % rc)
if cancel_func and cancel_func():
raise RuntimeError("ISO creation canceled")
@ -703,7 +709,10 @@ def run_creator(opts, cancel_func=None):
disk_img = opts.disk_image or disk_img
with PartitionMount(disk_img) as img_mount:
if img_mount and img_mount.mount_dir:
make_runtime(opts, img_mount.mount_dir, work_dir, calculate_disk_size(opts, ks)/1024.0)
rc = make_runtime(opts, img_mount.mount_dir, work_dir, calculate_disk_size(opts, ks)/1024.0)
if rc != 0:
log.error("make_runtime failed with rc = %d. See program.log", rc)
raise RuntimeError("make_runtime failed with rc = %d" % rc)
result_dir = make_livecd(opts, img_mount.mount_dir, work_dir)
# --iso-only removes the extra build artifacts, keeping only the boot.iso

View File

@ -234,7 +234,7 @@ class RuntimeBuilder(object):
os.makedirs(os.path.dirname(outfile))
# squash the rootfs
imgutils.mksquashfs(self.vars.root, outfile, compression, compressargs)
return imgutils.mksquashfs(self.vars.root, outfile, compression, compressargs)
def create_ext4_runtime(self, outfile="/var/tmp/squashfs.img", compression="xz", compressargs=None, size=2):
"""Create a squashfs compressed ext4 runtime"""
@ -253,8 +253,9 @@ class RuntimeBuilder(object):
raise
# squash the live rootfs and clean up workdir
imgutils.mksquashfs(workdir, outfile, compression, compressargs)
rc = imgutils.mksquashfs(workdir, outfile, compression, compressargs)
remove(workdir)
return rc
def finished(self):
""" Done using RuntimeBuilder