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
This commit is contained in:
Brian C. Lane 2019-07-25 09:57:43 -07:00
parent cf10fb40f3
commit cb91fa3c78
2 changed files with 42 additions and 18 deletions

View File

@ -303,6 +303,8 @@ def lmc_parser(dracut_default=""):
parser.add_argument("--releasever", default="29", parser.add_argument("--releasever", default="29",
help="substituted for @VERSION@ in bootloader config files") help="substituted for @VERSION@ in bootloader config files")
parser.add_argument("--volid", default=None, help="volume id") 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", parser.add_argument("--squashfs_args",
help="additional squashfs args") help="additional squashfs args")
parser.add_argument("--timeout", default=None, type=int, parser.add_argument("--timeout", default=None, type=int,

View File

@ -202,9 +202,15 @@ def make_runtime(opts, mount_dir, work_dir, size=None):
rb = RuntimeBuilder(product, arch, fake_dbo) rb = RuntimeBuilder(product, arch, fake_dbo)
compression, compressargs = squashfs_args(opts) compression, compressargs = squashfs_args(opts)
log.info("Creating runtime")
rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size, if opts.squashfs_only:
compression=compression, compressargs=compressargs) 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): 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 out any deleted blocks to make it compress better. If this fails for any reason
it will return False and log the error. 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))) 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")]) liveos_dir = joinpaths(work_dir, "runtime/LiveOS")
if rc != 0: os.makedirs(liveos_dir)
shutil.copy2(disk_img, joinpaths(liveos_dir, "rootfs.img"))
compression, compressargs = squashfs_args(opts) # Try to hardlink the rootfs file first, fall back top copying it
mksquashfs(joinpaths(work_dir, "runtime"), rc = execWithRedirect("/bin/ln", [disk_img, joinpaths(liveos_dir, "rootfs.img")])
joinpaths(work_dir, RUNTIME), compression, compressargs) 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")) 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): def calculate_disk_size(opts, ks):
""" Calculate the disk size from the kickstart """ Calculate the disk size from the kickstart