def _get_post_scripts_env(self, in_chroot):
        """Return an environment dict for %post scripts.

        This is the hook where subclasses may specify some environment
        variables for %post scripts by return a dict containing the desired
        environment.

        in_chroot -- whether this %post script is to be executed chroot()ed
                     into _instroot.
        """

        env = {}
        pnum = 0

        for p in kickstart.get_partitions(self.ks):
            env.update(self._set_part_env(pnum, "SIZE", p.size))
            env.update(self._set_part_env(pnum, "MOUNTPOINT", p.mountpoint))
            env.update(self._set_part_env(pnum, "FSTYPE", p.fstype))
            env.update(self._set_part_env(pnum, "LABEL", p.label))
            env.update(self._set_part_env(pnum, "FSOPTS", p.fsopts))
            env.update(self._set_part_env(pnum, "BOOTFLAG", p.active))
            env.update(self._set_part_env(pnum, "ALIGN", p.align))
            env.update(self._set_part_env(pnum, "TYPE_ID", p.part_type))
            env.update(
                self._set_part_env(pnum, "DEVNODE",
                                   "/dev/%s%d" % (p.disk, pnum + 1)))
            pnum += 1

        # Count of paritions
        env[self.installerfw_prefix + "PART_COUNT"] = str(pnum)

        # Partition table format
        ptable_format = self.ks.handler.bootloader.ptable
        env[self.installerfw_prefix + "PTABLE_FORMAT"] = ptable_format

        # The kerned boot parameters
        kernel_opts = self.ks.handler.bootloader.appendLine
        env[self.installerfw_prefix + "KERNEL_OPTS"] = kernel_opts

        # Name of the distribution
        env[self.installerfw_prefix + "DISTRO_NAME"] = self.distro_name

        # Name of the image creation tool
        env[self.installerfw_prefix + "INSTALLER_NAME"] = "wic"

        # The real current location of the mounted file-systems
        if in_chroot:
            mount_prefix = "/"
        else:
            mount_prefix = self._instroot
        env[self.installerfw_prefix + "MOUNT_PREFIX"] = mount_prefix

        # These are historical variables which lack the common name prefix
        if not in_chroot:
            env["INSTALL_ROOT"] = self._instroot
            env["IMG_NAME"] = self._name

        return env
Ejemplo n.º 2
0
    def _get_post_scripts_env(self, in_chroot):
        """Return an environment dict for %post scripts.

        This is the hook where subclasses may specify some environment
        variables for %post scripts by return a dict containing the desired
        environment.

        in_chroot -- whether this %post script is to be executed chroot()ed
                     into _instroot.
        """

        env = {}
        pnum = 0

        for p in kickstart.get_partitions(self.ks):
            env.update(self._set_part_env(pnum, "SIZE", p.size))
            env.update(self._set_part_env(pnum, "MOUNTPOINT", p.mountpoint))
            env.update(self._set_part_env(pnum, "FSTYPE", p.fstype))
            env.update(self._set_part_env(pnum, "LABEL", p.label))
            env.update(self._set_part_env(pnum, "FSOPTS", p.fsopts))
            env.update(self._set_part_env(pnum, "BOOTFLAG", p.active))
            env.update(self._set_part_env(pnum, "ALIGN", p.align))
            env.update(self._set_part_env(pnum, "TYPE_ID", p.part_type))
            env.update(self._set_part_env(pnum, "DEVNODE",
                                          "/dev/%s%d" % (p.disk, pnum + 1)))
            pnum += 1

        # Count of paritions
        env[self.installerfw_prefix + "PART_COUNT"] = str(pnum)

        # Partition table format
        ptable_format = self.ks.handler.bootloader.ptable
        env[self.installerfw_prefix + "PTABLE_FORMAT"] = ptable_format

        # The kerned boot parameters
        kernel_opts = self.ks.handler.bootloader.appendLine
        env[self.installerfw_prefix + "KERNEL_OPTS"] = kernel_opts

        # Name of the distribution
        env[self.installerfw_prefix + "DISTRO_NAME"] = self.distro_name

        # Name of the image creation tool
        env[self.installerfw_prefix + "INSTALLER_NAME"] = "wic"

        # The real current location of the mounted file-systems
        if in_chroot:
            mount_prefix = "/"
        else:
            mount_prefix = self._instroot
        env[self.installerfw_prefix + "MOUNT_PREFIX"] = mount_prefix

        # These are historical variables which lack the common name prefix
        if not in_chroot:
            env["INSTALL_ROOT"] = self._instroot
            env["IMG_NAME"] = self._name

        return env
