Commits

Rodrigo Bistolfi committed e22352e

controller.bootloader: Install initrd *after* bootloader

Comments (0)

Files changed (1)

vinstall/controller/bootloader.py

 
 
 import os
-from itertools import chain
 from vinstall.backend import bootloader, utils, sp
 from vinstall.backend.media import Disk, Partition
 from vinstall.core import Render, Controller, model, log
         """Return next step
 
         """
-        return None
+        return InitrdController
 
     def previous(self):
         """Return previous step
         LOG.debug("Target; %s", target)
         yield self.set_bind_mounts, tuple(), "Mounting pseudo filesystems"
         yield self.install_bootloader, (bootloader, target), "Installing bootloader"
-        yield self.clear_bind_mounts, tuple(), "Clearing bind mounts"
 
     def install_bootloader(self, bloader, target):
         """Install the bootloader
         for system in bootloader.OperatingSystem.all():
             lilo.add_os(system)
         with utils.Chroot("/mnt/TARGET"):
-            self.depmod()
-            self.mkinitrd()
             lilo.backup_config()
             lilo.write_config()
             lilo.install()
         LOG.debug("Installing Grub2 to %s", target)
         grub2 = bootloader.Grub2(target)
         with utils.Chroot("/mnt/TARGET"):
-            self.depmod()
-            self.mkinitrd()
             grub2.backup_config()
             grub2.install()
             grub2.write_config()
 
-    def mkinitrd(self):
-        LOG.debug("Creating initrd")
-        root = self.config["target_device"]
-        fs = self.config["target_device_fs"]
-        try:
-            utils.mkinitrd(root.path(), fs)
-        except Exception as e:
-            # initrd not supported
-            LOG.error("Initrd not supported: %s", e)
-
-    def depmod(self):
-        LOG.debug("Running depmod -a")
-        utils.depmod()
-
     def set_bind_mounts(self):
         """Bind mount some paths into the target.
         Later steps will need this when we chroot there
             cmd = "mount -o bind /%s /mnt/TARGET/%s" % (point, point)
             sp.check_call(cmd.split())
 
+
+
+class InitrdController(object):
+    "Create an initrd in target device"
+    
+    def init(self):
+        self.device = self.config["target_device"]
+        self.fs = self.config["target_device_fs"]
+
+    def next(self):
+        return None
+
+    def previous(self):
+        return Bootloader
+        
+    def command(self):
+        mkinitrd_doc = "Creating initrd for %s (%s)" % (self.root, self.fs)
+        yield self.mkinitrd, tuple(), mkinitrd_doc
+        yield self.depmod, tuple(), "Running depmod"
+        yield self.clear_bind_mounts, tuple(), "Clearing bind mounts"
+        
+    def mkinitrd(self):
+        LOG.debug("Creating initrd")
+        err = None
+        with utils.Chroot:
+            try:
+                utils.mkinitrd(self.root.path(), self.fs)
+            except Exception as e:
+                # initrd no supported
+                err = e
+        if err is not None:
+            LOG.error("Initrd not supported: %s", e)
+
+    def depmod(self):
+        LOG.debug("Running depmod -a")
+        with utils.Chroot("/mnt/TARGET"):
+            utils.depmod()
+
     def clear_bind_mounts(self):
         """Clear the mountpoints that were mounted for the configuration
 
         for mpoint in ("sys","proc","dev"):
             cmd = "umount -f /mnt/TARGET/%s" % mpoint
             sp.check_call(cmd.split())
-