[virt-tools-list] virt-install: Getting initrd 'injection' to work...

Martin Ellis martin at ellis.name
Thu Oct 21 22:02:41 UTC 2010

Hi all,

I've been trying to use preseeding [1] to automate installations of Debian-
based VMs. I'd been using an HTTP server to provide the configuration file,
but then found the following feature in the virt-tools changelog:

  "New virt-install --initrd-inject option, which enables installation using a _local_ kickstart file"

I don't know anything about Kickstart, but adding a file to the initrd is exactly what I need.
Unfortunately, the feature doesn't work for me.

I had a look at the patch that introduced this feature [2], and noticed
that it was using cpio -c when repacking the initrd.
The -c option means "ASCII cpio archive (pre-SVR4 or odc)".

I've only been able to get the feature to work if I change it to use the
'newc' format, by replacing -c with -Hnewc.
Using -Hnewc gives "ASCII cpio archive (SVR4 with no CRC)"

While I was looking, I also noticed that the initrd gets unpacked, and
then repacked again with the new files.  A more efficient way to do
this is to simply append a new (compressed) cpio archive onto the end
of the original initrd.  This works because Linux allows a sequence of
(optionally compressed) cpio archives concatenated together [3].

I've attached a patch addresses both issues.


[1] http://d-i.alioth.debian.org/manual/en.i386/apb.html
[2] http://hg.fedorahosted.org/hg/python-virtinst/rev/74bc3757b247
[3] http://git.kernel.org/?p=linux/kernel/git/stable/linux-2.6-stable.git;a=blob_plain;f=Documentation/early-userspace/buffer-format.txt;hb=HEAD

--- a/virtinst/DistroInstaller.py	Thu Sep 30 09:35:58 2010 +0000
+++ b/virtinst/DistroInstaller.py	Thu Oct 21 22:06:07 2010 +0100
@@ -180,40 +180,29 @@
         Insert files into the root directory of the initial ram disk
-        logging.debug("Unpacking initrd.")
         initrd = self._install_bootconfig.initrd
         tempdir = tempfile.mkdtemp(dir=self.scratchdir)
         os.chmod(tempdir, 0775)
-        gzip_proc = subprocess.Popen(['gzip', '-dc', initrd],
-                                     stdout=subprocess.PIPE, stderr=sys.stderr)
-        cpio_proc = subprocess.Popen(['cpio', '-i', '-d', '--quiet'],
-                                     stdin=gzip_proc.stdout,
-                                     stderr=sys.stderr, cwd=tempdir)
-        cpio_proc.wait()
-        gzip_proc.wait()
         for filename in self._initrd_injections:
             logging.debug("Copying %s to the initrd." % filename)
             shutil.copy(filename, tempdir)
-        logging.debug("Repacking the initrd.")
+        logging.debug("Appending to the initrd.")
         find_proc = subprocess.Popen(['find', '.', '-print0'],
                                      stderr=sys.stderr, cwd=tempdir)
-        cpio_proc = subprocess.Popen(['cpio', '-o', '--null', '-c', '--quiet'],
+        cpio_proc = subprocess.Popen(['cpio', '-o', '--null', '-Hnewc', '--quiet'],
                                      stderr=sys.stderr, cwd=tempdir)
-        new_initrd = initrd + '.new'
-        f = open(new_initrd, 'w')
+        f = open(initrd, 'ab')
         gzip_proc = subprocess.Popen(['gzip'], stdin=cpio_proc.stdout,
                                      stdout=f, stderr=sys.stderr)
-        f.close()
-        os.rename(new_initrd, initrd)
+        f.close()
     def _prepare_kernel_and_initrd(self, guest, meter):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: initrd-inject.diff
Type: text/x-patch
Size: 2192 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/virt-tools-list/attachments/20101021/332a960f/attachment.bin>

More information about the virt-tools-list mailing list