On Mon, 2012-11-12 at 18:37 -0500, Will Woods wrote:
If 'prefix' is passed to rebuild_initrds(), it will build a
*new*
initramfs with a name like $PREFIX-$KERNELVER.img, rather than
overwriting the existing initramfs.
---
src/pylorax/treebuilder.py | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py
index 3ff0e6f..74a59ae 100644
--- a/src/pylorax/treebuilder.py
+++ b/src/pylorax/treebuilder.py
@@ -186,10 +186,13 @@ class TreeBuilder(object):
def kernels(self):
return findkernels(root=self.vars.inroot)
- def rebuild_initrds(self, add_args=[], backup=""):
+ def rebuild_initrds(self, add_args=[], backup="", prefix=""):
'''Rebuild all the initrds in the tree. If backup is specified,
each
initrd will be renamed with backup as a suffix before rebuilding.
- If backup is empty, the existing initrd files will be
overwritten.'''
+ If backup is empty, the existing initrd files will be overwritten.
+ If suffix is specified, the existing initrd is untouched and a new
^^^should be prefix, right?
+ image is built with the filename
"${prefix}-${kernel.version}.img"
+ '''
dracut = ["dracut", "--nomdadmconf",
"--nolvmconf"] + add_args
if not backup:
dracut.append("--force")
@@ -197,11 +200,16 @@ class TreeBuilder(object):
# Hush some dracut warnings. TODO: bind-mount proc in place?
open(joinpaths(self.vars.inroot,"/proc/modules"),"w")
for kernel in self.kernels:
- logger.info("rebuilding %s", kernel.initrd.path)
+ if prefix:
+ idir = os.path.dirname(kernel.initrd.path)
+ outfile = joinpaths(idir,
prefix+'-'+kernel.version+'.img')
+ else:
+ outfile = kernel.initrd.path
+ logger.info("rebuilding %s", outfile)
if backup:
- initrd = joinpaths(self.vars.inroot, kernel.initrd.path)
+ initrd = joinpaths(self.vars.inroot, outfile)
os.rename(initrd, initrd + backup)
- cmd = dracut + [kernel.initrd.path, kernel.version]
+ cmd = dracut + [outfile, kernel.version]
runcmd(cmd, root=self.vars.inroot)
os.unlink(joinpaths(self.vars.inroot,"/proc/modules"))