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
1=== modified file 'bin/usb-creator-helper'
2--- bin/usb-creator-helper 2015-04-23 15:19:07 +0000
3+++ bin/usb-creator-helper 2015-05-08 05:58:21 +0000
4@@ -191,41 +191,68 @@
5 popen(['dd', 'if=%s' % os.path.join(grub_location, 'core.img'), 'of=%s' % parent_file,
6 'bs=512', 'count=62', 'seek=1', 'conv=sync'])
7 else:
8- if syslinux_legacy and find_on_path('syslinux-legacy'):
9- syslinux_var = "syslinux-legacy"
10- syslinux_exe = "syslinux-legacy"
11- syslinux_bin = "/usr/lib/syslinux-legacy/mbr.bin"
12- else:
13- syslinux_var = "syslinux"
14- syslinux_exe = "syslinux"
15- syslinux_bin = "/usr/lib/syslinux/mbr/mbr.bin"
16- if not os.path.exists(syslinux_bin):
17- syslinux_bin = "/usr/lib/syslinux/mbr.bin"
18 squashfs_mnt = ''
19 target_mounts = obj.get_filesystem().get_cached_property('MountPoints').get_bytestring_array()
20 if len(target_mounts) > 0:
21 target_mnt = target_mounts[0]
22- squashfs_img = os.path.join(target_mnt, 'casper',
23- 'filesystem.squashfs')
24- if os.path.exists(squashfs_img):
25- # Mount the squashfs so we are possible to install
26- # syslinux & mbr.bin from it.
27- squashfs_mnt = self.MountISO(squashfs_img)
28- if squashfs_mnt:
29- for mbrbin in [
30- os.path.join(squashfs_mnt, 'usr', 'lib',
31- syslinux_var, 'mbr.bin'),
32- os.path.join(squashfs_mnt, 'usr', 'lib',
33- syslinux_var, 'mbr', 'mbr.bin'),
34- os.path.join(squashfs_mnt, 'usr', 'lib',
35- syslinux_var.upper(), 'mbr.bin'),
36- ]:
37- if os.path.exists(mbrbin):
38- syslinux_exe = os.path.join(squashfs_mnt, 'usr',
39- 'bin', syslinux_var)
40- syslinux_bin = mbrbin
41- break
42- popen([syslinux_exe, '-f', device])
43+ for place in [ 'install', 'casper', 'live' ]:
44+ squashfs_img = os.path.join(target_mnt, place,
45+ 'filesystem.squashfs')
46+ if os.path.exists(squashfs_img):
47+ # Mount the squashfs so we are possible to install
48+ # syslinux & mbr.bin from it.
49+ squashfs_mnt = self.MountISO(squashfs_img)
50+ break
51+ syslinux_exe = ''
52+ syslinux_bin = ''
53+ for prefix in [ squashfs_mnt, os.path.sep ]:
54+ if not prefix:
55+ continue
56+ for syslinux_var in [ 'syslinux-legacy', 'syslinux' ]:
57+ if syslinux_var == 'syslinux-legacy' and not syslinux_legacy:
58+ continue
59+ syslinux_exe = os.path.join(os.path.sep,
60+ 'usr', 'bin', syslinux_var)
61+ if not os.path.exists(os.path.join(prefix, syslinux_exe)):
62+ continue
63+ for mbrbin in [
64+ os.path.join(prefix, 'usr', 'lib',
65+ syslinux_var, 'mbr.bin'),
66+ os.path.join(prefix, 'usr', 'lib',
67+ syslinux_var, 'mbr', 'mbr.bin'),
68+ os.path.join(prefix, 'usr', 'lib',
69+ syslinux_var.upper(), 'mbr.bin'),
70+ ]:
71+ if os.path.exists(mbrbin):
72+ syslinux_bin = mbrbin
73+ break
74+ if syslinux_bin:
75+ break
76+ if syslinux_bin:
77+ if squashfs_mnt and prefix == squashfs_mnt:
78+ overlay = self.mount_overlay(squashfs_mnt)
79+ if not overlay:
80+ continue
81+ popen(['mount', '-n', '-o', 'bind', '/proc/',
82+ os.path.join(overlay, 'proc')])
83+ popen(['mount', '-n', '-o', 'bind', '/dev/',
84+ os.path.join(overlay, 'dev')])
85+ try:
86+ popen(['chroot', overlay,
87+ syslinux_exe, '-f', device])
88+ except:
89+ syslinux_bin = ''
90+ continue
91+ finally:
92+ popen(['umount', os.path.join(overlay, 'dev')])
93+ popen(['umount', os.path.join(overlay, 'proc')])
94+ self.UnmountFile(overlay)
95+ else:
96+ popen([syslinux_exe, '-f', device])
97+ break
98+ if not syslinux_bin:
99+ # syslinux not found
100+ raise dbus.DBusException('com.ubuntu.USBCreator.Error.SystemInternal')
101 # Write the syslinux MBR.
102 popen(['dd', 'if=%s' % syslinux_bin, 'of=%s' % parent_file,
103 'bs=446', 'count=1', 'conv=sync'])
104@@ -345,6 +372,28 @@
105 logging.debug('Shutting down.')
106 loop.quit()
107
108+ def mount_overlay(self, directory):
109+ import tempfile
110+ ret = tempfile.mkdtemp()
111+ delta = tempfile.mkdtemp()
112+ work = tempfile.mkdtemp()
113+ methods = [
114+ [ 'mount', '-t', 'overlay', 'overlay', '-o',
115+ 'lowerdir=%s,upperdir=%s,workdir=%s' % (directory, delta, work),
116+ ret ],
117+ [ 'mount', '-t', 'aufs', 'none', '-o',
118+ 'br=%s:%s' % (delta, directory), ret ],
119+ [ 'mount', '-t', 'overlayfs', 'overlayfs', '-o',
120+ 'lowerdir=%s,upperdir=%s' % (directory, delta), ret ],
121+ ]
122+ for method in methods:
123+ try:
124+ popen(method)
125+ return ret
126+ except:
127+ pass
128+ return None
129+
130 # Taken from Jockey 0.5.3.
131 def check_polkit(self, sender, conn, priv):
132 if sender is None and conn is None:

Subscribers

People subscribed via source and target branches

to all changes: