From: jianzhong.fang Date: Tue, 8 Sep 2015 02:58:19 +0000 (+0800) Subject: Drop MIC liveusb image format support X-Git-Tag: accepted/tizen/5.5/unified/20191228.075036^2~90 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a63d31e2db43be3106788ed760f65379b98aeafc;p=platform%2Fupstream%2Fmic.git Drop MIC liveusb image format support Change-Id: I48e2f647b8278107bd4ce84c0c9c0237dec8b948 --- diff --git a/doc/man.rst b/doc/man.rst index fd75fd4..c3cdc61 100644 --- a/doc/man.rst +++ b/doc/man.rst @@ -32,7 +32,6 @@ Subcommands: | help(?) give detailed help on a specific sub-command | fs create fs image, which is also chroot directory | livecd create live CD image, used for CD booting - | liveusb create live USB image, used for USB booting | loop create loop image, including multi-partitions | raw create raw image, containing multi-partitions @@ -108,9 +107,7 @@ Options: Examples: - | mic convert tizen.iso liveusb | mic convert tizen.usbimg livecd - | mic cv --shell tizen.iso liveusb Advanced Usage ============== diff --git a/doc/usage.rst b/doc/usage.rst index dbd4c21..f13f0a9 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -44,7 +44,7 @@ Image formulation support * Including partition table and all the partitions * The image is bootable directly -- Livecd/liveusb +- Livecd * Mainly used for an ia32 build, it can be burned to CD or usbstick, which can be booted into a live system or installation UI @@ -70,7 +70,6 @@ Create help(?) give detailed help on a specific sub-command fs create fs image, which is also a chroot directory livecd create live CD image, used for CD booting - liveusb create live USB image, used for USB booting loop create loop image, including multi-partitions raw create raw image, containing multi-partitions @@ -182,9 +181,7 @@ This command is used for converting an image to another format. :: - mic cv tizen.iso liveusb mic cv tizen.usbimg livecd - mic cv --shell tizen.iso liveusb Getting Start ------------- diff --git a/mic/imager/liveusb.py b/mic/imager/liveusb.py deleted file mode 100644 index 64349ed..0000000 --- a/mic/imager/liveusb.py +++ /dev/null @@ -1,317 +0,0 @@ -#!/usr/bin/python -tt -# -# Copyright (c) 2011 Intel, Inc. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; version 2 of the License -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., 59 -# Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -import os -import shutil -import re - -from mic import msger -from mic.utils import misc, fs_related, runner -from mic.utils.errors import CreatorError, MountError -from mic.utils.partitionedfs import PartitionedMount -from mic.imager.livecd import LiveCDImageCreator -from mic.archive import packing - -class LiveUSBImageCreator(LiveCDImageCreator): - img_format = 'liveusb' - - def __init__(self, *args): - LiveCDImageCreator.__init__(self, *args) - - self._dep_checks.extend(["kpartx", "parted"]) - - # remove dependency of genisoimage in parent class - if "genisoimage" in self._dep_checks: - self._dep_checks.remove("genisoimage") - - def _create_usbimg(self, isodir): - overlaysizemb = 64 #default - #skipcompress = self.skip_compression? - fstype = "vfat" - homesizemb=0 - swapsizemb=0 - homefile="home.img" - plussize=128 - kernelargs=None - - if fstype == 'vfat': - if overlaysizemb > 2047: - raise CreatorError("Can't have an overlay of 2048MB or " - "greater on VFAT") - - if homesizemb > 2047: - raise CreatorError("Can't have an home overlay of 2048MB or " - "greater on VFAT") - - if swapsizemb > 2047: - raise CreatorError("Can't have an swap overlay of 2048MB or " - "greater on VFAT") - - livesize = misc.get_file_size(isodir + "/LiveOS") - - usbimgsize = (overlaysizemb + \ - homesizemb + \ - swapsizemb + \ - livesize + \ - plussize) * 1024L * 1024L - - disk = fs_related.SparseLoopbackDisk("%s/%s.usbimg" \ - % (self._outdir, self.name), - usbimgsize) - usbmnt = self._mkdtemp("usb-mnt") - usbloop = PartitionedMount(usbmnt) - usbloop.add_disk('/dev/sdb', disk) - - usbloop.add_partition(usbimgsize/1024/1024, - "/dev/sdb", - "/", - fstype, - boot=True) - - usbloop.mount() - - try: - fs_related.makedirs(usbmnt + "/LiveOS") - - if os.path.exists(isodir + "/LiveOS/squashfs.img"): - shutil.copyfile(isodir + "/LiveOS/squashfs.img", - usbmnt + "/LiveOS/squashfs.img") - else: - fs_related.mksquashfs(os.path.dirname(self._image), - usbmnt + "/LiveOS/squashfs.img") - - if os.path.exists(isodir + "/LiveOS/osmin.img"): - shutil.copyfile(isodir + "/LiveOS/osmin.img", - usbmnt + "/LiveOS/osmin.img") - - if fstype == "vfat" or fstype == "msdos": - uuid = usbloop.partitions[0]['mount'].uuid - label = usbloop.partitions[0]['mount'].fslabel - usblabel = "UUID=%s" % (uuid) - overlaysuffix = "-%s-%s" % (label, uuid) - else: - diskmount = usbloop.partitions[0]['mount'] - usblabel = "UUID=%s" % diskmount.uuid - overlaysuffix = "-%s-%s" % (diskmount.fslabel, diskmount.uuid) - - args = ['cp', "-Rf", isodir + "/isolinux", usbmnt + "/syslinux"] - rc = runner.show(args) - if rc: - raise CreatorError("Can't copy isolinux directory %s" \ - % (isodir + "/isolinux/*")) - - if os.path.isfile("/usr/share/syslinux/isolinux.bin"): - syslinux_path = "/usr/share/syslinux" - elif os.path.isfile("/usr/lib/syslinux/isolinux.bin"): - syslinux_path = "/usr/lib/syslinux" - elif os.path.isfile("/usr/lib/syslinux/bios/isolinux.bin"): - syslinux_path = "/usr/lib/syslinux/bios" - else: - raise CreatorError("syslinux not installed : " - "cannot find syslinux installation path") - - for f in ("isolinux.bin", "vesamenu.c32"): - path = os.path.join(syslinux_path, f) - if os.path.isfile(path): - args = ['cp', path, usbmnt + "/syslinux/"] - rc = runner.show(args) - if rc: - raise CreatorError("Can't copy syslinux file " + path) - else: - raise CreatorError("syslinux not installed: " - "syslinux file %s not found" % path) - - fd = open(isodir + "/isolinux/isolinux.cfg", "r") - text = fd.read() - fd.close() - pattern = re.compile('CDLABEL=[^ ]*') - text = pattern.sub(usblabel, text) - pattern = re.compile('rootfstype=[^ ]*') - text = pattern.sub("rootfstype=" + fstype, text) - if kernelargs: - text = text.replace("rd.live.image", "rd.live.image " + kernelargs) - - if overlaysizemb > 0: - msger.info("Initializing persistent overlay file") - overfile = "overlay" + overlaysuffix - if fstype == "vfat": - args = ['dd', - "if=/dev/zero", - "of=" + usbmnt + "/LiveOS/" + overfile, - "count=%d" % overlaysizemb, - "bs=1M"] - else: - args = ['dd', - "if=/dev/null", - "of=" + usbmnt + "/LiveOS/" + overfile, - "count=1", - "bs=1M", - "seek=%d" % overlaysizemb] - rc = runner.show(args) - if rc: - raise CreatorError("Can't create overlay file") - text = text.replace("rd.live.image", "rd.live.image rd.live.overlay=" + usblabel) - text = text.replace(" ro ", " rw ") - - if swapsizemb > 0: - msger.info("Initializing swap file") - swapfile = usbmnt + "/LiveOS/" + "swap.img" - args = ['dd', - "if=/dev/zero", - "of=" + swapfile, - "count=%d" % swapsizemb, - "bs=1M"] - rc = runner.show(args) - if rc: - raise CreatorError("Can't create swap file") - args = ["mkswap", "-f", swapfile] - rc = runner.show(args) - if rc: - raise CreatorError("Can't mkswap on swap file") - - if homesizemb > 0: - msger.info("Initializing persistent /home") - homefile = usbmnt + "/LiveOS/" + homefile - if fstype == "vfat": - args = ['dd', - "if=/dev/zero", - "of=" + homefile, - "count=%d" % homesizemb, - "bs=1M"] - else: - args = ['dd', - "if=/dev/null", - "of=" + homefile, - "count=1", - "bs=1M", - "seek=%d" % homesizemb] - rc = runner.show(args) - if rc: - raise CreatorError("Can't create home file") - - mkfscmd = fs_related.find_binary_path("/sbin/mkfs." + fstype) - if fstype == "ext2" or fstype == "ext3": - args = [mkfscmd, "-F", "-j", homefile] - else: - args = [mkfscmd, homefile] - rc = runner.show(args) - if rc: - raise CreatorError("Can't mke2fs home file") - if fstype == "ext2" or fstype == "ext3": - tune2fs = fs_related.find_binary_path("tune2fs") - args = [tune2fs, - "-c0", - "-i0", - "-ouser_xattr,acl", - homefile] - rc = runner.show(args) - if rc: - raise CreatorError("Can't tune2fs home file") - - if fstype == "vfat" or fstype == "msdos": - syslinuxcmd = fs_related.find_binary_path("syslinux") - syslinuxcfg = usbmnt + "/syslinux/syslinux.cfg" - args = [syslinuxcmd, - "-d", - "syslinux", - usbloop.partitions[0]["device"]] - - elif fstype == "ext2" or fstype == "ext3": - extlinuxcmd = fs_related.find_binary_path("extlinux") - syslinuxcfg = usbmnt + "/syslinux/extlinux.conf" - args = [extlinuxcmd, - "-i", - usbmnt + "/syslinux"] - - else: - raise CreatorError("Invalid file system type: %s" % (fstype)) - - os.unlink(usbmnt + "/syslinux/isolinux.cfg") - fd = open(syslinuxcfg, "w") - fd.write(text) - fd.close() - rc = runner.show(args) - if rc: - raise CreatorError("Can't install boot loader.") - - finally: - usbloop.unmount() - usbloop.cleanup() - - # Need to do this after image is unmounted and device mapper is closed - msger.info("set MBR") - found = False - for mbrfile in ["/usr/lib/syslinux/mbr.bin", "/usr/lib/syslinux/bios/mbr.bin", "/usr/share/syslinux/mbr.bin"]: - if os.path.exists(mbrfile): - found = True - break - if not found: - raise CreatorError("mbr.bin file didn't exist.") - mbrsize = os.path.getsize(mbrfile) - outimg = "%s/%s.usbimg" % (self._outdir, self.name) - - args = ['dd', - "if=" + mbrfile, - "of=" + outimg, - "seek=0", - "conv=notrunc", - "bs=1", - "count=%d" % (mbrsize)] - rc = runner.show(args) - if rc: - raise CreatorError("Can't set MBR.") - - def _stage_final_image(self): - try: - isodir = self._get_isodir() - fs_related.makedirs(isodir + "/LiveOS") - - minimal_size = self._resparse() - - if not self.skip_minimize: - fs_related.create_image_minimizer(isodir + "/LiveOS/osmin.img", - self._image, - minimal_size) - - if self.skip_compression: - shutil.move(self._image, - isodir + "/LiveOS/ext3fs.img") - else: - fs_related.makedirs(os.path.join( - os.path.dirname(self._image), - "LiveOS")) - shutil.move(self._image, - os.path.join(os.path.dirname(self._image), - "LiveOS", "ext3fs.img")) - fs_related.mksquashfs(os.path.dirname(self._image), - isodir + "/LiveOS/squashfs.img") - - self._create_usbimg(isodir) - - if self.pack_to: - self.image_files.update({'image_files': self.pack_to}) - usbimg = os.path.join(self._outdir, self.name + ".usbimg") - packimg = os.path.join(self._outdir, self.pack_to) - packing(packimg, usbimg) - os.unlink(usbimg) - else: - self.image_files.update({'image_files': self.name + ".usbimg"}) - - finally: - shutil.rmtree(isodir, ignore_errors = True) - self._set_isodir(None) - diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py deleted file mode 100644 index ed0cb26..0000000 --- a/plugins/imager/liveusb_plugin.py +++ /dev/null @@ -1,257 +0,0 @@ -#!/usr/bin/python -tt -# -# Copyright (c) 2011 Intel, Inc. -# -# This program is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the Free -# Software Foundation; version 2 of the License -# -# This program is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., 59 -# Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -import os -import shutil -import tempfile - -from mic import chroot, msger, rt_util -from mic.utils import misc, fs_related, errors -from mic.utils.partitionedfs import PartitionedMount -from mic.conf import configmgr -from mic.plugin import pluginmgr - -import mic.imager.liveusb as liveusb - -from mic.pluginbase import ImagerPlugin -class LiveUSBPlugin(ImagerPlugin): - name = 'liveusb' - - @classmethod - def do_create(self, subcmd, opts, *args): - """${cmd_name}: create liveusb image - - Usage: - ${name} ${cmd_name} [OPTS] - - ${cmd_option_list} - """ - - if len(args) != 1: - raise errors.Usage("Extra arguments given") - - creatoropts = configmgr.create - ksconf = args[0] - - if creatoropts['runtime'] == "bootstrap": - configmgr._ksconf = ksconf - rt_util.bootstrap_mic() - - if creatoropts['arch'] and creatoropts['arch'].startswith('arm'): - msger.warning('liveusb cannot support arm images, Quit') - return - - recording_pkgs = [] - if len(creatoropts['record_pkgs']) > 0: - recording_pkgs = creatoropts['record_pkgs'] - - if creatoropts['release'] is not None: - if 'name' not in recording_pkgs: - recording_pkgs.append('name') - if 'vcs' not in recording_pkgs: - recording_pkgs.append('vcs') - - configmgr._ksconf = ksconf - - # try to find the pkgmgr - pkgmgr = None - backends = pluginmgr.get_plugins('backend') - if 'auto' == creatoropts['pkgmgr']: - for key in configmgr.prefer_backends: - if key in backends: - pkgmgr = backends[key] - break - else: - for key in backends.keys(): - if key == creatoropts['pkgmgr']: - pkgmgr = backends[key] - break - - if not pkgmgr: - raise errors.CreatorError("Can't find backend: %s, " - "available choices: %s" % - (creatoropts['pkgmgr'], - ','.join(backends.keys()))) - - creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr) - - if len(recording_pkgs) > 0: - creator._recording_pkgs = recording_pkgs - - self.check_image_exists(creator.destdir, - creator.pack_to, - [creator.name + ".usbimg"], - creatoropts['release']) - try: - creator.check_depend_tools() - creator.mount(None, creatoropts["cachedir"]) - creator.install() - creator.configure(creatoropts["repomd"]) - creator.copy_kernel() - creator.unmount() - creator.package(creatoropts["destdir"]) - creator.create_manifest() - if creatoropts['release'] is not None: - creator.release_output(ksconf, creatoropts['destdir'], creatoropts['release']) - creator.print_outimage_info() - - except errors.CreatorError: - raise - finally: - creator.cleanup() - - msger.info("Finished.") - return 0 - - @classmethod - def do_chroot(cls, target, cmd=[]): - os_image = cls.do_unpack(target) - os_image_dir = os.path.dirname(os_image) - - # unpack image to target dir - imgsize = misc.get_file_size(os_image) * 1024L * 1024L - imgtype = misc.get_image_type(os_image) - if imgtype == "btrfsimg": - fstype = "btrfs" - myDiskMount = fs_related.BtrfsDiskMount - elif imgtype in ("ext3fsimg", "ext4fsimg"): - fstype = imgtype[:4] - myDiskMount = fs_related.ExtDiskMount - else: - raise errors.CreatorError("Unsupported filesystem type: %s" % fstype) - - extmnt = misc.mkdtemp() - extloop = myDiskMount(fs_related.SparseLoopbackDisk(os_image, imgsize), - extmnt, - fstype, - 4096, - "%s label" % fstype) - - try: - extloop.mount() - - except errors.MountError: - extloop.cleanup() - shutil.rmtree(extmnt, ignore_errors = True) - raise - - try: - if len(cmd) != 0: - cmdline = ' '.join(cmd) - else: - cmdline = "/bin/bash" - envcmd = fs_related.find_binary_inchroot("env", extmnt) - if envcmd: - cmdline = "%s HOME=/root %s" % (envcmd, cmdline) - chroot.chroot(extmnt, None, cmdline) - except: - raise errors.CreatorError("Failed to chroot to %s." %target) - finally: - chroot.cleanup_after_chroot("img", extloop, os_image_dir, extmnt) - - @classmethod - def do_pack(cls, base_on): - import subprocess - - def __mkinitrd(instance): - kernelver = instance._get_kernel_versions().values()[0][0] - args = [ "/usr/libexec/mkliveinitrd", "/boot/initrd-%s.img" % kernelver, "%s" % kernelver ] - try: - subprocess.call(args, preexec_fn = instance._chroot) - - except OSError, (err, msg): - raise errors.CreatorError("Failed to execute /usr/libexec/mkliveinitrd: %s" % msg) - - def __run_post_cleanups(instance): - kernelver = instance._get_kernel_versions().values()[0][0] - args = ["rm", "-f", "/boot/initrd-%s.img" % kernelver] - - try: - subprocess.call(args, preexec_fn = instance._chroot) - except OSError, (err, msg): - raise errors.CreatorError("Failed to run post cleanups: %s" % msg) - - convertoropts = configmgr.convert - convertoropts['name'] = os.path.splitext(os.path.basename(base_on))[0] - convertor = liveusb.LiveUSBImageCreator(convertoropts) - imgtype = misc.get_image_type(base_on) - if imgtype == "btrfsimg": - fstype = "btrfs" - elif imgtype in ("ext3fsimg", "ext4fsimg"): - fstype = imgtype[:4] - else: - raise errors.CreatorError("Unsupported filesystem type: %s" % fstyp) - convertor._set_fstype(fstype) - try: - convertor.mount(base_on) - __mkinitrd(convertor) - convertor._create_bootconfig() - __run_post_cleanups(convertor) - convertor.launch_shell(convertoropts['shell']) - convertor.unmount() - convertor.package() - convertor.print_outimage_info() - finally: - shutil.rmtree(os.path.dirname(base_on), ignore_errors = True) - - @classmethod - def do_unpack(cls, srcimg): - img = srcimg - imgsize = misc.get_file_size(img) * 1024L * 1024L - imgmnt = misc.mkdtemp() - disk = fs_related.SparseLoopbackDisk(img, imgsize) - imgloop = PartitionedMount(imgmnt, skipformat = True) - imgloop.add_disk('/dev/sdb', disk) - imgloop.add_partition(imgsize/1024/1024, "/dev/sdb", "/", "vfat", boot=False) - try: - imgloop.mount() - except errors.MountError: - imgloop.cleanup() - raise - - # legacy LiveOS filesystem layout support, remove for F9 or F10 - if os.path.exists(imgmnt + "/squashfs.img"): - squashimg = imgmnt + "/squashfs.img" - else: - squashimg = imgmnt + "/LiveOS/squashfs.img" - - tmpoutdir = misc.mkdtemp() - # unsquashfs requires outdir mustn't exist - shutil.rmtree(tmpoutdir, ignore_errors = True) - misc.uncompress_squashfs(squashimg, tmpoutdir) - - try: - # legacy LiveOS filesystem layout support, remove for F9 or F10 - if os.path.exists(tmpoutdir + "/os.img"): - os_image = tmpoutdir + "/os.img" - else: - os_image = tmpoutdir + "/LiveOS/ext3fs.img" - - if not os.path.exists(os_image): - raise errors.CreatorError("'%s' is not a valid live CD ISO : neither " - "LiveOS/ext3fs.img nor os.img exist" %img) - imgname = os.path.basename(srcimg) - imgname = os.path.splitext(imgname)[0] + ".img" - rtimage = os.path.join(tempfile.mkdtemp(dir = "/var/tmp", prefix = "tmp"), imgname) - shutil.copyfile(os_image, rtimage) - - finally: - imgloop.cleanup() - shutil.rmtree(tmpoutdir, ignore_errors = True) - shutil.rmtree(imgmnt, ignore_errors = True) - - return rtimage diff --git a/tools/mic b/tools/mic index 090e393..9dcc5bf 100755 --- a/tools/mic +++ b/tools/mic @@ -135,7 +135,7 @@ class MicCmd(cmdln.Cmdln): help="Launch shell before packaging the converted image") def do_convert(self, _subcmd, opts, *args): """${cmd_name}: convert image format - + Usage: mic convert @@ -174,7 +174,6 @@ class MicCmd(cmdln.Cmdln): % (srcformat, destformat)) maptab = { "livecd": "iso", - "liveusb": "usbimg", "loop": "img", } if destformat in maptab: