Split initrd for multiple kernels

This commit is contained in:
Martin Gracik 2010-12-06 14:59:59 +01:00
parent 826e580cd8
commit bdb9b700f4
2 changed files with 49 additions and 24 deletions

View File

@ -177,10 +177,17 @@ class Lorax(BaseLoraxClass):
logger.debug("set efiarch = {0.efiarch}".format(self))
logger.debug("set libdir = {0.libdir}".format(self))
# set up work directory
logger.info("setting up work directory")
self.workdir = workdir or tempfile.mkdtemp(prefix="pylorax.work.")
if not os.path.isdir(self.workdir):
os.makedirs(self.workdir)
logger.debug("using work directory {0.workdir}".format(self))
# set up install tree
logger.info("setting up install tree")
self.installtree = LoraxInstallTree(self.yum, self.basearch,
self.libdir)
self.libdir, self.workdir)
# set up required build parameters
logger.info("setting up build parameters")
@ -199,13 +206,6 @@ class Lorax(BaseLoraxClass):
logger.debug("set bugurl = {0.bugurl}".format(self))
logger.debug("set is_beta = {0.is_beta}".format(self))
# set up work directory
logger.info("setting up work directory")
self.workdir = workdir or tempfile.mkdtemp(prefix="pylorax.work.")
if not os.path.isdir(self.workdir):
os.makedirs(self.workdir)
logger.debug("using work directory {0.workdir}".format(self))
# parse the template
logger.info("parsing the template")
tfile = joinpaths(self.conf.get("lorax", "sharedir"),
@ -381,29 +381,43 @@ class Lorax(BaseLoraxClass):
logger.info("cleaning up python files")
self.installtree.cleanup_python_files()
# compress install tree
initrd = DataHolder(fname="initrd.img",
fpath=joinpaths(self.workdir, "initrd.img"))
# compress install tree (create initrd)
initrds = []
for kernel in self.outputtree.kernels:
suffix = ""
if kernel.ktype == constants.K_PAE:
suffix = "-PAE"
elif kernel.ktype == constants.K_XEN:
suffix = "-XEN"
logger.info("compressing install tree")
success, elapsed = self.installtree.compress(initrd)
if not success:
logger.error("error while compressing install tree")
else:
logger.info("took {0:.2f} seconds".format(elapsed))
fname = "initrd{0}.img".format(suffix)
# copy initrd to pxebootdir
shutil.copy2(initrd.fpath, self.outputtree.pxebootdir)
initrd = DataHolder(fname=fname,
fpath=joinpaths(self.workdir, fname),
itype=kernel.ktype)
logger.info("compressing install tree ({0})".format(kernel.version))
success, elapsed = self.installtree.compress(initrd, kernel)
if not success:
logger.error("error while compressing install tree")
else:
logger.info("took {0:.2f} seconds".format(elapsed))
# copy initrd to pxebootdir
shutil.copy2(initrd.fpath, self.outputtree.pxebootdir)
initrds.append(initrd)
# create initrd hard link in isolinuxdir
source = joinpaths(self.outputtree.pxebootdir, initrd.fname)
link_name = joinpaths(self.outputtree.isolinuxdir, initrd.fname)
source = joinpaths(self.outputtree.pxebootdir, initrds[0].fname)
link_name = joinpaths(self.outputtree.isolinuxdir, initrds[0].fname)
os.link(source, link_name)
# create efi images
efiboot = None
if grubefi:
kernel = self.outputtree.kernels[0]
initrd = initrds[0]
# create efiboot image with kernel
logger.info("creating efiboot image with kernel")

View File

@ -39,12 +39,13 @@ from sysutils import *
class LoraxInstallTree(BaseLoraxClass):
def __init__(self, yum, basearch, libdir):
def __init__(self, yum, basearch, libdir, workdir):
BaseLoraxClass.__init__(self)
self.yum = yum
self.root = self.yum.installroot
self.basearch = basearch
self.libdir = libdir
self.workdir = workdir
self.lcmds = constants.LoraxRequiredCommands()
@ -338,6 +339,9 @@ class LoraxInstallTree(BaseLoraxClass):
for fname in ["build", "source"]:
os.unlink(joinpaths(moddir, fname))
# move modules out of the tree
shutil.move(moddir, self.workdir)
def create_gconf(self):
gconfdir = joinpaths(self.root, ".gconf/desktop")
os.makedirs(gconfdir)
@ -498,11 +502,14 @@ class LoraxInstallTree(BaseLoraxClass):
dst = joinpaths(self.root, "sbin")
shutil.copy2(src, dst)
def compress(self, initrd):
def compress(self, initrd, kernel):
chdir = lambda: os.chdir(self.root)
start = time.time()
# move corresponding modules to the tree
shutil.move(joinpaths(self.workdir, kernel.version),
joinpaths(self.root, "modules"))
find = subprocess.Popen([self.lcmds.FIND, "."], stdout=subprocess.PIPE,
preexec_fn=chdir)
@ -514,6 +521,10 @@ class LoraxInstallTree(BaseLoraxClass):
gzipped.write(cpio.stdout.read())
gzipped.close()
# move modules out of the tree again
shutil.move(joinpaths(self.root, "modules", kernel.version),
self.workdir)
elapsed = time.time() - start
return True, elapsed