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,7 +202,13 @@ 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")
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, rb.create_ext4_runtime(joinpaths(work_dir, RUNTIME), size=size,
compression=compression, compressargs=compressargs) compression=compression, compressargs=compressargs)
@ -418,6 +424,16 @@ 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.
""" """
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 # Make sure free blocks are actually zeroed so it will compress
rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", disk_img]) rc = execWithRedirect("/usr/sbin/fsck.ext4", ["-y", "-f", "-E", "discard", disk_img])
if rc != 0: if rc != 0:
@ -426,16 +442,22 @@ def make_squashfs(opts, disk_img, work_dir):
liveos_dir = joinpaths(work_dir, "runtime/LiveOS") liveos_dir = joinpaths(work_dir, "runtime/LiveOS")
os.makedirs(liveos_dir) os.makedirs(liveos_dir)
os.makedirs(os.path.dirname(joinpaths(work_dir, RUNTIME)))
# Try to hardlink the rootfs file first, fall back top copying it
rc = execWithRedirect("/bin/ln", [disk_img, joinpaths(liveos_dir, "rootfs.img")]) rc = execWithRedirect("/bin/ln", [disk_img, joinpaths(liveos_dir, "rootfs.img")])
if rc != 0: if rc != 0:
shutil.copy2(disk_img, joinpaths(liveos_dir, "rootfs.img")) shutil.copy2(disk_img, joinpaths(liveos_dir, "rootfs.img"))
compression, compressargs = squashfs_args(opts) compression, compressargs = squashfs_args(opts)
mksquashfs(joinpaths(work_dir, "runtime"), rc = mksquashfs(joinpaths(work_dir, "runtime"), joinpaths(work_dir, RUNTIME), compression, compressargs)
joinpaths(work_dir, RUNTIME), compression, compressargs)
# Cleanup the runtime directory
remove(joinpaths(work_dir, "runtime")) remove(joinpaths(work_dir, "runtime"))
if rc:
log.error("Problem running mksquashfs: rc=%d", rc)
return False
else:
return True return True
def calculate_disk_size(opts, ks): def calculate_disk_size(opts, ks):