usb-creator-hackers team mailing list archive
-
usb-creator-hackers team
-
Mailing list archive
-
Message #00183
[Merge] lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot into lp:usb-creator
Yu Ning has proposed merging lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot into lp:usb-creator.
Requested reviews:
usb-creator hackers (usb-creator-hackers)
For more details, see:
https://code.launchpad.net/~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot/+merge/258346
--
Your team usb-creator hackers is requested to review the proposed merge of lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot into lp:usb-creator.
=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper 2015-04-23 15:19:07 +0000
+++ bin/usb-creator-helper 2015-05-06 09:06:47 +0000
@@ -191,41 +191,68 @@
popen(['dd', 'if=%s' % os.path.join(grub_location, 'core.img'), 'of=%s' % parent_file,
'bs=512', 'count=62', 'seek=1', 'conv=sync'])
else:
- if syslinux_legacy and find_on_path('syslinux-legacy'):
- syslinux_var = "syslinux-legacy"
- syslinux_exe = "syslinux-legacy"
- syslinux_bin = "/usr/lib/syslinux-legacy/mbr.bin"
- else:
- syslinux_var = "syslinux"
- syslinux_exe = "syslinux"
- syslinux_bin = "/usr/lib/syslinux/mbr/mbr.bin"
- if not os.path.exists(syslinux_bin):
- syslinux_bin = "/usr/lib/syslinux/mbr.bin"
squashfs_mnt = ''
target_mounts = obj.get_filesystem().get_cached_property('MountPoints').get_bytestring_array()
if len(target_mounts) > 0:
target_mnt = target_mounts[0]
- squashfs_img = os.path.join(target_mnt, 'casper',
- 'filesystem.squashfs')
- if os.path.exists(squashfs_img):
- # Mount the squashfs so we are possible to install
- # syslinux & mbr.bin from it.
- squashfs_mnt = self.MountISO(squashfs_img)
- if squashfs_mnt:
- for mbrbin in [
- os.path.join(squashfs_mnt, 'usr', 'lib',
- syslinux_var, 'mbr.bin'),
- os.path.join(squashfs_mnt, 'usr', 'lib',
- syslinux_var, 'mbr', 'mbr.bin'),
- os.path.join(squashfs_mnt, 'usr', 'lib',
- syslinux_var.upper(), 'mbr.bin'),
- ]:
- if os.path.exists(mbrbin):
- syslinux_exe = os.path.join(squashfs_mnt, 'usr',
- 'bin', syslinux_var)
- syslinux_bin = mbrbin
- break
- popen([syslinux_exe, '-f', device])
+ for place in [ 'install', 'casper', 'live' ]:
+ squashfs_img = os.path.join(target_mnt, place,
+ 'filesystem.squashfs')
+ if os.path.exists(squashfs_img):
+ # Mount the squashfs so we are possible to install
+ # syslinux & mbr.bin from it.
+ squashfs_mnt = self.MountISO(squashfs_img)
+ break
+ syslinux_exe = ''
+ syslinux_bin = ''
+ for prefix in [ squashfs_mnt, os.path.sep ]:
+ if not prefix:
+ continue
+ for syslinux_var in [ 'syslinux-legacy', 'syslinux' ]:
+ if syslinux_var == 'syslinux-legacy' and not syslinux_legacy:
+ continue
+ syslinux_exe = os.path.join(os.path.sep,
+ 'usr', 'bin', syslinux_var)
+ if not os.path.exists(os.path.join(prefix, syslinux_exe)):
+ continue
+ for mbrbin in [
+ os.path.join(prefix, 'usr', 'lib',
+ syslinux_var, 'mbr.bin'),
+ os.path.join(prefix, 'usr', 'lib',
+ syslinux_var, 'mbr', 'mbr.bin'),
+ os.path.join(prefix, 'usr', 'lib',
+ syslinux_var.upper(), 'mbr.bin'),
+ ]:
+ if os.path.exists(mbrbin):
+ syslinux_bin = mbrbin
+ break
+ if syslinux_bin:
+ break
+ if syslinux_bin:
+ if squashfs_mnt and prefix == squashfs_mnt:
+ overlay = self.mount_overlay(squashfs_mnt)
+ if not overlay:
+ continue
+ popen(['mount', '-n', '-o', 'bind', '/proc/',
+ os.path.join(overlay, 'proc')])
+ popen(['mount', '-n', '-o', 'bind', '/dev/',
+ os.path.join(overlay, 'dev')])
+ try:
+ popen(['chroot', overlay,
+ syslinux_exe, '-f', device])
+ except:
+ syslinux_bin = ''
+ continue
+ finally:
+ popen(['umount', os.path.join(overlay, 'dev')])
+ popen(['umount', os.path.join(overlay, 'proc')])
+ self.UnmountFile(overlay)
+ else:
+ popen([syslinux_exe, '-f', device])
+ break
+ if not syslinux_bin:
+ # syslinux not found
+ raise dbus.DBusException('com.ubuntu.USBCreator.Error.SystemInternal')
# Write the syslinux MBR.
popen(['dd', 'if=%s' % syslinux_bin, 'of=%s' % parent_file,
'bs=446', 'count=1', 'conv=sync'])
@@ -345,6 +372,32 @@
logging.debug('Shutting down.')
loop.quit()
+ def mount_overlay(self, directory):
+ import tempfile
+ ret = tempfile.mkdtemp()
+ delta = tempfile.mkdtemp()
+ work = tempfile.mkdtemp()
+ try:
+ popen(['mount', '-t', 'overlay', 'overlay', '-o',
+ 'lowerdir=%s,upperdir=%s,workdir=%s' % (directory, delta, work),
+ ret])
+ return ret
+ except:
+ pass
+ try:
+ popen(['mount', '-t', 'aufs', 'none', '-o',
+ 'br=%s:%s' % (delta, directory), ret])
+ return ret
+ except:
+ pass
+ try:
+ popen(['mount', '-t', 'overlayfs', 'overlayfs', '-o',
+ 'lowerdir=%s,upperdir=%s' % (directory, delta), ret])
+ return ret
+ except:
+ pass
+ return None
+
# Taken from Jockey 0.5.3.
def check_polkit(self, sender, conn, priv):
if sender is None and conn is None:
Follow ups