[PATCH] copy kickstarts into sysroot (#743135)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Brian C. Lane" <bcl@xxxxxxxxxx>

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/
---
 share/dracut_hooks/99anaconda-copy-ks.sh |    4 ++
 src/pylorax/__init__.py                  |    3 +-
 src/pylorax/installtree.py               |   46 ++++++++++++++++++++++++++++--
 3 files changed, 49 insertions(+), 4 deletions(-)
 create mode 100755 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 100755
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/__init__.py b/src/pylorax/__init__.py
index 8eb6c7f..ff14b4f 100644
--- a/src/pylorax/__init__.py
+++ b/src/pylorax/__init__.py
@@ -203,7 +203,8 @@ class Lorax(BaseLoraxClass):
         # set up install tree
         logger.info("setting up install tree")
         self.installtree = LoraxInstallTree(self.yum, self.basearch,
-                                            self.libdir, self.workdir)
+                                            self.libdir, self.workdir,
+                                            self.conf)
 
         # set up required build parameters
         logger.info("setting up build parameters")
diff --git a/src/pylorax/installtree.py b/src/pylorax/installtree.py
index eaea98b..88fa671 100644
--- a/src/pylorax/installtree.py
+++ b/src/pylorax/installtree.py
@@ -39,7 +39,7 @@ from sysutils import *
 
 class LoraxInstallTree(BaseLoraxClass):
 
-    def __init__(self, yum, basearch, libdir, workdir):
+    def __init__(self, yum, basearch, libdir, workdir, conf=None):
         BaseLoraxClass.__init__(self)
         self.yum = yum
         self.root = self.yum.installroot
@@ -47,9 +47,45 @@ class LoraxInstallTree(BaseLoraxClass):
         self.libdir = libdir
         self.workdir = workdir
         self.initramfs = {}
+        self.conf = conf
 
         self.lcmds = constants.LoraxRequiredCommands()
 
+    @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.conf:
+            return joinpaths( self.conf.get("lorax", "sharedir"),
+                              "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.root, "/tmp/", hook_script )
+            shutil.copy2( src, dst )
+            dracut_commands += ["--include", joinpaths( "/tmp/", hook_script ),
+                                dracut_path]
+
+        return dracut_commands
+
     def remove_locales(self):
         chroot = lambda: os.chroot(self.root)
 
@@ -548,12 +584,16 @@ class LoraxInstallTree(BaseLoraxClass):
 
     def make_dracut_initramfs(self):
         for kernel in self.kernels:
+            hooks = [ ("99anaconda-copy-ks.sh", "/lib/dracut/hooks/pre-pivot") ]
+            hook_commands = self.copy_dracut_hooks(hooks)
+
             outfile = "/tmp/initramfs.img" # inside the chroot
             logger.debug("chrooting into installtree to create initramfs.img")
             subprocess.check_call(["chroot", self.root, "/sbin/dracut",
                                    "--noprefix", "--nomdadmconf", "--nolvmconf",
-                                   "--xz", "--modules", "base dmsquash-live",
-                                   outfile, kernel.version])
+                                   "--xz", "--modules", "base dmsquash-live"] \
+                                  + hook_commands \
+                                  + [outfile, kernel.version])
             # move output file into installtree workdir
             dstdir = joinpaths(self.workdir, "dracut-%s" % kernel.version)
             os.makedirs(dstdir)
-- 
1.7.6

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux