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.
This commit is contained in:
Brian C. Lane 2016-03-04 17:22:51 -08:00
parent 9328100a4d
commit 4699c88109
2 changed files with 23 additions and 13 deletions

View File

@ -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) total += round_to_blocks(getsize(join(top,f)), blocksize)
if fstype == "btrfs": if fstype == "btrfs":
total = max(256*1024*1024, total) # btrfs minimum size: 256MB 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 return total
######## Execution contexts - use with the 'with' statement ############## ######## Execution contexts - use with the 'with' statement ##############

View File

@ -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) 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 Make the squashfs image from a directory
@ -396,6 +396,7 @@ def make_runtime(opts, mount_dir, work_dir):
:type opts: argparse options :type opts: argparse options
:param str mount_dir: Directory tree to compress :param str mount_dir: Directory tree to compress
:param str work_dir: Output compressed image to work_dir+images/install.img :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) kernel_arch = get_arch(mount_dir)
@ -413,7 +414,7 @@ def make_runtime(opts, mount_dir, work_dir):
rb = RuntimeBuilder(product, arch, fake_dbo) rb = RuntimeBuilder(product, arch, fake_dbo)
log.info("Creating runtime") 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): 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) joinpaths(work_dir, RUNTIME), compression, compressargs)
remove(joinpaths(work_dir, "runtime")) 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): 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. 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: if opts.image_name:
disk_img = joinpaths(opts.result_dir, opts.image_name) disk_img = joinpaths(opts.result_dir, opts.image_name)
else: else:
disk_img = tempfile.mktemp(prefix="lmc-disk-", suffix=".img", dir=opts.result_dir) disk_img = tempfile.mktemp(prefix="lmc-disk-", suffix=".img", dir=opts.result_dir)
log.info("disk_img = %s", disk_img) log.info("disk_img = %s", disk_img)
disk_size = calculate_disk_size(opts, ks)
try: try:
if opts.no_virt: if opts.no_virt:
novirt_install(opts, disk_img, disk_size) novirt_install(opts, disk_img, disk_size)
@ -1455,7 +1464,7 @@ def main():
disk_img = opts.disk_image or disk_img disk_img = opts.disk_image or disk_img
with PartitionMount(disk_img) as img_mount: with PartitionMount(disk_img) as img_mount:
if img_mount and img_mount.mount_dir: 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) result_dir = make_livecd(opts, img_mount.mount_dir, work_dir)
# --iso-only removes the extra build artifacts, keeping only the boot.iso # --iso-only removes the extra build artifacts, keeping only the boot.iso