Beispiel #1
0
def cleanup_mounts(chrootdir):
    umountcmd = misc.find_binary_path("umount")
    for point in BIND_MOUNTS:
        args = [ umountcmd, "-l", chrootdir + point ]
        runner.quiet(args)
    point = '/parentroot'
    args = [ umountcmd, "-l", chrootdir + point ]
    runner.quiet(args)

    abs_chrootdir = os.path.abspath(chrootdir)
    with open('/proc/mounts') as f:
        for line in f:
            if abs_chrootdir in line:
                point = line.split()[1]

                if abs_chrootdir == point:
                    continue

                args = [ umountcmd, "-l", point ]
                ret = runner.quiet(args)
                if ret != 0:
                    msger.warning("failed to unmount %s" % point)
                    return ret

    return 0
Beispiel #2
0
def cleanup_mounts(chrootdir):
    umountcmd = misc.find_binary_path("umount")
    for point in BIND_MOUNTS:
        args = [umountcmd, "-l", chrootdir + point]
        runner.quiet(args)
    point = '/parentroot'
    args = [umountcmd, "-l", chrootdir + point]
    runner.quiet(args)

    abs_chrootdir = os.path.abspath(chrootdir)
    with open('/proc/mounts') as f:
        for line in f:
            if abs_chrootdir in line:
                point = line.split()[1]

                if abs_chrootdir == point:
                    continue

                args = [umountcmd, "-l", point]
                ret = runner.quiet(args)
                if ret != 0:
                    msger.warning("failed to unmount %s" % point)
                    return ret

    return 0
Beispiel #3
0
    def generate_bmap(self):
        """ Generate block map file for the image. The idea is that while disk
        images we generate may be large (e.g., 4GiB), they may actually contain
        only little real data, e.g., 512MiB. This data are files, directories,
        file-system meta-data, partition table, etc. In other words, when
        flashing the image to the target device, you do not have to copy all the
        4GiB of data, you can copy only 512MiB of it, which is 4 times faster.

        This function generates the block map file for an arbitrary image that
        mic has generated. The block map file is basically an XML file which
        contains a list of blocks which have to be copied to the target device.
        The other blocks are not used and there is no need to copy them. """

        if self.bmap_needed is None:
            return

        msger.info("Generating the map file(s)")

        for name in self.__disks.keys():
            image = self._full_path(self.__imgdir, name, self.__disk_format)
            bmap_file = self._full_path(self._outdir, name, "bmap")
            self.image_files.setdefault(name, {}).update({'bmap': \
                                            os.path.basename(bmap_file)})

            msger.debug("Generating block map file '%s'" % bmap_file)
            
            bmaptoolcmd = misc.find_binary_path('bmaptool')
            rc = runner.show([bmaptoolcmd, 'create', image, '-o', bmap_file])
            if rc != 0:
                raise CreatorError("Failed to create bmap file: %s" % bmap_file)
Beispiel #4
0
    def generate_bmap(self):
        """ Generate block map file for the image. The idea is that while disk
        images we generate may be large (e.g., 4GiB), they may actually contain
        only little real data, e.g., 512MiB. This data are files, directories,
        file-system meta-data, partition table, etc. In other words, when
        flashing the image to the target device, you do not have to copy all the
        4GiB of data, you can copy only 512MiB of it, which is 4 times faster.

        This function generates the block map file for an arbitrary image that
        mic has generated. The block map file is basically an XML file which
        contains a list of blocks which have to be copied to the target device.
        The other blocks are not used and there is no need to copy them. """

        if self.bmap_needed is None:
            return

        msger.info("Generating the map file(s)")

        for name in self.__disks.keys():
            image = self._full_path(self.__imgdir, name, self.__disk_format)
            bmap_file = self._full_path(self._outdir, name, "bmap")
            self.image_files.setdefault(name, {}).update({'bmap': \
                                            os.path.basename(bmap_file)})

            msger.debug("Generating block map file '%s'" % bmap_file)
            
            bmaptoolcmd = misc.find_binary_path('bmaptool')
            rc = runner.show([bmaptoolcmd, 'create', image, '-o', bmap_file])
            if rc != 0:
                raise CreatorError("Failed to create bmap file: %s" % bmap_file)
Beispiel #5
0
def cleanup_mounts(chrootdir):
    umountcmd = misc.find_binary_path("umount")
    abs_chrootdir = os.path.abspath(chrootdir)
    mounts = open('/proc/mounts').readlines()
    for line in reversed(mounts):
        if abs_chrootdir not in line:
            continue

        point = line.split()[1]

        # '/' to avoid common name prefix
        if abs_chrootdir == point or point.startswith(abs_chrootdir + '/'):
            args = [ umountcmd, "-l", point ]
            ret = runner.quiet(args)
            if ret != 0:
                msger.warning("failed to unmount %s" % point)

    return 0
def cleanup_mounts(chrootdir):
    umountcmd = misc.find_binary_path("umount")
    abs_chrootdir = os.path.abspath(chrootdir)
    mounts = open('/proc/mounts').readlines()
    for line in reversed(mounts):
        if abs_chrootdir not in line:
            continue

        point = line.split()[1]

        # '/' to avoid common name prefix
        if abs_chrootdir == point or point.startswith(abs_chrootdir + '/'):
            args = [umountcmd, "-l", point]
            ret = runner.quiet(args)
            if ret != 0:
                msger.warning("failed to unmount %s" % point)

    return 0
Beispiel #7
0
def cleanup_mounts(chrootdir):
    """ clean up all mount entries owned by chrootdir """
    umountcmd = misc.find_binary_path("umount")
    mounts = open('/proc/mounts').readlines()
    for line in reversed(mounts):
        if chrootdir not in line:
            continue

        point = line.split()[1]

        # '/' to avoid common name prefix
        if chrootdir == point or point.startswith(chrootdir + '/'):
            args = [ umountcmd, "-l", point ]
            ret = runner.quiet(args)
            if ret != 0:
                msger.warning("failed to unmount %s" % point)
            if os.path.isdir(point) and len(os.listdir(point)) == 0:
                shutil.rmtree(point)
            else:
                msger.warning("%s is not directory or is not empty" % point)
Beispiel #8
0
def cleanup_mounts(chrootdir):
    """ clean up all mount entries owned by chrootdir """
    umountcmd = misc.find_binary_path("umount")
    mounts = open('/proc/mounts').readlines()
    for line in reversed(mounts):
        if chrootdir not in line:
            continue

        point = line.split()[1]

        # '/' to avoid common name prefix
        if chrootdir == point or point.startswith(chrootdir + '/'):
            args = [umountcmd, "-l", point]
            ret = runner.quiet(args)
            if ret != 0:
                msger.warning("failed to unmount %s" % point)
            if os.path.isdir(point) and len(os.listdir(point)) == 0:
                shutil.rmtree(point)
            else:
                msger.warning("%s is not directory or is not empty" % point)