mirror of
https://github.com/virt-manager/virt-manager.git
synced 2025-02-13 17:05:46 -06:00
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.
This commit is contained in:
parent
4910611d3c
commit
018fcbbb4a
@ -159,6 +159,61 @@ def _upload_file(conn, meter, destpool, src):
|
||||
return vol
|
||||
|
||||
|
||||
def _rhel4_initrd_inject(initrd, injections):
|
||||
try:
|
||||
file_proc = subprocess.Popen(["file", "-z", initrd],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
if not "ext2 filesystem" in file_proc.communicate()[0]:
|
||||
return False
|
||||
except:
|
||||
logging.exception("Failed to file command for rhel4 initrd detection")
|
||||
return False
|
||||
|
||||
logging.debug("Is RHEL4 initrd")
|
||||
|
||||
# Uncompress the initrd
|
||||
newinitrd = file(initrd + ".new", "wb")
|
||||
gzip_proc = subprocess.Popen(["gzip", "-d", "-f", "-c", initrd],
|
||||
stdout=newinitrd,
|
||||
stderr=subprocess.PIPE)
|
||||
gzip_proc.wait()
|
||||
newinitrd.close()
|
||||
|
||||
debugfserr = ""
|
||||
for filename in injections:
|
||||
# We have an ext2 filesystem, use debugfs to inject files
|
||||
cmd = ["debugfs", "-w", "-R",
|
||||
"write %s %s" % (filename, os.path.basename(filename)),
|
||||
newinitrd.name]
|
||||
logging.debug("Copying %s to the initrd with cmd=%s", filename, cmd)
|
||||
|
||||
debugfs_proc = subprocess.Popen(cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
debugfs_proc.wait()
|
||||
debugfserr += debugfs_proc.stderr.read() or ""
|
||||
|
||||
gziperr = gzip_proc.stderr.read()
|
||||
if gziperr:
|
||||
logging.debug("gzip stderr=%s", gziperr)
|
||||
if debugfserr:
|
||||
logging.debug("debugfs stderr=%s", debugfserr)
|
||||
|
||||
# Recompress the initrd
|
||||
gzip_proc = subprocess.Popen(["gzip"],
|
||||
stdin=file(newinitrd.name, "rb"),
|
||||
stdout=file(initrd, "wb"),
|
||||
stderr=subprocess.PIPE)
|
||||
gzip_proc.wait()
|
||||
gziperr = gzip_proc.stderr.read()
|
||||
if gziperr:
|
||||
logging.debug("gzip stderr=%s", gziperr)
|
||||
os.unlink(newinitrd.name)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _perform_initrd_injections(initrd, injections, scratchdir):
|
||||
"""
|
||||
Insert files into the root directory of the initial ram disk
|
||||
@ -166,6 +221,9 @@ def _perform_initrd_injections(initrd, injections, scratchdir):
|
||||
if not injections:
|
||||
return
|
||||
|
||||
if _rhel4_initrd_inject(initrd, injections):
|
||||
return
|
||||
|
||||
tempdir = tempfile.mkdtemp(dir=scratchdir)
|
||||
os.chmod(tempdir, 0775)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user