From 2f66212c0fc52714302e02024453c6f72b9e1db7 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 4 May 2016 18:42:03 -0700 Subject: [PATCH] livemedia-creator: Update make-pxe-live to support missing initramfs In some cases the initramfs may not be present in /boot to save space. Use it if present, otherwise use the kernel version to recreate the name of it. This also fixes problems with dracut running out of space when not using --live-rootfs-keep-size --- src/sbin/livemedia-creator | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index 4981ff0e..7895b0cd 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -460,8 +460,7 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir): if kernels_dir: kdir = os.path.relpath(kernels_dir[0], sys_root_dir) - kernels = [kernel for kernel in findkernels(sys_root_dir, kdir) - if hasattr(kernel, "initrd")] + kernels = [kernel for kernel in findkernels(sys_root_dir, kdir)] if not kernels: raise Exception("No initrds found, cannot rebuild_initrds") @@ -483,20 +482,27 @@ def rebuild_initrds_for_live(opts, sys_root_dir, results_dir): if not os.path.isdir(tmp_dir): os.mkdir(tmp_dir) + # Write the new initramfs directly to the results directory + os.mkdir(joinpaths(sys_root_dir, "results")) + mount(results_dir, opts="bind", mnt=joinpaths(sys_root_dir, "results")) + # Dracut runs out of space inside the minimal rootfs image + mount("/var/tmp", opts="bind", mnt=joinpaths(sys_root_dir, "var/tmp")) for kernel in kernels: - outfile = kernel.initrd.path + ".live" + if hasattr(kernel, "initrd"): + outfile = os.path.basename(kernel.initrd.path) + else: + # Construct an initrd from the kernel name + outfile = os.path.basename(kernel.path.replace("vmlinuz-", "initrd-") + ".img") log.info("rebuilding %s", outfile) kver = kernel.version - cmd = dracut + [outfile, kver] + cmd = dracut + ["/results/"+outfile, kver] runcmd(cmd, root=sys_root_dir) - new_initrd_path = joinpaths(results_dir, os.path.basename(kernel.initrd.path)) - shutil.move(joinpaths(sys_root_dir, outfile), new_initrd_path) - os.chmod(new_initrd_path, 0o644) shutil.copy2(joinpaths(sys_root_dir, kernel.path), results_dir) - + umount(joinpaths(sys_root_dir, "var/tmp"), delete=False) + umount(joinpaths(sys_root_dir, "results"), delete=False) os.unlink(joinpaths(sys_root_dir,"/proc/modules")) def create_pxe_config(template, images_dir, live_image_name, add_args = None):