blob: bc9928314ce50c12e0b8577d15071cfd9d991b76 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as
6# published by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# DESCRIPTION
18# This implements the 'isoimage-isohybrid' source plugin class for 'wic'
19#
20# AUTHORS
21# Mihaly Varga <mihaly.varga (at] ni.com>
22
23import os
24import re
25import shutil
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026import glob
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050028from wic import msger
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029from wic.pluginbase import SourcePlugin
30from wic.utils.oe.misc import exec_cmd, exec_native_cmd, get_bitbake_var
31
32class IsoImagePlugin(SourcePlugin):
33 """
34 Create a bootable ISO image
35
36 This plugin creates a hybrid, legacy and EFI bootable ISO image. The
37 generated image can be used on optical media as well as USB media.
38
39 Legacy boot uses syslinux and EFI boot uses grub or gummiboot (not
40 implemented yet) as bootloader. The plugin creates the directories required
41 by bootloaders and populates them by creating and configuring the
42 bootloader files.
43
44 Example kickstart file:
45 part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi, \\
46 image_name= IsoImage" --ondisk cd --label LIVECD --fstype=ext2
47 bootloader --timeout=10 --append=" "
48
49 In --sourceparams "loader" specifies the bootloader used for booting in EFI
50 mode, while "image_name" specifies the name of the generated image. In the
51 example above, wic creates an ISO image named IsoImage-cd.direct (default
52 extension added by direct imeger plugin) and a file named IsoImage-cd.iso
53 """
54
55 name = 'isoimage-isohybrid'
56
57 @classmethod
58 def do_configure_syslinux(cls, creator, cr_workdir):
59 """
60 Create loader-specific (syslinux) config
61 """
62 splash = os.path.join(cr_workdir, "/ISO/boot/splash.jpg")
63 if os.path.exists(splash):
64 splashline = "menu background splash.jpg"
65 else:
66 splashline = ""
67
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
70 syslinux_conf = ""
71 syslinux_conf += "PROMPT 0\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050072 syslinux_conf += "TIMEOUT %s \n" % (bootloader.timeout or 10)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 syslinux_conf += "\n"
74 syslinux_conf += "ALLOWOPTIONS 1\n"
75 syslinux_conf += "SERIAL 0 115200\n"
76 syslinux_conf += "\n"
77 if splashline:
78 syslinux_conf += "%s\n" % splashline
79 syslinux_conf += "DEFAULT boot\n"
80 syslinux_conf += "LABEL boot\n"
81
82 kernel = "/bzImage"
83 syslinux_conf += "KERNEL " + kernel + "\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050084 syslinux_conf += "APPEND initrd=/initrd LABEL=boot %s\n" \
85 % bootloader.append
Patrick Williamsc124f4f2015-09-15 14:41:29 -050086
87 msger.debug("Writing syslinux config %s/ISO/isolinux/isolinux.cfg" \
88 % cr_workdir)
89 with open("%s/ISO/isolinux/isolinux.cfg" % cr_workdir, "w") as cfg:
90 cfg.write(syslinux_conf)
91
92 @classmethod
93 def do_configure_grubefi(cls, part, creator, cr_workdir):
94 """
95 Create loader-specific (grub-efi) config
96 """
97 splash = os.path.join(cr_workdir, "/EFI/boot/splash.jpg")
98 if os.path.exists(splash):
99 splashline = "menu background splash.jpg"
100 else:
101 splashline = ""
102
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103 bootloader = creator.ks.bootloader
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104
105 grubefi_conf = ""
106 grubefi_conf += "serial --unit=0 --speed=115200 --word=8 "
107 grubefi_conf += "--parity=no --stop=1\n"
108 grubefi_conf += "default=boot\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500109 grubefi_conf += "timeout=%s\n" % (bootloader.timeout or 10)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 grubefi_conf += "\n"
111 grubefi_conf += "search --set=root --label %s " % part.label
112 grubefi_conf += "\n"
113 grubefi_conf += "menuentry 'boot'{\n"
114
115 kernel = "/bzImage"
116
117 grubefi_conf += "linux %s rootwait %s\n" \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500118 % (kernel, bootloader.append)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 grubefi_conf += "initrd /initrd \n"
120 grubefi_conf += "}\n"
121
122 if splashline:
123 grubefi_conf += "%s\n" % splashline
124
125 msger.debug("Writing grubefi config %s/EFI/BOOT/grub.cfg" \
126 % cr_workdir)
127 with open("%s/EFI/BOOT/grub.cfg" % cr_workdir, "w") as cfg:
128 cfg.write(grubefi_conf)
129
130 @staticmethod
131 def _build_initramfs_path(rootfs_dir, cr_workdir):
132 """
133 Create path for initramfs image
134 """
135
136 initrd = get_bitbake_var("INITRD")
137 if not initrd:
138 initrd_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
139 if not initrd_dir:
140 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting.\n")
141
142 image_name = get_bitbake_var("IMAGE_BASENAME")
143 if not image_name:
144 msger.error("Couldn't find IMAGE_BASENAME, exiting.\n")
145
146 image_type = get_bitbake_var("INITRAMFS_FSTYPES")
147 if not image_type:
148 msger.error("Couldn't find INITRAMFS_FSTYPES, exiting.\n")
149
150 machine_arch = get_bitbake_var("MACHINE_ARCH")
151 if not machine_arch:
152 msger.error("Couldn't find MACHINE_ARCH, exiting.\n")
153
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500154 initrd = glob.glob('%s/%s*%s.%s' % (initrd_dir, image_name, machine_arch, image_type))[0]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155
156 if not os.path.exists(initrd):
157 # Create initrd from rootfs directory
158 initrd = "%s/initrd.cpio.gz" % cr_workdir
159 initrd_dir = "%s/INITRD" % cr_workdir
160 shutil.copytree("%s" % rootfs_dir, \
161 "%s" % initrd_dir, symlinks=True)
162
163 if os.path.isfile("%s/init" % rootfs_dir):
164 shutil.copy2("%s/init" % rootfs_dir, "%s/init" % initrd_dir)
165 elif os.path.lexists("%s/init" % rootfs_dir):
166 os.symlink(os.readlink("%s/init" % rootfs_dir), \
167 "%s/init" % initrd_dir)
168 elif os.path.isfile("%s/sbin/init" % rootfs_dir):
169 shutil.copy2("%s/sbin/init" % rootfs_dir, \
170 "%s" % initrd_dir)
171 elif os.path.lexists("%s/sbin/init" % rootfs_dir):
172 os.symlink(os.readlink("%s/sbin/init" % rootfs_dir), \
173 "%s/init" % initrd_dir)
174 else:
175 msger.error("Couldn't find or build initrd, exiting.\n")
176
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500177 exec_cmd("cd %s && find . | cpio -o -H newc -R +0:+0 >./initrd.cpio " \
178 % initrd_dir, as_shell=True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500179 exec_cmd("gzip -f -9 -c %s/initrd.cpio > %s" \
180 % (cr_workdir, initrd), as_shell=True)
181 shutil.rmtree(initrd_dir)
182
183 return initrd
184
185 @classmethod
186 def do_stage_partition(cls, part, source_params, creator, cr_workdir,
187 oe_builddir, bootimg_dir, kernel_dir,
188 native_sysroot):
189 """
190 Special content staging called before do_prepare_partition().
191 It cheks if all necessary tools are available, if not
192 tries to instal them.
193 """
194 # Make sure parted is available in native sysroot
195 if not os.path.isfile("%s/usr/sbin/parted" % native_sysroot):
196 msger.info("Building parted-native...\n")
197 exec_cmd("bitbake parted-native")
198
199 # Make sure mkfs.ext2/3/4 is available in native sysroot
200 if not os.path.isfile("%s/sbin/mkfs.ext2" % native_sysroot):
201 msger.info("Building e2fsprogs-native...\n")
202 exec_cmd("bitbake e2fsprogs-native")
203
204 # Make sure syslinux is available in sysroot and in native sysroot
205 syslinux_dir = get_bitbake_var("STAGING_DATADIR")
206 if not syslinux_dir:
207 msger.error("Couldn't find STAGING_DATADIR, exiting.\n")
208 if not os.path.exists("%s/syslinux" % syslinux_dir):
209 msger.info("Building syslinux...\n")
210 exec_cmd("bitbake syslinux")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211 if not os.path.exists("%s/syslinux" % syslinux_dir):
212 msger.error("Please build syslinux first\n")
213
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500214 # Make sure syslinux is available in native sysroot
215 if not os.path.exists("%s/usr/bin/syslinux" % native_sysroot):
216 msger.info("Building syslinux-native...\n")
217 exec_cmd("bitbake syslinux-native")
218
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219 #Make sure mkisofs is available in native sysroot
220 if not os.path.isfile("%s/usr/bin/mkisofs" % native_sysroot):
221 msger.info("Building cdrtools-native...\n")
222 exec_cmd("bitbake cdrtools-native")
223
224 # Make sure mkfs.vfat is available in native sysroot
225 if not os.path.isfile("%s/sbin/mkfs.vfat" % native_sysroot):
226 msger.info("Building dosfstools-native...\n")
227 exec_cmd("bitbake dosfstools-native")
228
229 # Make sure mtools is available in native sysroot
230 if not os.path.isfile("%s/usr/bin/mcopy" % native_sysroot):
231 msger.info("Building mtools-native...\n")
232 exec_cmd("bitbake mtools-native")
233
234 @classmethod
235 def do_configure_partition(cls, part, source_params, creator, cr_workdir,
236 oe_builddir, bootimg_dir, kernel_dir,
237 native_sysroot):
238 """
239 Called before do_prepare_partition(), creates loader-specific config
240 """
241 isodir = "%s/ISO/" % cr_workdir
242
243 if os.path.exists(cr_workdir):
244 shutil.rmtree(cr_workdir)
245
246 install_cmd = "install -d %s " % isodir
247 exec_cmd(install_cmd)
248
249 # Overwrite the name of the created image
250 msger.debug("%s" % source_params)
251 if 'image_name' in source_params and \
252 source_params['image_name'].strip():
253 creator.name = source_params['image_name'].strip()
254 msger.debug("The name of the image is: %s" % creator.name)
255
256 @classmethod
257 def do_prepare_partition(cls, part, source_params, creator, cr_workdir,
258 oe_builddir, bootimg_dir, kernel_dir,
259 rootfs_dir, native_sysroot):
260 """
261 Called to do the actual content population for a partition i.e. it
262 'prepares' the partition to be incorporated into the image.
263 In this case, prepare content for a bootable ISO image.
264 """
265
266 isodir = "%s/ISO" % cr_workdir
267
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500268 if part.rootfs_dir is None:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269 if not 'ROOTFS_DIR' in rootfs_dir:
270 msger.error("Couldn't find --rootfs-dir, exiting.\n")
271 rootfs_dir = rootfs_dir['ROOTFS_DIR']
272 else:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500273 if part.rootfs_dir in rootfs_dir:
274 rootfs_dir = rootfs_dir[part.rootfs_dir]
275 elif part.rootfs_dir:
276 rootfs_dir = part.rootfs_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500277 else:
278 msg = "Couldn't find --rootfs-dir=%s connection "
279 msg += "or it is not a valid path, exiting.\n"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500280 msger.error(msg % part.rootfs_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500281
282 if not os.path.isdir(rootfs_dir):
283 rootfs_dir = get_bitbake_var("IMAGE_ROOTFS")
284 if not os.path.isdir(rootfs_dir):
285 msger.error("Couldn't find IMAGE_ROOTFS, exiting.\n")
286
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500287 part.rootfs_dir = rootfs_dir
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288
289 # Prepare rootfs.img
290 hdd_dir = get_bitbake_var("HDDDIR")
291 img_iso_dir = get_bitbake_var("ISODIR")
292
293 rootfs_img = "%s/rootfs.img" % hdd_dir
294 if not os.path.isfile(rootfs_img):
295 rootfs_img = "%s/rootfs.img" % img_iso_dir
296 if not os.path.isfile(rootfs_img):
297 # check if rootfs.img is in deploydir
298 deploy_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
299 image_name = get_bitbake_var("IMAGE_LINK_NAME")
300 rootfs_img = "%s/%s.%s" \
301 % (deploy_dir, image_name, part.fstype)
302
303 if not os.path.isfile(rootfs_img):
304 # create image file with type specified by --fstype
305 # which contains rootfs
306 du_cmd = "du -bks %s" % rootfs_dir
307 out = exec_cmd(du_cmd)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500308 part.size = int(out.split()[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 part.extra_space = 0
310 part.overhead_factor = 1.2
311 part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, \
312 native_sysroot)
313 rootfs_img = part.source_file
314
315 install_cmd = "install -m 0644 %s %s/rootfs.img" \
316 % (rootfs_img, isodir)
317 exec_cmd(install_cmd)
318
319 # Remove the temporary file created by part.prepare_rootfs()
320 if os.path.isfile(part.source_file):
321 os.remove(part.source_file)
322
323 # Prepare initial ramdisk
324 initrd = "%s/initrd" % hdd_dir
325 if not os.path.isfile(initrd):
326 initrd = "%s/initrd" % img_iso_dir
327 if not os.path.isfile(initrd):
328 initrd = cls._build_initramfs_path(rootfs_dir, cr_workdir)
329
330 install_cmd = "install -m 0644 %s %s/initrd" \
331 % (initrd, isodir)
332 exec_cmd(install_cmd)
333
334 # Remove the temporary file created by _build_initramfs_path function
335 if os.path.isfile("%s/initrd.cpio.gz" % cr_workdir):
336 os.remove("%s/initrd.cpio.gz" % cr_workdir)
337
338 # Install bzImage
339 install_cmd = "install -m 0644 %s/bzImage %s/bzImage" % \
340 (kernel_dir, isodir)
341 exec_cmd(install_cmd)
342
343 #Create bootloader for efi boot
344 try:
345 if source_params['loader'] == 'grub-efi':
346 # Builds grub.cfg if ISODIR didn't exist or
347 # didn't contains grub.cfg
348 bootimg_dir = img_iso_dir
349 if not os.path.exists("%s/EFI/BOOT" % bootimg_dir):
350 bootimg_dir = "%s/bootimg" % cr_workdir
351 if os.path.exists(bootimg_dir):
352 shutil.rmtree(bootimg_dir)
353 install_cmd = "install -d %s/EFI/BOOT" % bootimg_dir
354 exec_cmd(install_cmd)
355
356 if not os.path.isfile("%s/EFI/BOOT/boot.cfg" % bootimg_dir):
357 cls.do_configure_grubefi(part, creator, bootimg_dir)
358
359 # Builds bootx64.efi/bootia32.efi if ISODIR didn't exist or
360 # didn't contains it
361 target_arch = get_bitbake_var("TARGET_SYS")
362 if not target_arch:
363 msger.error("Coludn't find target architecture\n")
364
365 if re.match("x86_64", target_arch):
366 grub_target = 'x86_64-efi'
367 grub_image = "bootx64.efi"
368 elif re.match('i.86', target_arch):
369 grub_target = 'i386-efi'
370 grub_image = "bootia32.efi"
371 else:
372 msger.error("grub-efi is incompatible with target %s\n" \
373 % target_arch)
374
375 if not os.path.isfile("%s/EFI/BOOT/%s" \
376 % (bootimg_dir, grub_image)):
377 grub_path = get_bitbake_var("STAGING_LIBDIR")
378 if not grub_path:
379 msger.error("Couldn't find STAGING_LIBDIR, exiting.\n")
380
381 grub_core = "%s/grub/%s" % (grub_path, grub_target)
382 if not os.path.exists(grub_core):
383 msger.info("Building grub-efi...\n")
384 exec_cmd("bitbake grub-efi")
385 if not os.path.exists(grub_core):
386 msger.error("Please build grub-efi first\n")
387
388 grub_cmd = "grub-mkimage -p '/EFI/BOOT' "
389 grub_cmd += "-d %s " % grub_core
390 grub_cmd += "-O %s -o %s/EFI/BOOT/%s " \
391 % (grub_target, bootimg_dir, grub_image)
392 grub_cmd += "part_gpt part_msdos ntfs ntfscomp fat ext2 "
393 grub_cmd += "normal chain boot configfile linux multiboot "
394 grub_cmd += "search efi_gop efi_uga font gfxterm gfxmenu "
395 grub_cmd += "terminal minicmd test iorw loadenv echo help "
396 grub_cmd += "reboot serial terminfo iso9660 loopback tar "
397 grub_cmd += "memdisk ls search_fs_uuid udf btrfs xfs lvm "
398 grub_cmd += "reiserfs ata "
399 exec_native_cmd(grub_cmd, native_sysroot)
400
401 else:
402 # TODO: insert gummiboot stuff
403 msger.error("unrecognized bootimg-efi loader: %s" \
404 % source_params['loader'])
405 except KeyError:
406 msger.error("bootimg-efi requires a loader, none specified")
407
408 if os.path.exists("%s/EFI/BOOT" % isodir):
409 shutil.rmtree("%s/EFI/BOOT" % isodir)
410
411 shutil.copytree(bootimg_dir+"/EFI/BOOT", isodir+"/EFI/BOOT")
412
413 # If exists, remove cr_workdir/bootimg temporary folder
414 if os.path.exists("%s/bootimg" % cr_workdir):
415 shutil.rmtree("%s/bootimg" % cr_workdir)
416
417 # Create efi.img that contains bootloader files for EFI booting
418 # if ISODIR didn't exist or didn't contains it
419 if os.path.isfile("%s/efi.img" % img_iso_dir):
420 install_cmd = "install -m 0644 %s/efi.img %s/efi.img" % \
421 (img_iso_dir, isodir)
422 exec_cmd(install_cmd)
423 else:
424 du_cmd = "du -bks %s/EFI" % isodir
425 out = exec_cmd(du_cmd)
426 blocks = int(out.split()[0])
427 # Add some extra space for file system overhead
428 blocks += 100
429 msg = "Added 100 extra blocks to %s to get to %d total blocks" \
430 % (part.mountpoint, blocks)
431 msger.debug(msg)
432
433 # Ensure total sectors is an integral number of sectors per
434 # track or mcopy will complain. Sectors are 512 bytes, and we
435 # generate images with 32 sectors per track. This calculation is
436 # done in blocks, thus the mod by 16 instead of 32.
437 blocks += (16 - (blocks % 16))
438
439 # dosfs image for EFI boot
440 bootimg = "%s/efi.img" % isodir
441
442 dosfs_cmd = 'mkfs.vfat -n "EFIimg" -S 512 -C %s %d' \
443 % (bootimg, blocks)
444 exec_native_cmd(dosfs_cmd, native_sysroot)
445
446 mmd_cmd = "mmd -i %s ::/EFI" % bootimg
447 exec_native_cmd(mmd_cmd, native_sysroot)
448
449 mcopy_cmd = "mcopy -i %s -s %s/EFI/* ::/EFI/" \
450 % (bootimg, isodir)
451 exec_native_cmd(mcopy_cmd, native_sysroot)
452
453 chmod_cmd = "chmod 644 %s" % bootimg
454 exec_cmd(chmod_cmd)
455
456 # Prepare files for legacy boot
457 syslinux_dir = get_bitbake_var("STAGING_DATADIR")
458 if not syslinux_dir:
459 msger.error("Couldn't find STAGING_DATADIR, exiting.\n")
460
461 if os.path.exists("%s/isolinux" % isodir):
462 shutil.rmtree("%s/isolinux" % isodir)
463
464 install_cmd = "install -d %s/isolinux" % isodir
465 exec_cmd(install_cmd)
466
467 cls.do_configure_syslinux(creator, cr_workdir)
468
469 install_cmd = "install -m 444 %s/syslinux/ldlinux.sys " % syslinux_dir
470 install_cmd += "%s/isolinux/ldlinux.sys" % isodir
471 exec_cmd(install_cmd)
472
473 install_cmd = "install -m 444 %s/syslinux/isohdpfx.bin " % syslinux_dir
474 install_cmd += "%s/isolinux/isohdpfx.bin" % isodir
475 exec_cmd(install_cmd)
476
477 install_cmd = "install -m 644 %s/syslinux/isolinux.bin " % syslinux_dir
478 install_cmd += "%s/isolinux/isolinux.bin" % isodir
479 exec_cmd(install_cmd)
480
481 install_cmd = "install -m 644 %s/syslinux/ldlinux.c32 " % syslinux_dir
482 install_cmd += "%s/isolinux/ldlinux.c32" % isodir
483 exec_cmd(install_cmd)
484
485 #create ISO image
486 iso_img = "%s/tempiso_img.iso" % cr_workdir
487 iso_bootimg = "isolinux/isolinux.bin"
488 iso_bootcat = "isolinux/boot.cat"
489 efi_img = "efi.img"
490
491 mkisofs_cmd = "mkisofs -V %s " % part.label
492 mkisofs_cmd += "-o %s -U " % iso_img
493 mkisofs_cmd += "-J -joliet-long -r -iso-level 2 -b %s " % iso_bootimg
494 mkisofs_cmd += "-c %s -no-emul-boot -boot-load-size 4 " % iso_bootcat
495 mkisofs_cmd += "-boot-info-table -eltorito-alt-boot "
496 mkisofs_cmd += "-eltorito-platform 0xEF -eltorito-boot %s " % efi_img
497 mkisofs_cmd += "-no-emul-boot %s " % isodir
498
499 msger.debug("running command: %s" % mkisofs_cmd)
500 exec_native_cmd(mkisofs_cmd, native_sysroot)
501
502 shutil.rmtree(isodir)
503
504 du_cmd = "du -Lbks %s" % iso_img
505 out = exec_cmd(du_cmd)
506 isoimg_size = int(out.split()[0])
507
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500508 part.size = isoimg_size
509 part.source_file = iso_img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500510
511 @classmethod
512 def do_install_disk(cls, disk, disk_name, creator, workdir, oe_builddir,
513 bootimg_dir, kernel_dir, native_sysroot):
514 """
515 Called after all partitions have been prepared and assembled into a
516 disk image. In this case, we insert/modify the MBR using isohybrid
517 utility for booting via BIOS from disk storage devices.
518 """
519
520 full_path = creator._full_path(workdir, disk_name, "direct")
521 iso_img = "%s.p1" % full_path
522 full_path_iso = creator._full_path(workdir, disk_name, "iso")
523
524 isohybrid_cmd = "isohybrid -u %s" % iso_img
525 msger.debug("running command: %s" % \
526 isohybrid_cmd)
527 exec_native_cmd(isohybrid_cmd, native_sysroot)
528
529 # Replace the image created by direct plugin with the one created by
530 # mkisofs command. This is necessary because the iso image created by
531 # mkisofs has a very specific MBR is system area of the ISO image, and
532 # direct plugin adds and configures an another MBR.
533 msger.debug("Replaceing the image created by direct plugin\n")
534 os.remove(full_path)
535 shutil.copy2(iso_img, full_path_iso)
536 shutil.copy2(full_path_iso, full_path)
537
538 # Remove temporary ISO file
539 os.remove(iso_img)