From 4699c881090b55de12bfe6b8548b3bfe30207ba8 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 4 Mar 2016 17:22:51 -0800 Subject: [PATCH] livemedia-creator: Create runtime using kickstart partition size When using no-virt the runtime filesystem size comes from the kickstart. For virt installs lmc was creating a runtime filesystem that was just slightly larger than the space used by the files installed by anaconda. This can run into problems with larger filesystem. It is also inconsistent behavior between virt and no-virt installations. With this commit the virt runtime filesystem will also come from the kickstart. --- src/pylorax/imgutils.py | 1 + src/sbin/livemedia-creator | 35 ++++++++++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/pylorax/imgutils.py b/src/pylorax/imgutils.py index fce9566a..b77d26a8 100644 --- a/src/pylorax/imgutils.py +++ b/src/pylorax/imgutils.py @@ -281,6 +281,7 @@ def estimate_size(rootdir, graft=None, fstype=None, blocksize=4096, overhead=256 total += round_to_blocks(getsize(join(top,f)), blocksize) if fstype == "btrfs": total = max(256*1024*1024, total) # btrfs minimum size: 256MB + logger.info("Size of %s block %s fs at %s estimated to be %s", blocksize, fstype, rootdir, total) return total ######## Execution contexts - use with the 'with' statement ############## diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index d1cdd25b..ed7bdc08 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -388,7 +388,7 @@ def make_fsimage(diskimage, fsimage, img_size=None, label="Anaconda"): mkext4img(img_mount.mount_dir, fsimage, size=img_size, label=label) -def make_runtime(opts, mount_dir, work_dir): +def make_runtime(opts, mount_dir, work_dir, size=None): """ Make the squashfs image from a directory @@ -396,6 +396,7 @@ def make_runtime(opts, mount_dir, work_dir): :type opts: argparse options :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 """ kernel_arch = get_arch(mount_dir) @@ -413,7 +414,7 @@ def make_runtime(opts, mount_dir, work_dir): rb = RuntimeBuilder(product, arch, fake_dbo) log.info("Creating runtime") - rb.create_runtime(joinpaths(work_dir, RUNTIME), size=None) + rb.create_runtime(joinpaths(work_dir, RUNTIME), size=size) def rebuild_initrds_for_live(opts, sys_root_dir, results_dir): """ @@ -974,6 +975,23 @@ def make_squashfs(disk_img, work_dir, compression="xz", compressargs=None): joinpaths(work_dir, RUNTIME), compression, compressargs) remove(joinpaths(work_dir, "runtime")) +def calculate_disk_size(opts, ks): + """ Calculate the disk size from the kickstart + + :param opts: options passed to livemedia-creator + :type opts: argparse options + :param str ks: Path to the kickstart to use for the installation + + """ + # Disk size for a filesystem image should only be the size of / + # to prevent surprises when using the same kickstart for different installations. + unique_partitions = dict((p.mountpoint, p) for p in ks.handler.partition.partitions) + if opts.no_virt and (opts.make_iso or opts.make_fsimage): + disk_size = 2 + sum(p.size for p in unique_partitions.values() if p.mountpoint == "/") + else: + disk_size = 2 + sum(p.size for p in unique_partitions.values()) + log.info("Using disk size of %sMiB", disk_size) + return disk_size def make_image(opts, ks): """ @@ -987,21 +1005,12 @@ def make_image(opts, ks): Use qemu+boot.iso or anaconda to install to a disk image. """ - # Disk size for a filesystem image should only be the size of / - # to prevent surprises when using the same kickstart for different installations. - unique_partitions = dict((p.mountpoint, p) for p in ks.handler.partition.partitions) - if opts.no_virt and (opts.make_iso or opts.make_fsimage): - disk_size = 2 + sum(p.size for p in unique_partitions.values() if p.mountpoint == "/") - else: - disk_size = 2 + sum(p.size for p in unique_partitions.values()) - log.info("disk_size = %sMiB", disk_size) - if opts.image_name: disk_img = joinpaths(opts.result_dir, opts.image_name) else: disk_img = tempfile.mktemp(prefix="lmc-disk-", suffix=".img", dir=opts.result_dir) log.info("disk_img = %s", disk_img) - + disk_size = calculate_disk_size(opts, ks) try: if opts.no_virt: novirt_install(opts, disk_img, disk_size) @@ -1455,7 +1464,7 @@ def main(): 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) + make_runtime(opts, img_mount.mount_dir, work_dir, calculate_disk_size(opts, ks)) result_dir = make_livecd(opts, img_mount.mount_dir, work_dir) # --iso-only removes the extra build artifacts, keeping only the boot.iso