usb-creator-hackers team mailing list archive
-
usb-creator-hackers team
-
Mailing list archive
-
Message #00076
[Merge] lp:~superm1/usb-creator/grub-support into lp:usb-creator
Mario Limonciello has proposed merging lp:~superm1/usb-creator/grub-support into lp:usb-creator.
Requested reviews:
Colin Watson (cjwatson)
usb-creator hackers (usb-creator-hackers)
This adds early support for installing using grub rather than syslinux (when applicable) to avoid getting into the same situation as had happened with 10.10 changing syntax of the syslinux.cfg.
It makes an assumption that when grub is installed to CDs it will be installed in boot/grub/i386-pc. This assumption was based upon the way that EFI was implemented on AMD64 CDs for 10.10 that modules were in /boot/grub/x86_64-efi. If that's a bad assumption, this can be modified.
--
https://code.launchpad.net/~superm1/usb-creator/grub-support/+merge/34504
Your team usb-creator hackers is requested to review the proposed merge of lp:~superm1/usb-creator/grub-support into lp:usb-creator.
=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper 2010-04-01 13:11:48 +0000
+++ bin/usb-creator-helper 2010-09-02 23:49:45 +0000
@@ -18,6 +18,8 @@
import gobject
import dbus.service
import logging
+import tempfile
+import os
logging.basicConfig(level=logging.DEBUG)
from dbus.mainloop.glib import DBusGMainLoop
from usbcreator.misc import *
@@ -67,15 +69,23 @@
self.polkit = None
# TODO return boolean success
- @dbus.service.method(USBCREATOR_IFACE, in_signature='s', out_signature='',
+ @dbus.service.method(USBCREATOR_IFACE, in_signature='ss', out_signature='',
sender_keyword='sender', connection_keyword='conn')
- def InstallBootloader(self, device, sender=None, conn=None):
- '''Installs syslinux to the partition boot code area and writes the
+ def InstallBootloader(self, device, bootloader, sender=None, conn=None):
+ '''Install a bootloader to the boot code area, either grub or syslinux.
+
+ The function takes a partition device file of the form /dev/sda1
+ and a bootloader argument of 'grub' or 'syslinux'
+
+ For GRUB, it's expected that GRUB already exists, all that is
+ installed is the bootsector code from grub-setup.
+
+ For syslinux:
+ Installs syslinux to the partition boot code area and writes the
syslinux boot code to the disk code area. The latter is done to
handle cases where a bootloader is accidentally installed to the
- MBR, and to handle some buggy BIOSes.
+ MBR, and to handle some buggy BIOSes.'''
- The function takes a partition device file of the form /dev/sda1.'''
self.check_polkit(sender, conn, 'com.ubuntu.usbcreator.bootloader')
check_system_internal(device)
@@ -87,27 +97,36 @@
udisks = dbus.Interface(udisks, DISKS_IFACE)
device = udisks.FindDeviceByDeviceFile(device)
deviceobj = bus.get_object(DISKS_IFACE, device)
-
- popen(['syslinux', '-f', device_file])
+
# Find the parent of the partition.
parent = deviceobj.Get(device, 'partition-slave',
dbus_interface=PROPS_IFACE)
parentobj = bus.get_object(DISKS_IFACE, parent)
parent = parentobj.Get(parent, 'device-file',
dbus_interface=PROPS_IFACE)
- # Write the syslinux MBR.
- popen(['dd', 'if=/usr/lib/syslinux/mbr.bin', 'of=%s' % parent,
- 'bs=446', 'count=1', 'conv=sync'])
- num = deviceobj.Get(device, 'partition-number',
- dbus_interface=PROPS_IFACE)
- try:
- popen(['/sbin/parted', parent, 'set', str(num), 'boot', 'on'])
- except USBCreatorProcessException:
- # Don't worry about not being able to re-read the partition table.
- # TODO: As this will still be a problem for KVM users, this should
- # be fixed by unmounting all the partitions before we get to this
- # point, then remounting the target partition after.
- pass
+
+ if bootloader == 'grub':
+ core = tempfile.mktemp()
+ popen(['grub-mkimage', '-p', '/boot/grub/i386-pc', '-o', core,
+ 'biosdisk', 'part_msdos', 'fat', 'ntfs'])
+ popen(['/usr/sbin/grub-setup', '-d', '/', '-b', '/usr/lib/grub/i386-pc/boot.img',
+ '-c', core, parent])
+ os.remove(core)
+ elif bootloader == 'syslinux':
+ popen(['syslinux', '-f', device_file])
+ # Write the syslinux MBR.
+ popen(['dd', 'if=/usr/lib/syslinux/mbr.bin', 'of=%s' % parent,
+ 'bs=446', 'count=1', 'conv=sync'])
+ num = deviceobj.Get(device, 'partition-number',
+ dbus_interface=PROPS_IFACE)
+ try:
+ popen(['/sbin/parted', parent, 'set', str(num), 'boot', 'on'])
+ except USBCreatorProcessException:
+ # Don't worry about not being able to re-read the partition table.
+ # TODO: As this will still be a problem for KVM users, this should
+ # be fixed by unmounting all the partitions before we get to this
+ # point, then remounting the target partition after.
+ pass
@dbus.service.method(USBCREATOR_IFACE, in_signature='s', out_signature='',
sender_keyword='sender', connection_keyword='conn')
=== modified file 'debian/changelog'
--- debian/changelog 2010-08-31 18:33:45 +0000
+++ debian/changelog 2010-09-02 23:49:45 +0000
@@ -2,6 +2,8 @@
* Mangle whether the 'ui' keyword is in syslinux.cfg based on the OS version.
(LP: #608382)
+ * Grow support for installing GRUB to USB sticks if it's detected in the image
+ rather than isolinux.
-- Mario Limonciello <Mario_Limonciello@xxxxxxxx> Mon, 30 Aug 2010 17:00:20 -0500
=== modified file 'usbcreator/install.py'
--- usbcreator/install.py 2010-08-31 18:33:45 +0000
+++ usbcreator/install.py 2010-09-02 23:49:45 +0000
@@ -185,7 +185,7 @@
if os.path.exists(ldlinux):
os.remove(ldlinux)
- def install_bootloader(self):
+ def install_bootloader(self, bootloader):
logging.debug('install_bootloader')
self.progress_pulse()
self.progress_message(_('Installing the bootloader...'))
@@ -207,7 +207,7 @@
bus = dbus.SystemBus()
obj = bus.get_object('com.ubuntu.USBCreator',
'/com/ubuntu/USBCreator')
- obj.InstallBootloader(self.device,
+ obj.InstallBootloader(self.device, bootloader,
dbus_interface='com.ubuntu.USBCreator',
timeout=MAX_DBUS_TIMEOUT)
except dbus.DBusException:
@@ -419,7 +419,12 @@
self.remove_extras()
self.initialize_progress_thread()
- self.install_bootloader()
+
+ if 'boot/grub/i386-pc' in listing:
+ bootloader = 'grub'
+ else:
+ bootloader = 'syslinux'
+ self.install_bootloader(bootloader)
# Copy.
@@ -507,7 +512,11 @@
self.check()
self.initialize_progress_thread()
- self.install_bootloader()
+ if os.path.isdir(os.path.join(self.source, 'boot', 'grub', 'i386-pc')):
+ bootloader = 'grub'
+ else:
+ bootloader = 'syslinux'
+ self.install_bootloader(bootloader)
self.progress_message(_('Copying files...'))
for dirpath, dirnames, filenames in os.walk(self.source):
Follow ups