def __init__(self, table_type: str, storage_provider: DeviceProvider, start_sector: int = None): # bind the underlaying block device providing class instance # to this object (e.g loop) if present. This is done to guarantee # the correct destructor order when the device should be released. self.storage_provider = storage_provider # list of protected map ids. If used in a custom partitions # setup this will lead to a raise conditition in order to # avoid conflicts with the existing partition layout and its # customizaton capabilities self.protected_map_ids = [ 'root', 'readonly', 'boot', 'prep', 'spare', 'swap', 'efi_csm', 'efi' ] self.partition_map: Dict[str, str] = {} self.public_partition_id_map: Dict[str, str] = {} self.partition_id_map: Dict[str, str] = {} self.is_mapped = False self.partitioner = Partitioner.new(table_type, storage_provider, start_sector) self.table_type = table_type
def process(self): """ reformats raw disk image and its format to a new disk geometry using the qemu tool chain """ self.manual = Help() if self.command_args.get('help') is True: return self.manual.show('kiwi::image::resize') abs_target_dir_path = os.path.abspath( self.command_args['--target-dir']) if self.command_args['--root']: image_root = os.path.abspath( os.path.normpath(self.command_args['--root'])) else: image_root = os.sep.join( [abs_target_dir_path, 'build', 'image-root']) self.load_xml_description(image_root, self.global_args['--kiwi-file']) disk_format = self.xml_state.build_type.get_format() image_format = DiskFormat.new(disk_format or 'raw', self.xml_state, image_root, abs_target_dir_path) if not image_format.has_raw_disk(): raise KiwiImageResizeError( 'no raw disk image {0} found in build results'.format( image_format.diskname)) new_disk_size = StringToSize.to_bytes(self.command_args['--size']) # resize raw disk log.info('Resizing raw disk to {0} bytes'.format(new_disk_size)) resize_result = image_format.resize_raw_disk(new_disk_size) # resize raw disk partition table firmware = FirmWare(self.xml_state) loop_provider = LoopDevice(image_format.diskname) loop_provider.create(overwrite=False) partitioner = Partitioner.new(firmware.get_partition_table_type(), loop_provider) partitioner.resize_table() del loop_provider # resize disk format from resized raw disk if disk_format and resize_result is True: log.info('Creating {0} disk format from resized raw disk'.format( disk_format)) image_format.create_image_format() elif resize_result is False: log.info('Raw disk is already at {0} bytes'.format(new_disk_size))
def __init__(self, table_type, storage_provider, start_sector=None): # bind the underlaying block device providing class instance # to this object (e.g loop) if present. This is done to guarantee # the correct destructor order when the device should be released. self.storage_provider = storage_provider self.partition_map = {} self.public_partition_id_map = {} self.partition_id_map = {} self.is_mapped = False self.partitioner = Partitioner.new(table_type, storage_provider, start_sector) self.table_type = table_type
def __init__( self, table_type: str, storage_provider: DeviceProvider, start_sector: int = None, extended_layout: bool = False ): """ Construct a new Disk layout object :param string table_type: Partition table type name :param object storage_provider: Instance of class based on DeviceProvider :param int start_sector: sector number :param bool extended_layout: If set to true and on msdos table type when creating more than 4 partitions, this will cause the fourth partition to be an extended partition and all following partitions will be placed as logical partitions inside of that extended partition """ # bind the underlaying block device providing class instance # to this object (e.g loop) if present. This is done to guarantee # the correct destructor order when the device should be released. self.storage_provider = storage_provider # list of protected map ids. If used in a custom partitions # setup this will lead to a raise conditition in order to # avoid conflicts with the existing partition layout and its # customizaton capabilities self.protected_map_ids = [ 'root', 'readonly', 'boot', 'prep', 'spare', 'swap', 'efi_csm', 'efi' ] self.partition_map: Dict[str, str] = {} self.public_partition_id_map: Dict[str, str] = {} self.partition_id_map: Dict[str, str] = {} self.is_mapped = False self.partitioner = Partitioner.new( table_type, storage_provider, start_sector, extended_layout ) self.table_type = table_type
def append_unpartitioned_space(self) -> None: """ Extends the raw disk if an unpartitioned area is specified """ if self.unpartitioned_bytes: log.info('Expanding disk with %d bytes of unpartitioned space', self.unpartitioned_bytes) disk_format = DiskFormat.new('raw', self.xml_state, self.root_dir, self.target_dir) disk_format.resize_raw_disk(self.unpartitioned_bytes, append=True) firmware = FirmWare(self.xml_state) loop_provider = LoopDevice(disk_format.diskname) loop_provider.create(overwrite=False) partitioner = Partitioner.new(firmware.get_partition_table_type(), loop_provider) partitioner.resize_table()
def test_partitioner_dasd_with_custom_start_sector(self, mock_dasd): storage_provider = Mock() with self._caplog.at_level(logging.WARNING): Partitioner.new('dasd', storage_provider, 4096) mock_dasd.assert_called_once_with(storage_provider, None, False)
def test_partitioner_dasd(self, mock_dasd): storage_provider = Mock() Partitioner.new('dasd', storage_provider) mock_dasd.assert_called_once_with(storage_provider, None, False)
def test_partitioner_msdos(self, mock_dos): storage_provider = Mock() Partitioner.new('msdos', storage_provider) mock_dos.assert_called_once_with(storage_provider, None, False)
def test_partitioner_gpt(self, mock_gpt): storage_provider = Mock() Partitioner.new('gpt', storage_provider) mock_gpt.assert_called_once_with(storage_provider, None, False)
def test_partitioner_for_arch_not_implemented(self): with raises(KiwiPartitionerSetupError): Partitioner.new('foo', Mock())