livemedia-creator: Change fsck.ext4 discard failures to errors

Something is causing problems with the ext4 rootfs.img when running with
no-virt inside koji. This results in a failed image that looks good
until you try to boot it.

make_squashfs will now return False if it fails, and make_live_image
will return None (instead of the result path). lmc will exit with a 1
and log an error.
This commit is contained in:
Brian C. Lane 2016-03-09 14:29:18 -08:00
parent 4fea0ba7f1
commit 3e9efdcf48
1 changed files with 23 additions and 4 deletions

View File

@ -954,14 +954,21 @@ def make_squashfs(disk_img, work_dir, compression="xz", compressargs=None):
:param str disk_img: Path to the unpartitioned filesystem disk image
:param str work_dir: Output compressed image to work_dir+images/install.img
:param str compression: Compression type to use
:returns: True if squashfs creation was successful. False if there was an error.
:rtype: bool
Take disk_img and put it into LiveOS/rootfs.img and squashfs this
tree into work_dir+images/install.img
fsck.ext4 is run on the disk image to make sure there are no errors and to zero
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.warning("Problem zeroing free blocks of %s", disk_img)
log.error("Problem zeroing free blocks of %s", disk_img)
return False
liveos_dir = joinpaths(work_dir, "runtime/LiveOS")
os.makedirs(liveos_dir)
@ -974,6 +981,7 @@ def make_squashfs(disk_img, work_dir, compression="xz", compressargs=None):
mksquashfs(joinpaths(work_dir, "runtime"),
joinpaths(work_dir, RUNTIME), compression, compressargs)
remove(joinpaths(work_dir, "runtime"))
return True
def calculate_disk_size(opts, ks):
""" Calculate the disk size from the kickstart
@ -1039,8 +1047,12 @@ def make_live_images(opts, work_dir, root_dir, rootfs_image=None, size=None):
:param str work_dir: Directory for storing results
:param str root_dir: Root directory of live filesystem tree
:param str rootfs_image: Path to live rootfs image to be used
:returns: Path of directory with created images
:returns: Path of directory with created images or None
:rtype: str
fsck.ext4 is run on the rootfs_image to make sure there are no errors and to zero
out any deleted blocks to make it compress better. If this fails for any reason
it will return None and log the error.
"""
sys_root = ""
if opts.ostree:
@ -1054,7 +1066,8 @@ def make_live_images(opts, work_dir, root_dir, rootfs_image=None, size=None):
# Make sure free blocks are actually zeroed so it will compress
rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", rootfs_image])
if rc != 0:
log.warning("Problem zeroing free blocks of %s", rootfs_image)
log.error("Problem zeroing free blocks of %s", rootfs_image)
return None
rc = execWithRedirect("/bin/ln", [rootfs_image, joinpaths(liveos_dir, "rootfs.img")])
if rc != 0:
@ -1456,7 +1469,10 @@ def main():
else:
log.info("no BCJ filter for arch %s", arch.basearch)
make_squashfs(disk_img, work_dir, compression, compressargs)
if not make_squashfs(disk_img, work_dir, compression, compressargs):
log.error("squashfs.img creation failed")
sys.exit(1)
with Mount(disk_img, opts="loop") as mount_dir:
result_dir = make_livecd(opts, mount_dir, work_dir)
else:
@ -1522,6 +1538,9 @@ def main():
finally:
if mounted_sysroot_boot_dir:
umount(mounted_sysroot_boot_dir)
if result_dir is None:
log.error("Creating live image failed.")
sys.exit(1)
if opts.result_dir != opts.tmp and result_dir:
copytree(result_dir, opts.result_dir, preserve=False)