+
+def build_loopbackcfg(target):
+ """Generate GRUB's loopback.cfg based on existing config files.
+
+ @target: target directory
+ """
+
+ grub_dir = '/boot/grub/'
+ mkdir(os.path.join(target, grub_dir))
+
+ f = open(target + grub_dir + 'loopback.cfg', 'w')
+
+ f.write("# grml2usb generated grub2 configuration file\n")
+ f.write("source /boot/grub/header.cfg\n")
+
+ for defaults in glob.glob(target + os.path.sep + grub_dir + os.path.sep + "*_default.cfg"):
+ sourcefile = defaults.split(target + os.path.sep)[1]
+ logging.debug("Found source file" + sourcefile)
+ os.path.isfile(defaults) and f.write("source " + sourcefile + "\n")
+
+ for ops in glob.glob(target + os.path.sep + grub_dir + os.path.sep + "*_options.cfg"):
+ sourcefile = ops.split(target + os.path.sep)[1]
+ logging.debug("Found source file" + sourcefile)
+ os.path.isfile(ops) and f.write("source " + sourcefile + "\n")
+
+ f.write("source /boot/grub/adddons.cfg\n")
+ f.write("source /boot/grub/footer.cfg\n")
+ f.close()
+
+