Add dracut support to livecd/liveusb images
authorAnas Nashif <anas.nashif@intel.com>
Fri, 9 Nov 2012 18:03:38 +0000 (10:03 -0800)
committerAnas Nashif <anas.nashif@intel.com>
Fri, 9 Nov 2012 18:03:38 +0000 (10:03 -0800)
This adds support to initrd images using dracut and enables systemd
and udev and other plugins that will be used to boot pc-style systems.

The previous initrd method was last used in MeeGo and is currently not
supported in in Tizen, so it is obsolete and does work with new udev
and systemd booting.

mic/imager/livecd.py
mic/imager/liveusb.py
mic/kickstart/__init__.py

index a9f4d09..116e8a0 100644 (file)
@@ -129,15 +129,10 @@ class LiveImageCreatorBase(LoopImageCreator):
         """
 
         if self.ks is None:
-            r = "ro liveimg"
+            r = "ro rd.live.image"
         else:
             r = kickstart.get_kernel_args(self.ks)
 
-        if os.path.exists(self._instroot + "/usr/bin/rhgb") or \
-           os.path.exists(self._instroot + "/usr/bin/plymouth") and \
-           ' rhgb' not in r:
-            r += ' rhgb'
-
         return r
 
     def _get_mkisofs_options(self, isodir):
@@ -166,15 +161,22 @@ class LiveImageCreatorBase(LoopImageCreator):
 
         return False
 
+    def __restore_file(self,path):
+        try:
+            os.unlink(path)
+        except:
+            pass
+        if os.path.exists(path + '.rpmnew'):
+            os.rename(path + '.rpmnew', path)
+
     def _mount_instroot(self, base_on = None):
         LoopImageCreator._mount_instroot(self, base_on)
         self.__write_initrd_conf(self._instroot + "/etc/sysconfig/mkinitrd")
+        self.__write_dracut_conf(self._instroot + "/etc/dracut.conf.d/02livecd.conf")
 
     def _unmount_instroot(self):
-        try:
-            os.unlink(self._instroot + "/etc/sysconfig/mkinitrd")
-        except:
-            pass
+        self.__restore_file(self._instroot + "/etc/sysconfig/mkinitrd")
+        self.__restore_file(self._instroot + "/etc/dracut.conf.d/02livecd.conf")
         LoopImageCreator._unmount_instroot(self)
 
     def __ensure_isodir(self):
@@ -199,6 +201,12 @@ class LiveImageCreatorBase(LoopImageCreator):
             env["LIVE_ROOT"] = self.__ensure_isodir()
 
         return env
+    def __write_dracut_conf(self, path):
+        if not os.path.exists(os.path.dirname(path)):
+            fs_related.makedirs(os.path.dirname(path))
+        f = open(path, "a")
+        f.write('add_dracutmodules+=" dmsquash-live pollcdrom "')
+        f.close()
 
     def __write_initrd_conf(self, path):
         content = ""
@@ -354,7 +362,7 @@ class x86LiveImageCreator(LiveImageCreatorBase):
 
     def __copy_syslinux_background(self, isodest):
         background_path = self._instroot + \
-                          "/usr/lib/anaconda-runtime/syslinux-vesa-splash.jpg"
+                          "/usr/share/branding/default/syslinux/syslinux-vesa-splash.jpg"
 
         if not os.path.exists(background_path):
             return False
@@ -365,15 +373,23 @@ class x86LiveImageCreator(LiveImageCreatorBase):
 
     def __copy_kernel_and_initramfs(self, isodir, version, index):
         bootdir = self._instroot + "/boot"
+        isDracut = False
 
         if self._alt_initrd_name:
             src_initrd_path = os.path.join(bootdir, self._alt_initrd_name)
         else:
-            src_initrd_path = os.path.join(bootdir, "initrd-" +version+ ".img")
+            if os.path.exists(bootdir + "/initramfs-" + version + ".img"):
+                src_initrd_path = os.path.join(bootdir, "initramfs-" +version+ ".img")
+                isDracut = True
+            else:
+                src_initrd_path = os.path.join(bootdir, "initrd-" +version+ ".img")
 
         try:
+            msger.debug("copy %s to %s" % (bootdir + "/vmlinuz-" + version, isodir + "/isolinux/vmlinuz" + index))
             shutil.copyfile(bootdir + "/vmlinuz-" + version,
-                            isodir + "/isolinux/vmlinuz" + index)
+                    isodir + "/isolinux/vmlinuz" + index)
+
+            msger.debug("copy %s to %s" % (src_initrd_path, isodir + "/isolinux/initrd" + index + ".img"))
             shutil.copyfile(src_initrd_path,
                             isodir + "/isolinux/initrd" + index + ".img")
         except:
@@ -386,7 +402,7 @@ class x86LiveImageCreator(LiveImageCreatorBase):
                             isodir + "/isolinux/xen" + index + ".gz")
             is_xen = True
 
-        return is_xen
+        return (is_xen,isDracut)
 
     def __is_default_kernel(self, kernel, kernels):
         if len(kernels) == 1:
@@ -417,20 +433,26 @@ menu color hotkey 7 #ffffffff #ff000000
 menu color timeout_msg 0 #ffffffff #00000000
 menu color timeout 0 #ffffffff #00000000
 menu color cmdline 0 #ffffffff #00000000
+menu hidden
+menu clear
 """ % args
 
