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

View File

@ -186,10 +186,13 @@ class TreeBuilder(object):
def kernels(self): def kernels(self):
return findkernels(root=self.vars.inroot) 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 '''Rebuild all the initrds in the tree. If backup is specified, each
initrd will be renamed with backup as a suffix before rebuilding. 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 dracut = ["dracut", "--nomdadmconf", "--nolvmconf"] + add_args
if not backup: if not backup:
dracut.append("--force") dracut.append("--force")
@ -197,11 +200,16 @@ class TreeBuilder(object):
# Hush some dracut warnings. TODO: bind-mount proc in place? # Hush some dracut warnings. TODO: bind-mount proc in place?
open(joinpaths(self.vars.inroot,"/proc/modules"),"w") open(joinpaths(self.vars.inroot,"/proc/modules"),"w")
for kernel in self.kernels: 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: if backup:
initrd = joinpaths(self.vars.inroot, kernel.initrd.path) initrd = joinpaths(self.vars.inroot, outfile)
os.rename(initrd, initrd + backup) os.rename(initrd, initrd + backup)
cmd = dracut + [kernel.initrd.path, kernel.version] cmd = dracut + [outfile, kernel.version]
runcmd(cmd, root=self.vars.inroot) runcmd(cmd, root=self.vars.inroot)
os.unlink(joinpaths(self.vars.inroot,"/proc/modules")) os.unlink(joinpaths(self.vars.inroot,"/proc/modules"))