Merge lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot into lp:usb-creator

Proposed by Yu Ning
Status: Needs review
Proposed branch: lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot
Merge into: lp:usb-creator
Diff against target: 132 lines (+80/-31)
1 file modified
bin/usb-creator-helper (+80/-31)
To merge this branch: bzr merge lp:~yuningdodo/usb-creator/usb-creator.lp1325801v4-exec-syslinux-in-chroot
Reviewer Review Type Date Requested Status
usb-creator hackers Pending
Review via email: mp+258346@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Yu Ning (yuningdodo) wrote :
473. By Yu Ning

* attempt overlay methods with a loop.

Unmerged revisions

473. By Yu Ning

* attempt overlay methods with a loop.

472. By Yu Ning

* Install syslinux in a chroot environment so we can also burn an i386 ISO on an amd64 host. (LP: #1325801)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/usb-creator-helper'
--- bin/usb-creator-helper 2015-04-23 15:19:07 +0000
+++ bin/usb-creator-helper 2015-05-08 05:58:21 +0000
@@ -191,41 +191,68 @@
191 popen(['dd', 'if=%s' % os.path.join(grub_location, 'core.img'), 'of=%s' % parent_file,191 popen(['dd', 'if=%s' % os.path.join(grub_location, 'core.img'), 'of=%s' % parent_file,
192 'bs=512', 'count=62', 'seek=1', 'conv=sync'])192 'bs=512', 'count=62', 'seek=1', 'conv=sync'])
193 else:193 else:
194 if syslinux_legacy and find_on_path('syslinux-legacy'):
195 syslinux_var = "syslinux-legacy"
196 syslinux_exe = "syslinux-legacy"
197 syslinux_bin = "/usr/lib/syslinux-legacy/mbr.bin"
198 else:
199 syslinux_var = "syslinux"
200 syslinux_exe = "syslinux"
201 syslinux_bin = "/usr/lib/syslinux/mbr/mbr.bin"
202 if not os.path.exists(syslinux_bin):
203 syslinux_bin = "/usr/lib/syslinux/mbr.bin"
204 squashfs_mnt = ''194 squashfs_mnt = ''
205 target_mounts = obj.get_filesystem().get_cached_property('MountPoints').get_bytestring_array()195 target_mounts = obj.get_filesystem().get_cached_property('MountPoints').get_bytestring_array()
206 if len(target_mounts) > 0:196 if len(target_mounts) > 0:
207 target_mnt = target_mounts[0]197 target_mnt = target_mounts[0]
208 squashfs_img = os.path.join(target_mnt, 'casper',198 for place in [ 'install', 'casper', 'live' ]:
209 'filesystem.squashfs')199 squashfs_img = os.path.join(target_mnt, place,
210 if os.path.exists(squashfs_img):200 'filesystem.squashfs')
211 # Mount the squashfs so we are possible to install201 if os.path.exists(squashfs_img):
212 # syslinux & mbr.bin from it.202 # Mount the squashfs so we are possible to install
213 squashfs_mnt = self.MountISO(squashfs_img)203 # syslinux & mbr.bin from it.
214 if squashfs_mnt:204 squashfs_mnt = self.MountISO(squashfs_img)
215 for mbrbin in [205 break
216 os.path.join(squashfs_mnt, 'usr', 'lib',206 syslinux_exe = ''
217 syslinux_var, 'mbr.bin'),207 syslinux_bin = ''
218 os.path.join(squashfs_mnt, 'usr', 'lib',208 for prefix in [ squashfs_mnt, os.path.sep ]:
219 syslinux_var, 'mbr', 'mbr.bin'),209 if not prefix:
220 os.path.join(squashfs_mnt, 'usr', 'lib',210 continue
221 syslinux_var.upper(), 'mbr.bin'),211 for syslinux_var in [ 'syslinux-legacy', 'syslinux' ]:
222 ]:212 if syslinux_var == 'syslinux-legacy' and not syslinux_legacy:
223 if os.path.exists(mbrbin):213 continue
224 syslinux_exe = os.path.join(squashfs_mnt, 'usr',214 syslinux_exe = os.path.join(os.path.sep,
225 'bin', syslinux_var)215 'usr', 'bin', syslinux_var)
226 syslinux_bin = mbrbin216 if not os.path.exists(os.path.join(prefix, syslinux_exe)):
227 break217 continue
228 popen([syslinux_exe, '-f', device])218 for mbrbin in [
219 os.path.join(prefix, 'usr', 'lib',
220 syslinux_var, 'mbr.bin'),
221 os.path.join(prefix, 'usr', 'lib',
222 syslinux_var, 'mbr', 'mbr.bin'),
223 os.path.join(prefix, 'usr', 'lib',
224 syslinux_var.upper(), 'mbr.bin'),
225 ]:
226 if os.path.exists(mbrbin):
227 syslinux_bin = mbrbin
228 break
229 if syslinux_bin:
230 break
231 if syslinux_bin:
232 if squashfs_mnt and prefix == squashfs_mnt:
233 overlay = self.mount_overlay(squashfs_mnt)
234 if not overlay:
235 continue
236 popen(['mount', '-n', '-o', 'bind', '/proc/',
237 os.path.join(overlay, 'proc')])
238 popen(['mount', '-n', '-o', 'bind', '/dev/',
239 os.path.join(overlay, 'dev')])
240 try:
241 popen(['chroot', overlay,
242 syslinux_exe, '-f', device])
243 except:
244 syslinux_bin = ''
245 continue
246 finally:
247 popen(['umount', os.path.join(overlay, 'dev')])
248 popen(['umount', os.path.join(overlay, 'proc')])
249 self.UnmountFile(overlay)
250 else:
251 popen([syslinux_exe, '-f', device])
252 break
253 if not syslinux_bin:
254 # syslinux not found
255 raise dbus.DBusException('com.ubuntu.USBCreator.Error.SystemInternal')
229 # Write the syslinux MBR.256 # Write the syslinux MBR.
230 popen(['dd', 'if=%s' % syslinux_bin, 'of=%s' % parent_file,257 popen(['dd', 'if=%s' % syslinux_bin, 'of=%s' % parent_file,
231 'bs=446', 'count=1', 'conv=sync'])258 'bs=446', 'count=1', 'conv=sync'])
@@ -345,6 +372,28 @@
345 logging.debug('Shutting down.')372 logging.debug('Shutting down.')
346 loop.quit()373 loop.quit()
347374
375 def mount_overlay(self, directory):
376 import tempfile
377 ret = tempfile.mkdtemp()
378 delta = tempfile.mkdtemp()
379 work = tempfile.mkdtemp()
380 methods = [
381 [ 'mount', '-t', 'overlay', 'overlay', '-o',
382 'lowerdir=%s,upperdir=%s,workdir=%s' % (directory, delta, work),
383 ret ],
384 [ 'mount', '-t', 'aufs', 'none', '-o',
385 'br=%s:%s' % (delta, directory), ret ],
386 [ 'mount', '-t', 'overlayfs', 'overlayfs', '-o',
387 'lowerdir=%s,upperdir=%s' % (directory, delta), ret ],
388 ]
389 for method in methods:
390 try:
391 popen(method)
392 return ret
393 except:
394 pass
395 return None
396
348 # Taken from Jockey 0.5.3.397 # Taken from Jockey 0.5.3.
349 def check_polkit(self, sender, conn, priv):398 def check_polkit(self, sender, conn, priv):
350 if sender is None and conn is None:399 if sender is None and conn is None:

Subscribers

People subscribed via source and target branches

to all changes: