Description of problem: "virt-install --initrd-inject=..." inject does not work. No diagnostic is printed, but the files simply do not appear on the installer's initrd. The problem is that earlier versions of Linux used a compressed ext2 image for the initrd. initrd-inject only works if the initrd is a compressed cpio image. (Indeed, the script happily appends compressed cpio blocks to the ext2 image which are then ignored by the kernel.) Version-Release number of selected component (if applicable): 0.600.0 (also current git) How reproducible: alwas Steps to Reproduce: 1. "virt-install --initrd-inject=foo <any RHEL 4.x version>" 2. 3. Actual results: File "foo" does not appear on the initrd during installation Expected results: File "foo" should appear on the initrd during installation Additional info: I am working on a patch for this, but I am not an experienced Python programmer. Yet.
I decided I do not have time to learn Python right now... So I worked around this issue in my shell script wrapper. I am including my approach here in case it can help someone else or provide a basis for a real patch. The below fragment of shell script code assumes that $location is what you plan to pass to "virt-install --location=...". The code locates the pxeboot/initrd.img file within $location and determines whether it is an ext2 compressed image. If so, it creates a temporary directory, copies the vmlinuz and initrd.img files into it, and adds "file1", "file2", and "file3" to the initrd.img. Then it modifies $location to point to the temporary directory. (It also arranges to remove the temporary directory when the containing shell script exits.) So, once this fragment finishes, your script just does "virt-install --location=$location ..." to get the installation going. You can even include "--initrd-inject=..." lines, although they will of course have no effect when the initrd is actually ext2. In this way you can wind up with a generic install script. I hope this basic approach can be adapted to DistroInstaller.py by someone better versed in Python. It does assume that e2fstools is installed (for debugfs), and it will fail if the ext2 initrd does not already have enough free space on it to hold the injected files. This is good enough for my application and would probably be a reasonable assumption for an initial patch. Shell script fragment follows. --- # At this point, "$location" refers to the OS distro pxeboot_dir=$(find "$location"/. -name example -prune -o -type d -name pxeboot -print) initrd="$pxeboot_dir"/initrd.img [ -f "$initrd" ] \ && file_initrd=$(file -z "$initrd") if [ -f "$initrd" ] && [ "$file_initrd" != "${file_initrd#* ext2 }" ] ; then # This is awful. "virt-install --initrd-inject=..." does not # handle compressed ext2 images (RHEL 4 and below). So hack # around it. (If # https://bugzilla.redhat.com/show_bug.cgi?id=866608 is ever # fixed, all of this can be removed.) echo "$0: Looks like $initrd ext2... Engaging hack" # Create temporary directory and arrange to remove it on script exit. temp_dir=$(mktemp -d) trap "rm -rf $temp_dir" EXIT mkdir -p $temp_dir/images/pxeboot cp -a "$pxeboot_dir"/vmlinuz $temp_dir/images/pxeboot/. temp_initrd=$temp_dir/images/pxeboot/initrd.img # "-f" just in case initrd is not compressed zcat -f "$initrd" > $temp_initrd # Inject files into temp initrd. for file in file1 file2 file3 ; do /sbin/debugfs -w -R "write $file ${file##*/}" $temp_initrd done location=$temp_dir fi # Now we can run virt-install --location=$location ...
This is fixed upstream now: commit 018fcbbb4abb15974463cf2b3f76eecdabb02e5e Author: Cole Robinson <crobinso> Date: Mon Sep 2 16:10:28 2013 -0400 distroinstaller: Support --initrd-inject for RHEL4 (bz 866608) RHEL4 kernels are gzip'd ext2 images, so unzip it, use debugfs to inject files, and zip it back up. Based on shell code from Patrick J. LoPresti.