17 usage
= 'usage: mkbiarch.py <x86 Live ISO File> <x64 Live ISO File> <Target Multi Arch Image File>'
18 print >> sys
.stdout
, usage
21 def mount(src
, dst
, options
=None):
22 if os
.path
.exists(src
):
23 if not os
.path
.exists(dst
):
26 args
= ("/bin/mount", src
, dst
)
28 args
= ("/bin/mount", options
, src
, dst
)
29 rc
= subprocess
.call(args
)
35 if os
.path
.exists(src
):
36 args
= ("/bin/umount", src
)
37 rc
= subprocess
.call(args
)
43 if os
.path
.exists(src
):
44 if not os
.path
.exists(dst
):
45 if not os
.path
.isfile(src
):
51 if os
.path
.exists(src
):
56 tmp
= tempfile
.mkdtemp()
59 args
= ("/bin/mkdir", "-p", dir)
60 rc
= subprocess
.call(args
)
63 def losetup(src
, dst
, offset
=None):
64 if os
.path
.exists(src
):
65 if os
.path
.exists(dst
):
67 args
= ("/sbin/losetup", src
, dst
)
69 args
= ("/sbin/losetup", "-o", str(offset
), src
, dst
)
70 rc
= subprocess
.call(args
)
74 args
= ("/sbin/losetup", "-d", device
)
75 rc
= subprocess
.call(args
)
78 fd
= open(os
.devnull
, 'w')
82 args
= ("/bin/dd", "if=%s"%file
, "of=%s"%target
)
83 rc
= subprocess
.call(args
)
86 args
= ("/sbin/losetup", "--find")
87 rc
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
).communicate()[0].rstrip()
91 args
= ("/sbin/losetup", "-j", file)
92 rc
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
).communicate()[0].split(":")
96 def mkimage(bs
, count
):
97 tmp
= tempfile
.mkstemp()
99 args
= ("/bin/dd", "if=/dev/zero",
100 "of=%s"%image
, "bs=%s"%bs
,
102 rc
= subprocess
.call(args
)
107 if os
.path
.exists(ent
):
108 return os
.stat(ent
).st_size
113 def partition(device
):
114 dev
= parted
.Device(path
=device
)
115 disk
= parted
.freshDisk(dev
, 'msdos')
116 constraint
= parted
.Constraint(device
=dev
)
118 new_geom
= parted
.Geometry(device
=dev
,
120 end
=(constraint
.maxSize
- 1))
121 filesystem
= parted
.FileSystem(type="ext2",
123 partition
= parted
.Partition(disk
=disk
,
125 type=parted
.PARTITION_NORMAL
,
127 constraint
= parted
.Constraint(exactGeom
=new_geom
)
128 partition
.setFlag(parted
.PARTITION_BOOT
)
129 disk
.addPartition(partition
=partition
,
130 constraint
=constraint
)
134 def format(partition
):
135 args
= ("/sbin/mke2fs", "-j", partition
)
136 rc
= subprocess
.call(args
)
139 mbr
= "/usr/share/syslinux/mbr.bin"
143 args
= ("/sbin/blkid", "-s", "UUID", "-o", "value", device
)
144 rc
= subprocess
.Popen(args
, stdout
=subprocess
.PIPE
).communicate()[0].rstrip()
147 def syslinux(multitmp
, config
, **args
):
148 arg
= ("/sbin/extlinux", "--install", multitmp
+ "/extlinux/")
149 rc
= subprocess
.call(arg
)
155 menu background splash.jpg
156 menu title Welcome to Fedora 13
157 menu color border 0 #ffffffff #00000000
158 menu color sel 7 #ffffffff #ff000000
159 menu color title 0 #ffffffff #00000000
160 menu color tabmsg 0 #ffffffff #00000000
161 menu color unsel 0 #ffffffff #00000000
162 menu color hotsel 0 #ff000000 #ffffffff
163 menu color hotkey 7 #ffffffff #ff000000
164 menu color timeout_msg 0 #ffffffff #00000000
165 menu color timeout 0 #ffffffff #00000000
166 menu color cmdline 0 #ffffffff #00000000
171 menu label Fedora-13-x86
173 append initrd=initrd0.img root=UUID=%(uuid)s rootfstype=auto ro live_dir=/x86/LiveOS liveimg
176 menu label Fedora-13-x64
178 append initrd=initrd1.img root=UUID=%(uuid)s rootfstype=auto ro live_dir=/x64/LiveOS liveimg
180 fd
= open(config
, 'w')
185 # use md5 module to verify image files
188 def setup(x86
, x64
, multi
):
190 sz
= size(x86
) + size(x64
)
194 count
= count
+ 102400
196 multi
= mkimage(blsz
, count
)
200 partition(lodev(multi
))
202 lounset(lodev(multi
))
204 losetup(lo(), multi
, offset
=512)
208 mount(lodev(multi
), multitmp
)
216 mount(lodev(x86
), x86tmp
)
217 mount(lodev(x64
), x64tmp
)
220 dirs
= ("/extlinux/", "/x86/", "/x64/")
222 mkdir(multitmp
+ dir)
223 dirs
= ("/x86/", "/x64/")
225 mkdir(multitmp
+ dir + "/LiveOS/")
227 intermediate
= tempfile
.mkdtemp() # loopdev performance is slow
228 # copy to here first then back
229 # to multitmp + dir which is looback also
231 imgs
= ("squashfs.img", "osmin.img")
233 copy(x86tmp
+ "/LiveOS/" + img
, intermediate
)
234 copy(intermediate
+ "/" + img
, multitmp
+ "/x86/LiveOS/")
236 copy(x64tmp
+ "/LiveOS/" + img
, intermediate
)
237 copy(intermediate
+ "/" + img
, multitmp
+ "/x64/LiveOS/")
239 for file in os
.listdir(x86tmp
+ "/isolinux/"):
240 copy(x86tmp
+ "/isolinux/" + file, multitmp
+ "/extlinux/")
242 copy(x64tmp
+ "/isolinux/vmlinuz0", multitmp
+ "/extlinux/vmlinuz1")
243 copy(x64tmp
+ "/isolinux/initrd0.img", multitmp
+ "/extlinux/initrd1.img")
247 uuid
= getuuid(lodev(multi
))
250 config
= (multitmp
+ "/extlinux/extlinux.conf")
263 lounset(lodev(multi
))
265 shutil
.rmtree(x86tmp
)
266 shutil
.rmtree(x64tmp
)
267 shutil
.rmtree(multitmp
)
268 shutil
.rmtree(intermediate
)
272 if os
.path
.exists(sys
.argv
[3]):
273 os
.unlink(sys
.argv
[3])
274 move(multi
, sys
.argv
[3])
277 def parse(x86
, x64
, multi
):
278 for file in x86
, x64
:
279 if os
.path
.exists(file):
285 setup(x86
, x64
, multi
)
292 parse(sys
.argv
[1], sys
.argv
[2], sys
.argv
[3])
302 if __name__
== "__main__":