Ejemplo n.º 3
0
    def __init__(self, creatoropts=None, pkgmgr=None):
        """Initialise a LiveImageCreator instance.

           This method takes the same arguments as ImageCreator.__init__().
        """
        LoopImageCreator.__init__(self, creatoropts, pkgmgr)

        #Controls whether to use squashfs to compress the image.
        self.skip_compression = False

        #Controls whether an image minimizing snapshot should be created.
        #
        #This snapshot can be used when copying the system image from the ISO in
        #order to minimize the amount of data that needs to be copied; simply,
        #it makes it possible to create a version of the image's filesystem with
        #no spare space.
        self.skip_minimize = False

        #A flag which indicates i act as a convertor default false
        self.actasconvertor = False

        #The bootloader timeout from kickstart.
        if self.ks:
            self._timeout = kickstart.get_timeout(self.ks, 10)
        else:
            self._timeout = 10

        #The default kernel type from kickstart.
        if self.ks:
            self._default_kernel = kickstart.get_default_kernel(
                self.ks, "kernel")
        else:
            self._default_kernel = None

        if self.ks:
            parts = kickstart.get_partitions(self.ks)
            if len(parts) > 1:
                raise CreatorError("Can't support multi partitions in ks file "
                                   "for this image type")
            # FIXME: rename rootfs img to self.name,
            # else can't find files when create iso
            self._instloops[0]['name'] = self.name + ".img"

        self.__isodir = None

        self.__modules = [
            "=ata", "sym53c8xx", "aic7xxx", "=usb", "=firewire", "=mmc",
            "=pcmcia", "mptsas"
        ]
        if self.ks:
            self.__modules.extend(kickstart.get_modules(self.ks))

        self._dep_checks.extend(
            ["isohybrid", "unsquashfs", "mksquashfs", "dd", "genisoimage"])
Ejemplo n.º 4
0
    def _mount_instroot(self, base_on = None):
        self.__imgdir = self._mkdtemp()

        #Set a default partition if no partition is given out
        if not self.ks.handler.partition.partitions:
            partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
            args = partstr.split()
            pd = self.ks.handler.partition.parse(args[1:])
            if pd not in self.ks.handler.partition.partitions:
                self.ks.handler.partition.partitions.append(pd)

        #list of partitions from kickstart file
        parts = kickstart.get_partitions(self.ks)

        #list of disks where a disk is an dict with name: and size
        disks = []

        for i in range(len(parts)):
            if parts[i].disk:
                disk = parts[i].disk
            else:
                raise CreatorError("Failed to create disks, no --ondisk specified in partition line of ks file")

            if not parts[i].fstype:
                 raise CreatorError("Failed to create disks, no --fstype specified in partition line of ks file")

            size =   parts[i].size * 1024L * 1024L

            found = False
            for j in range(len(disks)):
                if disks[j]['name'] == disk:
                    disks[j]['size'] = disks[j]['size'] + size
                    found = True
                    break
                else:
                    found = False
            if not found:
                disks.append({ 'name': disk, 'size': size })

        #create disk
        for item in disks:
            msger.debug("Adding disk %s as %s/%s-%s.raw" % (item['name'], self.__imgdir,self.name, item['name']))
            disk = fs_related.SparseLoopbackDisk("%s/%s-%s.raw" % (self.__imgdir,self.name, item['name']),item['size'])
            self.__disks[item['name']] = disk

        self.__instloop = PartitionedMount(self.__disks, self._instroot)

        for p in parts:
            self.__instloop.add_partition(int(p.size), p.disk, p.mountpoint, p.fstype, fsopts = p.fsopts, boot = p.active)

        self.__instloop.mount()
        self._create_mkinitrd_config()
Ejemplo n.º 5
0
    def _get_parts(self):
        if not self.ks:
            raise CreatorError("Failed to get partition info, "
                               "please check your kickstart setting.")

        # Set a default partition if no partition is given out
        if not self.ks.handler.partition.partitions:
            partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
            args = partstr.split()
            pd = self.ks.handler.partition.parse(args[1:])
            if pd not in self.ks.handler.partition.partitions:
                self.ks.handler.partition.partitions.append(pd)

        # partitions list from kickstart file
        return kickstart.get_partitions(self.ks)
Ejemplo n.º 6
0
    def _get_parts(self):
        if not self.ks:
            raise CreatorError("Failed to get partition info, "
                               "please check your kickstart setting.")

        # Set a default partition if no partition is given out
        if not self.ks.handler.partition.partitions:
            partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
            args = partstr.split()
            pd = self.ks.handler.partition.parse(args[1:])
            if pd not in self.ks.handler.partition.partitions:
                self.ks.handler.partition.partitions.append(pd)

        # partitions list from kickstart file
        return kickstart.get_partitions(self.ks)
