Index: livecd/creator/livecd-creator
===================================================================
--- livecd.orig/creator/livecd-creator
+++ livecd/creator/livecd-creator
@@ -27,6 +27,7 @@ import traceback
 import subprocess
 import shutil
 import yum
+import gzip
 import pykickstart.parser
 import pykickstart.version
 
@@ -929,10 +930,102 @@ menu color hotkey 0 #ffffffff #ff000000
         self.createSquashFS()
         self.createIso()
 
+class InitramfsTarget(InstallationTarget):
+    def __init__(self, repos, packages, epackages, groups, fs_label, skip_compression, skip_prelink):
+        InstallationTarget.__init__(self, repos, packages, epackages, groups, fs_label, skip_compression, skip_prelink)
+
+    def base_on(self, base_on):
+        raise InstallationError("--base-on is not supported with --type=initramfs")
+
+    def write_fstab(self):
+        fstab = open(self.build_dir + "/install_root/etc/fstab", "w")
+        fstab.write("rootfs       /           ext3    defaults,noatime 0 0\n")
+        fstab.write("devpts       /dev/pts    devpts  gid=5,mode=620   0 0\n")
+        fstab.write("tmpfs        /dev/shm    tmpfs   defaults         0 0\n")
+        fstab.write("proc         /proc       proc    defaults         0 0\n")
+        fstab.write("sysfs        /sys        sysfs   defaults         0 0\n")
+        fstab.close()
+
+    def setup(self, image_size, base_on = None):
+        return InstallationTarget.setup(self, image_size, base_on, noloop = True)
+
+    def install(self):
+        InstallationTarget.install(self)
+
+    def _chdir_to_install_root(self):
+        os.chdir(self.build_dir + "/install_root")
+
+    def _spawn_find(self):
+        (rpipe, wpipe) = os.pipe()
+
+        pid = os.fork()
+        if pid == 0: # child
+            os.close(rpipe)
+            self._chdir_to_install_root()
+            for (root, dirs, files) in os.walk("."):
+                os.write(wpipe, root + "\n")
+                for d in dirs:
+                    if os.path.islink(os.path.join(root, d)):
+                        os.write(wpipe, os.path.join(root, d) + "\n")
+                for f in files:
+                    os.write(wpipe, os.path.join(root, f) + "\n")
+            os._exit(0)
+
+        os.close(wpipe)
+
+        return rpipe
+
+    def createInitramfs(self):
+        findfd = self._spawn_find()
+
+        cpio = subprocess.Popen(["/bin/cpio", "-o", "-H", "newc"],
+                                preexec_fn=self._chdir_to_install_root,
+                                stdin=findfd,
+                                stdout=subprocess.PIPE)
+
+        gz = gzip.open(self.build_dir + "/out/initramfs.img", "w")
+
+        while 1:
+            buf = cpio.stdout.read(1024 * 512) # 512k buffer
+            if not buf:
+                break
+            gz.write(buf)
+
+        gz.close()
+        os.close(findfd)
+
+        shutil.move(self.build_dir + "/out/initramfs.img",
+                    self.fs_label + "-initramfs.img")
+        shutil.copyfile(self.build_dir + "/install_root/boot/vmlinuz-" + self.get_kernel_version(),
+                        self.fs_label + "-vmlinuz")
+
+    def writeXML(self):
+        xml = open(self.fs_label + ".xml", "w")
+        xml.write("<domain>\n")
+        xml.write("  <name>%s</name>\n" % self.fs_label)
+        xml.write("  <os>\n")
+        xml.write("    <type>linux</type>\n")
+        xml.write("    <kernel>%s/%s-vmlinuz</kernel>\n" % (os.getcwd(), self.fs_label))
+        xml.write("    <initrd>%s/%s-initramfs.img</initrd>\n" % (os.getcwd(), self.fs_label))
+        xml.write("    <cmdline>debug console=xvc0 rdinit=/sbin/init</cmdline>\n")
+        xml.write("  </os>\n")
+        xml.write("  <memory>1048576</memory>\n")
+        xml.write("  <vcpu>1</vcpu>\n")
+        xml.write("  <devices>\n")
+        xml.write("    <interface />\n")
+        xml.write("  </devices>\n")
+        xml.write("</domain>\n")
+        xml.close()
+
+    def package(self):
+        InstallationTarget.package(self)
+        self.createInitramfs()
+        self.writeXML()
+
 def usage(out):
     print >> out, """
 usage: livecd-creator [--help] 
-                      [--type=<livecd|...>]
+                      [--type=<livecd|initramfs>]
                       [--config=<path-to-kickstart-file> | --repo=<name>,<url> --package=<p>]
                       [--repo=<name1>,<url1>] [--repo=<name2>,<url2> ...]
                       [--package=<p1>] [--package=<p2> ...]
@@ -1004,6 +1097,8 @@ def parse_options(args):
         if o in ("-t", "--type"):
             if a == "livecd":
                 options.target_class = LiveCDTarget
+            elif a == "initramfs":
+                options.target_class = InitramfsTarget
             else:
                 raise Usage("'%s' is not a known installation target type." % a)
             continue
