From: "Brian C. Lane" bcl@redhat.com
In the latest method for booting the rootfs is in the LiveOS directory of the media, not appended to the initrd. Detect this and mount the iso and pass the CDLABEL to virt-install. --- src/sbin/livemedia-creator | 47 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 41 insertions(+), 6 deletions(-)
diff --git a/src/sbin/livemedia-creator b/src/sbin/livemedia-creator index 3848dd0..88d31f8 100755 --- a/src/sbin/livemedia-creator +++ b/src/sbin/livemedia-creator @@ -2,7 +2,7 @@ # # Live Media Creator # -# Copyright (C) 2011 Red Hat, Inc. +# Copyright (C) 2011-2012 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -44,7 +44,7 @@ from pykickstart.version import makeVersion
# Use the Lorax treebuilder branch for iso creation from pylorax.base import DataHolder -from pylorax.treebuilder import TreeBuilder, RuntimeBuilder +from pylorax.treebuilder import TreeBuilder, RuntimeBuilder, udev_escape from pylorax.sysutils import joinpaths, remove, linktree from pylorax.imgutils import PartitionMount, mksparse from pylorax.executils import execWithRedirect, execWithCapture @@ -158,8 +158,11 @@ class IsoMountpoint(object): """ Mount the iso on a temporary directory and check to make sure the vmlinuz and initrd.img files exist + Check the iso for a LiveOS directory and set a flag. + Extract the iso's label. """ def __init__( self, iso_path ): + self.label = None self.iso_path = iso_path self.mount_dir = tempfile.mkdtemp() if not self.mount_dir: @@ -176,6 +179,7 @@ class IsoMountpoint(object): self.repo = self.mount_dir else: self.repo = None + self.liveos = os.path.isdir( self.mount_dir+"/LiveOS" )
try: for f in [self.kernel, self.initrd]: @@ -185,12 +189,27 @@ class IsoMountpoint(object): self.umount() raise
+ self.get_iso_label() + def umount( self ): cmd = ["umount", self.mount_dir] log.debug( cmd ) execWithRedirect( cmd[0], cmd[1:] ) os.rmdir( self.mount_dir )
+ def get_iso_label( self ): + """ + Get the iso's label using isoinfo + """ + cmd = [ "isoinfo", "-d", "-i", self.iso_path ] + log.debug( cmd ) + isoinfo_output = execWithCapture( cmd[0], cmd[1:] ) + log.debug( isoinfo_output ) + for line in isoinfo_output.splitlines(): + if line.startswith("Volume id: "): + self.label = line[11:] + return +
class ImageMount(object): """ @@ -297,22 +316,38 @@ class VirtualInstall( object ): for ks in ks_paths: cmd.append("--initrd-inject") cmd.append(ks) + disk_opts = "path={0}".format(disk_img) disk_opts += ",format=raw" if not os.path.isfile(disk_img): disk_opts += ",size={0}".format(img_size) + cmd.append("--disk") + cmd.append(disk_opts) + + if iso.liveos: + disk_opts = "path={0},device=cdrom".format(iso.iso_path) + cmd.append("--disk") + cmd.append(disk_opts) + extra_args = "ks=file:/{0}".format(os.path.basename(ks_paths[0])) if kernel_args: extra_args += " "+kernel_args if not vnc: extra_args += " console=/dev/ttyS0" + if iso.liveos: + extra_args += " root=live:CDLABEL={0}".format(udev_escape(iso.label)) + cmd.append("--extra-args") + cmd.append(extra_args) + + cmd.append("--location") + cmd.append(iso.mount_dir) + channel_args = "tcp,host={0}:{1},mode=connect,target_type=virtio" \ ",name=org.fedoraproject.anaconda.log.0".format( virtio_host, virtio_port) - [cmd.append(o) for o in ["--disk", disk_opts, - "--extra-args", extra_args, - "--location", iso.mount_dir, - "--channel", channel_args]] + cmd.append("--channel") + cmd.append(channel_args) + log.debug( cmd )
rc = execWithRedirect( cmd[0], cmd[1:] )
From: "Brian C. Lane" bcl@redhat.com
The installer no longer has access to the initrd's root. We need to copy any needed files over to /sysroot before switching root. This copies *.cfg and *.ks files.
It also adds the ability to add dracut hook scripts to the initramfs from /usr/share/lorax/dracut_hooks/
This re-adds commit af6d4e2c50072eb3d76242481cb6c1bc016f6f54 which was lost during the switch to the treebuilder branch. --- share/dracut_hooks/99anaconda-copy-ks.sh | 4 +++ src/pylorax/treebuilder.py | 41 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 share/dracut_hooks/99anaconda-copy-ks.sh
diff --git a/share/dracut_hooks/99anaconda-copy-ks.sh b/share/dracut_hooks/99anaconda-copy-ks.sh new file mode 100644 index 0000000..ed52088 --- /dev/null +++ b/share/dracut_hooks/99anaconda-copy-ks.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Copy over kickstart files from the initrd to the sysroot before pivot +cp /*cfg /*ks /sysroot/ 2> /dev/null + diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py index 8f4d239..12fdcf9 100644 --- a/src/pylorax/treebuilder.py +++ b/src/pylorax/treebuilder.py @@ -25,7 +25,7 @@ from os.path import basename, isdir from subprocess import check_call, check_output
from sysutils import joinpaths, remove -from shutil import copytree +from shutil import copytree, copy2 from base import DataHolder from ltmpl import LoraxTemplateRunner import imgutils @@ -163,6 +163,7 @@ class TreeBuilder(object): isolabel=isolabel, udev=udev_escape) self._runner = LoraxTemplateRunner(inroot, outroot, templatedir=templatedir) self._runner.defaults = self.vars + self.templatedir = templatedir
@property def kernels(self): @@ -175,6 +176,9 @@ class TreeBuilder(object): dracut = ["dracut", "--noprefix", "--nomdadmconf", "--nolvmconf"] + add_args if not backup: dracut.append("--force") + hooks = [("99anaconda-copy-ks.sh", "/lib/dracut/hooks/pre-pivot")] + hook_commands = self.copy_dracut_hooks(hooks) + # Hush some dracut warnings. TODO: bind-mount proc in place? open(joinpaths(self.vars.inroot,"/proc/modules"),"w") for kernel in self.kernels: @@ -183,7 +187,7 @@ class TreeBuilder(object): initrd = joinpaths(self.vars.inroot, kernel.initrd.path) os.rename(initrd, initrd + backup) check_call(["chroot", self.vars.inroot] + \ - dracut + [kernel.initrd.path, kernel.version]) + dracut + hook_commands + [kernel.initrd.path, kernel.version]) os.unlink(joinpaths(self.vars.inroot,"/proc/modules"))
def build(self): @@ -198,6 +202,39 @@ class TreeBuilder(object): iso = joinpaths(self.vars.outroot, data['boot.iso']) check_call(["implantisomd5", iso])
+ @property + def dracut_hooks_path(self): + """ Return the path to the lorax dracut hooks scripts + + Use the configured share dir if it is setup, + otherwise default to /usr/share/lorax/dracut_hooks + """ + if self.templatedir: + return joinpaths(self.templatedir, "dracut_hooks") + else: + return "/usr/share/lorax/dracut_hooks" + + def copy_dracut_hooks(self, hooks): + """ Copy the hook scripts in hooks into the installroot's /tmp/ + and return a list of commands to pass to dracut when creating the + initramfs + + hooks is a list of tuples with the name of the hook script and the + target dracut hook directory + (eg. [("99anaconda-copy-ks.sh", "/lib/dracut/hooks/pre-pivot")]) + """ + dracut_commands = [] + for hook_script, dracut_path in hooks: + src = joinpaths(self.dracut_hooks_path, hook_script) + if not os.path.exists(src): + logger.error("Missing lorax dracut hook script %s" % (src)) + continue + dst = joinpaths(self.vars.inroot, "/tmp/", hook_script) + copy2(src, dst) + dracut_commands += ["--include", joinpaths("/tmp/", hook_script), + dracut_path] + return dracut_commands + #### TreeBuilder helper functions
def findkernels(root="/", kdir="boot"):
On Wed, 2012-01-25 at 22:03 -0800, Brian C. Lane wrote:
From: "Brian C. Lane" bcl@redhat.com
The installer no longer has access to the initrd's root. We need to copy any needed files over to /sysroot before switching root. This copies *.cfg and *.ks files.
It also adds the ability to add dracut hook scripts to the initramfs from /usr/share/lorax/dracut_hooks/
This re-adds commit af6d4e2c50072eb3d76242481cb6c1bc016f6f54 which was lost during the switch to the treebuilder branch.
Oh! Sorry about that.
This patch looks fine, so feel free to push. A couple notes below just for the record..
diff --git a/share/dracut_hooks/99anaconda-copy-ks.sh b/share/dracut_hooks/99anaconda-copy-ks.sh new file mode 100644 index 0000000..ed52088 --- /dev/null +++ b/share/dracut_hooks/99anaconda-copy-ks.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# Copy over kickstart files from the initrd to the sysroot before pivot +cp /*cfg /*ks /sysroot/ 2> /dev/null
99anaconda-copy-ks.sh will be absorbed into the upcoming "anaconda" dracut module, so this should get dropped when that happens.
- def copy_dracut_hooks(self, hooks):
""" Copy the hook scripts in hooks into the installroot's /tmp/
and return a list of commands to pass to dracut when creating the
initramfs
hooks is a list of tuples with the name of the hook script and the
target dracut hook directory
(eg. [("99anaconda-copy-ks.sh", "/lib/dracut/hooks/pre-pivot")])
I'd rather see this stuff happen in the templates somewhere, but since dracut still gets invoked outside the templates there's really no other way to do it.
-w
On Wed, 2012-01-25 at 22:03 -0800, Brian C. Lane wrote:
From: "Brian C. Lane" bcl@redhat.com
In the latest method for booting the rootfs is in the LiveOS directory of the media, not appended to the initrd. Detect this and mount the iso and pass the CDLABEL to virt-install.
Looks fine. Ack, with one note:
self.liveos = os.path.isdir( self.mount_dir+"/LiveOS" )
This path may change - possibly soon: https://bugzilla.redhat.com/show_bug.cgi?id=782108
So we might look into parsing the bootloader config on the image (or .treeinfo?) to find the runtime image.
-w
anaconda-devel@lists.fedoraproject.org