Ejemplo n.º 7
0
    def __init__(self, creatoropts=None, pkgmgr=None):
        """Initialise a LiveImageCreator instance.

           This method takes the same arguments as ImageCreator.__init__().
        """
        LoopImageCreator.__init__(self, creatoropts, pkgmgr)

        # Controls whether to use squashfs to compress the image.
        self.skip_compression = False

        # Controls whether an image minimizing snapshot should be created.
        #
        # This snapshot can be used when copying the system image from the ISO in
        # order to minimize the amount of data that needs to be copied; simply,
        # it makes it possible to create a version of the image's filesystem with
        # no spare space.
        self.skip_minimize = False

        # A flag which indicates i act as a convertor default false
        self.actasconvertor = False

        # The bootloader timeout from kickstart.
        if self.ks:
            self._timeout = kickstart.get_timeout(self.ks, 10)
        else:
            self._timeout = 10

        # The default kernel type from kickstart.
        if self.ks:
            self._default_kernel = kickstart.get_default_kernel(self.ks, "kernel")
        else:
            self._default_kernel = None

        if self.ks:
            parts = kickstart.get_partitions(self.ks)
            if len(parts) > 1:
                raise CreatorError("Can't support multi partitions in ks file " "for this image type")
            # FIXME: rename rootfs img to self.name,
            # else can't find files when create iso
            self._instloops[0]["name"] = self.name + ".img"

        self.__isodir = None

        self.__modules = ["=ata", "sym53c8xx", "aic7xxx", "=usb", "=firewire", "=mmc", "=pcmcia", "mptsas"]
        if self.ks:
            self.__modules.extend(kickstart.get_modules(self.ks))

        self._dep_checks.extend(["isohybrid", "unsquashfs", "mksquashfs", "dd", "genisoimage"])
