← Back to team overview

usb-creator-hackers team mailing list archive

[Merge] lp:~yuningdodo/usb-creator/usb-creator.lp1159016-mangle-grub into lp:usb-creator

 

Yu Ning has proposed merging lp:~yuningdodo/usb-creator/usb-creator.lp1159016-mangle-grub into lp:usb-creator.

Requested reviews:
  usb-creator hackers (usb-creator-hackers)
Related bugs:
  Bug #1159016 in usb-creator (Ubuntu): "64 bit live-USB successfully boots, but without persistence on UEFI pc"
  https://bugs.launchpad.net/ubuntu/+source/usb-creator/+bug/1159016

For more details, see:
https://code.launchpad.net/~yuningdodo/usb-creator/usb-creator.lp1159016-mangle-grub/+merge/250267

* usbcreator/install.py: adjust grub configurations, otherwise the persistent mode can't be enabled with UEFI BIOS. (LP: #1159016)

-- 
Your team usb-creator hackers is requested to review the proposed merge of lp:~yuningdodo/usb-creator/usb-creator.lp1159016-mangle-grub into lp:usb-creator.
=== modified file 'usbcreator/install.py'
--- usbcreator/install.py	2013-01-28 12:44:46 +0000
+++ usbcreator/install.py	2015-02-19 07:39:13 +0000
@@ -324,6 +324,42 @@
                     f.close()
         self.check()
 
+    def mangle_grub(self):
+        logging.debug('mangle_grub')
+        self.progress_message(_('Modifying grub configuration...'))
+        
+        # Mangle the configuration files based on the options we've selected.
+        import glob
+        to_append = ' cdrom-detect/try-usb=true noprompt'
+        if self.persist != 0:
+            to_append += ' persistent'
+        for filename in glob.iglob(os.path.join(self.target,
+                                                'boot', 'grub', '*.cfg')):
+            f = None
+            try:
+                f = open(filename, 'r')
+                to_write = []
+                for line in f.readlines():
+                    tokens = line.strip().split()
+                    if tokens and tokens[0] == 'linux' \
+                            and 'boot=casper' in tokens \
+                            and 'integrity-check' not in tokens:
+                        line = line.rstrip('\r\n') + to_append + '\n'
+                    to_write.append(line)
+                f.close()
+                f = open(filename, 'w')
+                f.writelines(to_write)
+            except (KeyboardInterrupt, SystemExit):
+                raise
+            except:
+                # TODO evand 2009-07-28: Fail?  Warn?
+                logging.exception('Unable to add persistence support to %s:' %
+                                  filename)
+            finally:
+                if f:
+                    f.close()
+        self.check()
+
     def create_persistence(self):
         logging.debug('create_persistence')
         if self.persist != 0:
@@ -527,6 +563,7 @@
         else:
             self.install_bootloader()
             self.mangle_syslinux()
+        self.mangle_grub()
 
         self.create_persistence()
         self.sync()
@@ -623,6 +660,7 @@
         else:
             self.install_bootloader()
             self.mangle_syslinux()
+        self.mangle_grub()
 
         self.create_persistence()
         self.sync()


Follow ups