def __init__(self, xml_state, root_dir): self.configured_size = xml_state.get_build_type_size() self.size = SystemSize(root_dir) self.requested_image_type = xml_state.get_build_type_name() if self.requested_image_type in Defaults.get_filesystem_image_types(): self.requested_filesystem = self.requested_image_type else: self.requested_filesystem = xml_state.build_type.get_filesystem()
def __init__(self, xml_state, root_dir): self.configured_size = xml_state.get_build_type_size() self.build_type_name = xml_state.get_build_type_name() self.filesystem = xml_state.build_type.get_filesystem() self.bootpart_requested = xml_state.build_type.get_bootpartition() self.bootpart_mbytes = xml_state.build_type.get_bootpartsize() self.mdraid = xml_state.build_type.get_mdraid() self.luks = xml_state.build_type.get_luks() self.volume_manager = xml_state.get_volume_management() self.bootloader = xml_state.build_type.get_bootloader() self.oemconfig = xml_state.get_build_type_oemconfig_section() self.volumes = xml_state.get_volumes() self.firmware = FirmWare(xml_state) self.rootsize = SystemSize(root_dir) self.root_dir = root_dir self.xml_state = xml_state
def __calculate_volume_mbytes(self): """ calculate the number of mbytes each volume path currently consumes and also provide a total number of these values """ volume_mbytes_type = namedtuple('volume_mbytes_type', ['volume', 'total']) volume_mbytes = {} volume_total = 0 for volume in self.volumes: if volume.realpath and not volume.realpath == '/': path_to_volume = self.root_dir + '/' + volume.realpath if os.path.exists(path_to_volume): volume_size = SystemSize(path_to_volume) volume_mbytes[volume.realpath] = volume_size.customize( volume_size.accumulate_mbyte_file_sizes(), self.filesystem) volume_total += volume_mbytes[volume.realpath] return volume_mbytes_type(volume=volume_mbytes, total=volume_total)
def get_volume_mbsize(self, mbsize, size_type, realpath, filesystem_name): """ Implements size lookup for the given path and desired filesystem according to the specified size type """ if size_type == 'freespace': # Please note for nested volumes which contains other volumes # the freespace calculation is not correct. Example: # /usr is a volume and /usr/lib is a volume. If freespace is # set for the /usr volume the data size calculated also # contains the data of the /usr/lib path which will live in # an extra volume later. The result will be more freespace # than expected ! Especially for the root volume this matters # most because it always nests all other volumes. Thus it is # better to use a fixed size for the root volume if it is not # configured to use all rest space # # You are invited to fix it :) volume_size = SystemSize(self.root_dir + '/' + realpath) mbsize = int(mbsize) + \ Defaults.get_min_volume_mbytes() mbsize += volume_size.customize( volume_size.accumulate_mbyte_file_sizes(), filesystem_name) return mbsize
def __get_container_filesystem_size_mbytes(self): size = SystemSize(self.root_dir) root_dir_mbytes = size.accumulate_mbyte_file_sizes() return size.customize(root_dir_mbytes, 'ext4')
def create(self): # media dir to store CD contents self.media_dir = mkdtemp(prefix='live-media.', dir=self.target_dir) rootsize = SystemSize(self.media_dir) # custom iso metadata log.info('Using following live ISO metadata:') log.info('--> Application id: %s', self.mbrid.get_id()) log.info('--> Publisher: %s', Defaults.get_publisher()) custom_iso_args = [ '-A', self.mbrid.get_id(), '-p', '"' + Defaults.get_preparer() + '"', '-publisher', '"' + Defaults.get_publisher() + '"', ] if self.volume_id: log.info('--> Volume id: %s', self.volume_id) custom_iso_args.append('-V') custom_iso_args.append('"' + self.volume_id + '"') # prepare boot(initrd) root system log.info('Preparing live ISO boot system') self.boot_image_task.prepare() # export modprobe configuration to boot image self.system_setup.export_modprobe_setup( self.boot_image_task.boot_root_directory) # pack system into live boot structure log.info('Packing system into live ISO type: %s', self.live_type) if self.live_type in self.types: live_type_image = FileSystem(name=self.types[self.live_type], device_provider=None, root_dir=self.root_dir) live_type_image.create_on_file(self.live_image_file) Command.run(['mv', self.live_image_file, self.media_dir]) self.__create_live_iso_client_config(self.live_type) else: raise KiwiLiveBootImageError('live ISO type "%s" not supported' % self.live_type) # setup bootloader config to boot the ISO via isolinux log.info('Setting up isolinux bootloader configuration') bootloader_config_isolinux = BootLoaderConfig('isolinux', self.xml_state, self.media_dir) bootloader_config_isolinux.setup_live_boot_images( mbrid=None, lookup_path=self.boot_image_task.boot_root_directory) bootloader_config_isolinux.setup_live_image_config(mbrid=None) bootloader_config_isolinux.write() # setup bootloader config to boot the ISO via EFI if self.firmware.efi_mode(): log.info('Setting up EFI grub bootloader configuration') bootloader_config_grub = BootLoaderConfig('grub2', self.xml_state, self.media_dir) bootloader_config_grub.setup_live_boot_images( mbrid=self.mbrid, lookup_path=self.boot_image_task.boot_root_directory) bootloader_config_grub.setup_live_image_config(mbrid=self.mbrid) bootloader_config_grub.write() # create initrd for live image log.info('Creating live ISO boot image') self.__create_live_iso_kernel_and_initrd() # calculate size and decide if we need UDF if rootsize.accumulate_mbyte_file_sizes() > 4096: log.info('ISO exceeds 4G size, using UDF filesystem') custom_iso_args.append('-allow-limited-size') custom_iso_args.append('-udf') # create iso filesystem from media_dir log.info('Creating live ISO image') iso_image = FileSystemIsoFs(device_provider=None, root_dir=self.media_dir, custom_args=custom_iso_args) iso_header_offset = iso_image.create_on_file(self.isoname) # make it hybrid if self.hybrid: Iso.create_hybrid(iso_header_offset, self.mbrid, self.isoname) self.result.add('live_image', self.isoname) return self.result