Ejemplo n.º 8
0
    def __init__(self, creatoropts=None, pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks,
                                                       "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'extopts': part.extopts or None,
                    'loop': None,  # to be created in _mount_instroot
                    })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self.__imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(self.ks,
                                                         4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
Ejemplo n.º 9
0
    def _mount_instroot(self, base_on=None):
        self.__imgdir = self._mkdtemp()

        #Set a default partition if no partition is given out
        if not self.ks.handler.partition.partitions:
            partstr = "part / --size 1900 --ondisk sda --fstype=ext3"
            args = partstr.split()
            pd = self.ks.handler.partition.parse(args[1:])
            if pd not in self.ks.handler.partition.partitions:
                self.ks.handler.partition.partitions.append(pd)

        #list of partitions from kickstart file
        parts = kickstart.get_partitions(self.ks)

        #list of disks where a disk is an dict with name: and size
        disks = []

        for i in range(len(parts)):
            if parts[i].disk:
                disk = parts[i].disk
            else:
                raise CreatorError(
                    "Failed to create disks, no --ondisk specified in partition line of ks file"
                )

            if not parts[i].fstype:
                raise CreatorError(
                    "Failed to create disks, no --fstype specified in partition line of ks file"
                )

            size = parts[i].size * 1024L * 1024L

            found = False
            for j in range(len(disks)):
                if disks[j]['name'] == disk:
                    disks[j]['size'] = disks[j]['size'] + size
                    found = True
                    break
                else:
                    found = False
            if not found:
                disks.append({'name': disk, 'size': size})

        #create disk
        for item in disks:
            msger.debug("Adding disk %s as %s/%s-%s.raw" %
                        (item['name'], self.__imgdir, self.name, item['name']))
            disk = fs_related.SparseLoopbackDisk(
                "%s/%s-%s.raw" % (self.__imgdir, self.name, item['name']),
                item['size'])
            self.__disks[item['name']] = disk

        self.__instloop = PartitionedMount(self.__disks, self._instroot)

        for p in parts:
            self.__instloop.add_partition(int(p.size),
                                          p.disk,
                                          p.mountpoint,
                                          p.fstype,
                                          fsopts=p.fsopts,
                                          boot=p.active)

        self.__instloop.mount()
        self._create_mkinitrd_config()
Ejemplo n.º 10
0
Archivo: loop.py Proyecto: tizenpdk/mic
    def __init__(self, creatoropts=None, pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks,
                                                       "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")
            if self.__fstype in AFTER_MNT_FS.keys():
                self.__fstype = "ext4"

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                aft_fstype = None
                if part.fstype == "swap":
                    continue
                elif part.fstype in AFTER_MNT_FS.keys():
                    aft_fstype = part.fstype
                    part.fstype = "ext4"

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'aft_fstype': aft_fstype or None,
                    'extopts': part.extopts or None,
                    'vdfsopts': part.vdfsopts or None,
                    'squashfsopts': part.squashfsopts or None,
                    'cpioopts': part.cpioopts or None,
                    'loop': None,  # to be created in _mount_instroot
                    'uuid': part.uuid or None,
                    'kspart' : part,
                    'exclude_image' : part.exclude_image or None,
                    })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self._imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(self.ks,
                                                         4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
Ejemplo n.º 11
0
    def __init__(self, creatoropts=None, pkgmgr=None, taring_to=None):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)
        self.taring_to = taring_to

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            self.__fstype = kickstart.get_image_fstype(self.ks, "ext3")
            self.__fsopts = kickstart.get_image_fsopts(self.ks,
                                                       "defaults,noatime")

            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'
                allloops.append({
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096L * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'loop': None,  # to be created in _mount_instroot
                })
            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        self.__imgdir = None

        if self.ks:
            self.__image_size = kickstart.get_image_size(
                self.ks, 4096L * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"
Ejemplo n.º 12
0
    def __init__(self,
                 creatoropts=None,
                 pkgmgr=None,
                 compress_image=None,
                 shrink_image=False):
        """Initialize a LoopImageCreator instance.

        This method takes the same arguments as ImageCreator.__init__()
        with the addition of:

        fslabel -- A string used as a label for any filesystems created.
        """

        BaseImageCreator.__init__(self, creatoropts, pkgmgr)

        self.compress_image = compress_image
        self.shrink_image = shrink_image

        self.__fslabel = None
        self.fslabel = self.name

        self.__blocksize = 4096
        if self.ks:
            #self.__fstype = kickstart.get_image_fstype(self.ks,
            #                                           "ext3")
            #self.__fsopts = kickstart.get_image_fsopts(self.ks,
            #                                           "defaults,noatime")
            allloops = []
            for part in sorted(kickstart.get_partitions(self.ks),
                               key=lambda p: p.mountpoint):
                if part.fstype == "swap":
                    continue

                label = part.label
                mp = part.mountpoint
                if mp == '/':
                    # the base image
                    if not label:
                        label = self.name
                else:
                    mp = mp.rstrip('/')
                    if not label:
                        msger.warning('no "label" specified for loop img at %s'
                                      ', use the mountpoint as the name' % mp)
                        label = mp.split('/')[-1]

                imgname = misc.strip_end(label, '.img') + '.img'

                loop_data = {
                    'mountpoint': mp,
                    'label': label,
                    'name': imgname,
                    'size': part.size or 4096 * 1024 * 1024,
                    'fstype': part.fstype or 'ext3',
                    'fsopts': part.fsopts,
                    'loop': None,  # to be created in _mount_instroot
                }

                if loop_data['fstype'] == "btrfs":
                    subvols = []
                    snaps = []
                    for item in kickstart.get_btrfs_list(self.ks):
                        if item.parent == label:
                            if item.subvol:
                                subvols.append({
                                    'size':
                                    0,  # In sectors
                                    'mountpoint':
                                    item.
                                    mountpoint,  # Mount relative to chroot
                                    'fstype':
                                    "btrfs",  # Filesystem type
                                    'fsopts':
                                    "defaults,noatime,subvol=%s" %
                                    item.name,  # Filesystem mount options
                                    'device':
                                    None,  # kpartx device node for partition
                                    'mount':
                                    None,  # Mount object
                                    'subvol':
                                    item.name,  # Subvolume name
                                    'label':
                                    item.label,
                                    'boot':
                                    False,  # Bootable flag
                                    'mounted':
                                    False,  # Mount flag
                                    'quota':
                                    item.quota,
                                    'parent':
                                    item.parent,
                                })
                            if item.snapshot:
                                snaps.append({
                                    'name': item.name,
                                    'base': item.base
                                })
                    else:
                        loop_data['subvolumes'] = subvols
                        loop_data['snapshots'] = snaps

                allloops.append(loop_data)

            self._instloops = allloops

        else:
            self.__fstype = None
            self.__fsopts = None
            self._instloops = []

        if self.ks:
            self.__image_size = kickstart.get_image_size(
                self.ks, 4096 * 1024 * 1024)
        else:
            self.__image_size = 0

        self._img_name = self.name + ".img"