def unmount(self): """ Remove loop/dm device nodes which we created in 'mount()' and call the base class' 'unmount()' method. """ for p in self.__instloop.partitions: if p['mapper_device']: path = self._instroot + p['mapper_device'] if os.path.exists(path): os.unlink(path) if p['mpath_device']: path = self._instroot + p['mpath_device'] if os.path.exists(path): os.unlink(path) path = self._instroot + "/dev/mapper" if os.path.exists(path): shutil.rmtree(path, ignore_errors=True) for name in self.__disks.keys(): if self.__disks[name].device: path = self._instroot + self.__disks[name].device if os.path.exists(path): os.unlink(path) BaseImageCreator.unmount(self)
def __init__(self, creatoropts=None, pkgmgr=None, compress_image=None, generate_bmap=None, fstab_entry="uuid"): """Initialize a ApplianceImageCreator instance. This method takes the same arguments as ImageCreator.__init__() """ BaseImageCreator.__init__(self, creatoropts, pkgmgr) self.__instloop = None self.__imgdir = None self.__disks = {} self.__disk_format = "raw" self._disk_names = [] self._ptable_format = self.ks.handler.bootloader.ptable self.vmem = 512 self.vcpu = 1 self.checksum = False self.use_uuid = fstab_entry == "uuid" self.appliance_version = None self.appliance_release = None self.compress_image = compress_image self.bmap_needed = generate_bmap #self.getsource = False #self.listpkg = False self._dep_checks.extend(["sync", "kpartx", "parted", "extlinux"])
def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, hdddir, staging_data_dir, creatoropts=None, pkgmgr=None, compress_image=None, generate_bmap=None, fstab_entry="uuid"): """ Initialize a DirectImageCreator instance. This method takes the same arguments as ImageCreator.__init__() """ BaseImageCreator.__init__(self, creatoropts, pkgmgr) self.__instimage = None self.__imgdir = None self.__disks = {} self.__disk_format = "direct" self._disk_names = [] self._ptable_format = self.ks.handler.bootloader.ptable self.use_uuid = fstab_entry == "uuid" self.compress_image = compress_image self.bmap_needed = generate_bmap self.oe_builddir = oe_builddir if image_output_dir: self.tmpdir = image_output_dir self.cachedir = "%s/cache" % image_output_dir self.rootfs_dir = rootfs_dir self.bootimg_dir = bootimg_dir self.kernel_dir = kernel_dir self.native_sysroot = native_sysroot self.hdddir = hdddir self.staging_data_dir = staging_data_dir
def __init__(self, creatoropts=None, pkgmgr=None, compress_image=None, generate_bmap=None, fstab_entry="uuid"): """Initialize a ApplianceImageCreator instance. This method takes the same arguments as ImageCreator.__init__() """ BaseImageCreator.__init__(self, creatoropts, pkgmgr) self.__instloop = None self.__imgdir = None self.__disks = {} self.__disk_format = "raw" self._disk_names = [] self._ptable_format = self.ks.handler.bootloader.ptable self.vmem = 512 self.vcpu = 1 self.checksum = False self.use_uuid = fstab_entry == "uuid" self.appliance_version = None self.appliance_release = None self.compress_image = compress_image self.bmap_needed = generate_bmap self._need_extlinux = not kickstart.use_installerfw(self.ks, "bootloader") #self.getsource = False #self.listpkg = False self._dep_checks.extend(["sync", "kpartx", "parted"]) if self._need_extlinux: self._dep_checks.extend(["extlinux"])
def __init__(self, cfgmgr = None, pkgmgr = None): self.zips = { "tar.bz2" : "" } BaseImageCreator.__init__(self, cfgmgr, pkgmgr) self._fstype = None self._fsopts = None self._include_src = False
def configure(self, repodata = None): import subprocess def chroot(): os.chroot(self._instroot) os.chdir("/") if os.path.exists(self._instroot + "/usr/bin/Xorg"): subprocess.call(["/bin/chmod", "u+s", "/usr/bin/Xorg"], preexec_fn = chroot) BaseImageCreator.configure(self, repodata)
def _get_sign_scripts_env(self): env = BaseImageCreator._get_sign_scripts_env(self) # Directory path of %post-umounts scripts if self._umountdir: env['UMOUNT_SCRIPTS_PATH'] = str(self._umountdir) return env
def mount(self, base_on = None, cachedir = None): """ This method calls the base class' 'mount()' method and then creates block device nodes corresponding to the image's partitions in the image itself. Namely, the image has /dev/loopX device corresponding to the entire image, and per-partition /dev/mapper/* devices. We copy these files to image's "/dev" directory in order to enable scripts which run in the image chroot environment to access own raw partitions. For example, this can be used to install the bootloader to the MBR (say, from an installer framework plugin). """ def copy_devnode(src, dest): """A helper function for copying device nodes.""" if not src: return stat_obj = os.stat(src) assert stat.S_ISBLK(stat_obj.st_mode) os.mknod(dest, stat_obj.st_mode, os.makedev(os.major(stat_obj.st_rdev), os.minor(stat_obj.st_rdev))) # os.mknod uses process umask may create a nod with different # permissions, so we use os.chmod to make sure permissions are # correct. os.chmod(dest, stat_obj.st_mode) BaseImageCreator.mount(self, base_on, cachedir) # Copy the disk loop devices for name in self.__disks.keys(): loopdev = self.__disks[name].device copy_devnode(loopdev, self._instroot + loopdev) # Copy per-partition dm nodes os.mkdir(self._instroot + "/dev/mapper", os.stat("/dev/mapper").st_mode) for p in self.__instloop.partitions: copy_devnode(p['mapper_device'], self._instroot + p['mapper_device']) copy_devnode(p['mpath_device'], self._instroot + p['mpath_device'])
def _get_post_scripts_env(self, in_chroot): env = BaseImageCreator._get_post_scripts_env(self, in_chroot) # Export the file-system UUIDs and partition UUIDs (AKA PARTUUIDs) for p in self.__instloop.partitions: env.update(self._set_part_env(p['ks_pnum'], "UUID", p['uuid'])) env.update( self._set_part_env(p['ks_pnum'], "PARTUUID", p['partuuid'])) return env
def __init__(self, oe_builddir, image_output_dir, rootfs_dir, bootimg_dir, kernel_dir, native_sysroot, hdddir, staging_data_dir, creatoropts=None, pkgmgr=None, compress_image=None, generate_bmap=None, fstab_entry="uuid"): """ Initialize a DirectImageCreator instance. This method takes the same arguments as ImageCreator.__init__() """ BaseImageCreator.__init__(self, creatoropts, pkgmgr) self.__instimage = None self.__imgdir = None self.__disks = {} self.__disk_format = "direct" self._disk_names = [] self._ptable_format = self.ks.handler.bootloader.ptable self.use_uuid = fstab_entry == "uuid" self.compress_image = compress_image self.bmap_needed = generate_bmap self.oe_builddir = oe_builddir if image_output_dir: self.tmpdir = image_output_dir self.cachedir = "%s/cache" % image_output_dir self.rootfs_dir = rootfs_dir self.bootimg_dir = bootimg_dir self.kernel_dir = kernel_dir self.native_sysroot = native_sysroot self.hdddir = hdddir self.staging_data_dir = staging_data_dir self.boot_type = ""
def _get_post_scripts_env(self, in_chroot): env = BaseImageCreator._get_post_scripts_env(self, in_chroot) # Export the file-system UUIDs and partition UUIDs (AKA PARTUUIDs) for p in self.__instloop.partitions: env.update(self._set_part_env(p['ks_pnum'], "UUID", p['uuid'])) env.update(self._set_part_env(p['ks_pnum'], "PARTUUID", p['partuuid'])) env.update(self._set_part_env(p['ks_pnum'], "DEVNODE_NOW", p['mapper_device'])) env.update(self._set_part_env(p['ks_pnum'], "DISK_DEVNODE_NOW", self.__disks[p['disk_name']].device)) return env
def _get_required_packages(self): required_packages = BaseImageCreator._get_required_packages(self) if self._need_extlinux: if not self.target_arch or not self.target_arch.startswith("arm"): required_packages += ["syslinux", "syslinux-extlinux"] return required_packages
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"
def _get_excluded_packages(self): return BaseImageCreator._get_excluded_packages(self)
def postinstall(self): BaseImageCreator.postinstall(self) self.move_post_umount_scripts()
def _get_required_packages(self): required_packages = BaseImageCreator._get_required_packages(self) if not self.target_arch or not self.target_arch.startswith("arm"): required_packages += ["syslinux", "syslinux-extlinux"] return required_packages
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"