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 efiarch = {0.efiarch}".format(self))
logger.debug("set libdir = {0.libdir}".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 # set up install tree
logger.info("setting up install tree") logger.info("setting up install tree")
self.installtree = LoraxInstallTree(self.yum, self.basearch, self.installtree = LoraxInstallTree(self.yum, self.basearch,
self.libdir) self.libdir, self.workdir)
# set up required build parameters # set up required build parameters
logger.info("setting up 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 bugurl = {0.bugurl}".format(self))
logger.debug("set is_beta = {0.is_beta}".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 # parse the template
logger.info("parsing the template") logger.info("parsing the template")
tfile = joinpaths(self.conf.get("lorax", "sharedir"), tfile = joinpaths(self.conf.get("lorax", "sharedir"),
@ -381,12 +381,23 @@ class Lorax(BaseLoraxClass):
logger.info("cleaning up python files") logger.info("cleaning up python files")
self.installtree.cleanup_python_files() self.installtree.cleanup_python_files()
# compress install tree # compress install tree (create initrd)
initrd = DataHolder(fname="initrd.img", initrds = []
fpath=joinpaths(self.workdir, "initrd.img")) 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") fname = "initrd{0}.img".format(suffix)
success, elapsed = self.installtree.compress(initrd)
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: if not success:
logger.error("error while compressing install tree") logger.error("error while compressing install tree")
else: else:
@ -395,15 +406,18 @@ class Lorax(BaseLoraxClass):
# copy initrd to pxebootdir # copy initrd to pxebootdir
shutil.copy2(initrd.fpath, self.outputtree.pxebootdir) shutil.copy2(initrd.fpath, self.outputtree.pxebootdir)
initrds.append(initrd)
# create initrd hard link in isolinuxdir # create initrd hard link in isolinuxdir
source = joinpaths(self.outputtree.pxebootdir, initrd.fname) source = joinpaths(self.outputtree.pxebootdir, initrds[0].fname)
link_name = joinpaths(self.outputtree.isolinuxdir, initrd.fname) link_name = joinpaths(self.outputtree.isolinuxdir, initrds[0].fname)
os.link(source, link_name) os.link(source, link_name)
# create efi images # create efi images
efiboot = None efiboot = None
if grubefi: if grubefi:
kernel = self.outputtree.kernels[0] kernel = self.outputtree.kernels[0]
initrd = initrds[0]
# create efiboot image with kernel # create efiboot image with kernel
logger.info("creating efiboot image with kernel") logger.info("creating efiboot image with kernel")

View File

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