-    def __get_image_stanza(self, is_xen, **args):
+    def __get_image_stanza(self, is_xen, isDracut, **args):
+        if isDracut:
+            args["rootlabel"] = "live:CDLABEL=%(fslabel)s" % args
+        else:
+            args["rootlabel"] = "CDLABEL=%(fslabel)s" % args
         if not is_xen:
             template = """label %(short)s
   menu label %(long)s
   kernel vmlinuz%(index)s
-  append initrd=initrd%(index)s.img root=CDLABEL=%(fslabel)s rootfstype=iso9660 %(liveargs)s %(extra)s
+  append initrd=initrd%(index)s.img root=%(rootlabel)s rootfstype=iso9660 %(liveargs)s %(extra)s
 """
         else:
             template = """label %(short)s
   menu label %(long)s
   kernel mboot.c32
-  append xen%(index)s.gz --- vmlinuz%(index)s root=CDLABEL=%(fslabel)s rootfstype=iso9660 %(liveargs)s %(extra)s --- initrd%(index)s.img
+  append xen%(index)s.gz --- vmlinuz%(index)s root=%(rootlabel)s rootfstype=iso9660 %(liveargs)s %(extra)s --- initrd%(index)s.img
 """
         return template % args
 
@@ -501,7 +523,9 @@ menu color cmdline 0 #ffffffff #00000000
         index = "0"
         netinst = None
         for version in versions:
-            is_xen = self.__copy_kernel_and_initramfs(isodir, version, index)
+            (is_xen, isDracut) = self.__copy_kernel_and_initramfs(isodir, version, index)
+            if index == "0":
+                self._isDracut = isDracut
 
             default = self.__is_default_kernel(kernel, kernels)
 
@@ -514,10 +538,15 @@ menu color cmdline 0 #ffffffff #00000000
 
             oldmenus["verify"]["long"] = "%s %s" % (oldmenus["verify"]["long"],
                                                     long)
+            # tell dracut not to ask for LUKS passwords or activate mdraid sets
+            if isDracut:
+                kern_opts = kernel_options + " rd.luks=0 rd.md=0 rd.dm=0"
+            else:
+                kern_opts = kernel_options
 
-            cfg += self.__get_image_stanza(is_xen,
+            cfg += self.__get_image_stanza(is_xen, isDracut,
                                            fslabel = self.fslabel,
-                                           liveargs = kernel_options,
+                                           liveargs = kern_opts,
                                            long = long,
                                            short = "linux" + index,
                                            extra = "",
@@ -551,7 +580,7 @@ menu color cmdline 0 #ffffffff #00000000
                 if len(menu) >= 3:
                     extra = menu[2]
 
-                cfg += self.__get_image_stanza(is_xen,
+                cfg += self.__get_image_stanza(is_xen, isDracut,
                                                fslabel = self.fslabel,
                                                liveargs = kernel_options,
                                                long = long,
@@ -567,7 +596,7 @@ menu color cmdline 0 #ffffffff #00000000
             default_index = "0"
 
         if netinst:
-            cfg += self.__get_image_stanza(is_xen,
+            cfg += self.__get_image_stanza(is_xen, isDracut,
                                            fslabel = self.fslabel,
                                            liveargs = kernel_options,
                                            long = netinst["long"],
index e46f122..d45ac79 100644 (file)
@@ -137,7 +137,7 @@ class LiveUSBImageCreator(LiveCDImageCreator):
             pattern = re.compile('rootfstype=[^ ]*')
             text = pattern.sub("rootfstype=" + fstype, text)
             if kernelargs:
-                text = text.replace("liveimg", "liveimg " + kernelargs)
+                text = text.replace("rd.live.image", "rd.live.image " + kernelargs)
 
             if overlaysizemb > 0:
                 msger.info("Initializing persistent overlay file")
@@ -158,7 +158,7 @@ class LiveUSBImageCreator(LiveCDImageCreator):
                 rc = runner.show(args)
                 if rc:
                     raise CreatorError("Can't create overlay file")
-                text = text.replace("liveimg", "liveimg overlay=" + usblabel)
+                text = text.replace("rd.live.image", "rd.live.image rd.live.overlay=" + usblabel)
                 text = text.replace(" ro ", " rw ")
 
             if swapsizemb > 0:
index 087965c..d53144d 100644 (file)
@@ -330,9 +330,12 @@ class UserConfig(KickstartConfig):
         if userconfig.groups:
             args += [ "--groups", string.join(userconfig.groups, ",") ]
         if userconfig.name:
+            args += [ "-m"]
+            args += [ "-d", "/home/%s" % userconfig.name  ]
             args.append(userconfig.name)
             try:
                 dev_null = os.open("/dev/null", os.O_WRONLY)
+                msger.debug('adding user with %s' % args)
                 subprocess.call(args,
                                  stdout = dev_null,
                                  stderr = dev_null,
@@ -726,7 +729,7 @@ def get_timeout(ks, default = None):
         return default
     return int(ks.handler.bootloader.timeout)
 
-def get_kernel_args(ks, default = "ro liveimg"):
+def get_kernel_args(ks, default = "ro rd.live.image"):
     if not hasattr(ks.handler.bootloader, "appendLine"):
         return default
     if ks.handler.bootloader.appendLine is None: