treebuilder: add 'prefix' to rebuild_initrds()

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.
This commit is contained in:
Will Woods 2012-11-13 01:33:14 -05:00 committed by Dennis Gilmore
parent e4c03a98b9
commit 5b48574d5e
1 changed files with 13 additions and 5 deletions

View File

@ -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
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"))