kiwi.storage Package

Submodules

kiwi.storage.device_provider Module

class kiwi.storage.device_provider.DeviceProvider[source]

Bases: object

Base class for any class providing storage devices

get_byte_size(device: str) int[source]

Size of device in bytes

Parameters:

device (string) – node name

Returns:

byte value from blockdev

Return type:

int

get_device()[source]

Representation of device nodes

Could provide one ore more devices representing the storage Implementation in specialized device provider class

get_uuid(device: str) str[source]

UUID of device

Parameters:

device (string) – node name

Returns:

UUID from blkid

Return type:

str

is_loop() bool[source]

Check if device provider is loop based

By default this is always False and needs an implementation in the the specialized device provider class

Returns:

True or False

Return type:

bool

kiwi.storage.disk Module

class kiwi.storage.disk.Disk(table_type: str, storage_provider: DeviceProvider, start_sector: int | None = None, extended_layout: bool = False)[source]

Bases: DeviceProvider

Implements storage disk and partition table setup

activate_boot_partition()[source]

Activate boot partition

Note: not all Partitioner instances supports this

create_boot_partition(mbsize: str, clone: int = 0)[source]

Create boot partition

Populates kiwi_BootPart(id) and optional kiwi_BootPartClone(id)

Parameters:
  • mbsize (str) – partition size string

  • clone (int) – create [clone] cop(y/ies) of the boot partition

create_custom_partitions(table_entries: Dict[str, ptable_entry_type]) None[source]

Create partitions from custom data set

table_entries = {
    map_name: ptable_entry_type
}
Parameters:

table (dict) – partition table spec

create_efi_csm_partition(mbsize: str)[source]

Create EFI bios grub partition

Populates kiwi_BiosGrub(id)

Parameters:

mbsize (str) – partition size string

create_efi_partition(mbsize: str)[source]

Create EFI partition

Populates kiwi_EfiPart(id)

Parameters:

mbsize (str) – partition size string

create_hybrid_mbr()[source]

Turn partition table into a hybrid GPT/MBR table

Note: only GPT tables supports this

create_mbr()[source]

Turn partition table into MBR (msdos table)

Note: only GPT tables supports this

create_prep_partition(mbsize: str)[source]

Create prep partition

Populates kiwi_PrepPart(id)

Parameters:

mbsize (str) – partition size string

create_root_lvm_partition(mbsize: str, clone: int = 0)[source]

Create root partition for use with LVM

Populates kiwi_RootPart(id)

Parameters:
  • mbsize (str) – partition size string

  • clone (int) – create [clone] cop(y/ies) of the lvm roo partition

create_root_partition(mbsize: str, clone: int = 0)[source]

Create root partition

Populates kiwi_RootPart(id) and kiwi_BootPart(id) if no extra boot partition is requested

Parameters:
  • mbsize (str) – partition size string

  • clone (int) – create [clone] cop(y/ies) of the root partition

create_root_raid_partition(mbsize: str, clone: int = 0)[source]

Create root partition for use with MD Raid

Populates kiwi_RootPart(id) and kiwi_RaidPart(id) as well as the default raid device node at boot time which is configured to be kiwi_RaidDev(/dev/mdX)

Parameters:
  • mbsize (str) – partition size string

  • clone (int) – create [clone] cop(y/ies) of the raid root partition

create_root_readonly_partition(mbsize: str, clone: int = 0)[source]

Create root readonly partition for use with overlayfs

Populates kiwi_ReadOnlyPart(id), the partition is meant to contain a squashfs readonly filesystem. The partition size should be the size of the squashfs filesystem in order to avoid wasting disk space

Parameters:
  • mbsize (str) – partition size string

  • clone (int) – create [clone] cop(y/ies) of the ro root partition

create_spare_partition(mbsize: str)[source]

Create spare partition for custom use

Populates kiwi_SparePart(id)

Parameters:

mbsize (str) – partition size string

create_swap_partition(mbsize: str)[source]

Create swap partition

Populates kiwi_SwapPart(id)

Parameters:

mbsize (str) – partition size string

gUID

Unified partition UUIDs according to systemd

get_device() Dict[str, MappedDevice][source]

Names of partition devices

Note that the mapping requires an explicit map() call

Returns:

instances of MappedDevice

Return type:

dict

get_discoverable_partition_ids() Dict[str, str][source]

Ask systemd for a list of standardized GUIDs for the current architecture and return them in a dictionary. If there is no such information available an empty dictionary is returned

Returns:

key:value dict from systemd-id128

Return type:

dict

get_public_partition_id_map() Dict[str, str][source]

Populated partition name to number map

is_loop() bool[source]

Check if storage provider is loop based

The information is taken from the storage provider. If the storage provider is loop based the disk is it too

Returns:

True or False

Return type:

bool

map_partitions()[source]

Map/Activate partitions

In order to access the partitions through a device node it is required to map them if the storage provider is loop based

protected_map_ids

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

set_start_sector(start_sector: int)[source]

Set start sector

Note: only effective on DOS tables

storage_provider

the underlaying device provider

wipe()[source]

Zap (destroy) any GPT and MBR data structures if present For DASD disks create a new VTOC table

class kiwi.storage.disk.ptable_entry_type(mbsize, clone, partition_name, partition_type, mountpoint, filesystem)

Bases: tuple

clone: int

Alias for field number 1

filesystem: str

Alias for field number 5

mbsize: int

Alias for field number 0

mountpoint: str

Alias for field number 4

partition_name: str

Alias for field number 2

partition_type: str

Alias for field number 3

kiwi.storage.loop_device Module

class kiwi.storage.loop_device.LoopDevice(filename: str, filesize_mbytes: int | None = None, blocksize_bytes: int | None = None)[source]

Bases: DeviceProvider

Create and manage loop device file for block operations

Parameters:
  • filename (string) – loop file name to create

  • filesize_mbytes (int) – size of the loop file

  • blocksize_bytes (int) – blocksize used in loop driver

create(overwrite: bool = True)[source]

Setup a loop device of the blocksize given in the constructor The file to loop is created with the size specified in the constructor unless an existing one should not be overwritten

Parameters:

overwrite (bool) – overwrite existing file to loop

get_device() str[source]

Device node name

Returns:

device node name

Return type:

str

is_loop() bool[source]

Always True

Returns:

True

Return type:

bool

kiwi.storage.luks_device Module

class kiwi.storage.luks_device.LuksDevice(storage_provider: DeviceProvider)[source]

Bases: DeviceProvider

Implements luks setup on a storage device

Parameters:

storage_provider (object) – Instance of class based on DeviceProvider

create_crypto_luks(passphrase: str, osname: str | None = None, options: list | None = None, keyfile: str = '', randomize: bool = True, root_dir: str = '') None[source]

Create luks device. Please note the passphrase is readable at creation time of this image. Make sure your host system is secure while this process runs

Parameters:
  • passphrase (string) – credentials

  • osname (string) – distribution name to match distribution specific options for cryptsetup

  • options (list) – further cryptsetup options

  • keyfile (string) – file path name file path name which contains an alternative key to unlock the luks device

  • root_dir (string) – root dir path

create_crypttab(filename: str) None[source]

Create crypttab, setting the UUID of the storage device

Parameters:

filename (string) – file path name

static create_random_keyfile(filename: str) None[source]

Create keyfile with random data

Parameters:

filename (string) – file path name

get_device() MappedDevice | None[source]

Instance of MappedDevice providing the luks device

Returns:

mapped luks device

Return type:

MappedDevice

is_loop() bool[source]

Check if storage provider is loop based

Return loop status from base storage provider

Returns:

True or False

Return type:

bool

storage_provider

the underlaying device provider

kiwi.storage.mapped_device Module

class kiwi.storage.mapped_device.MappedDevice(device: str, device_provider: DeviceProvider)[source]

Bases: DeviceProvider

Hold a reference on a single device

Parameters:
  • device_provider (object) – Instance of class based on DeviceProvider

  • device (string) – Device node name

get_device() str[source]

Mapped device node name

Returns:

device node name

Return type:

str

is_loop() bool[source]

Check if storage provider is loop based

Return loop status from base storage provider

Returns:

True or False

Return type:

bool

kiwi.storage.raid_device Module

class kiwi.storage.raid_device.RaidDevice(storage_provider: DeviceProvider)[source]

Bases: DeviceProvider

Implement raid setup on a storage device

Parameters:

storage_provider (object) – Instance of class based on DeviceProvider

create_degraded_raid(raid_level)[source]

Create a raid array in degraded mode with one device missing. This only works in the raid levels 0(striping) and 1(mirroring)

Parameters:

raid_level (string) – raid level name

create_raid_config(filename: str) None[source]

Create mdadm config file from mdadm request

Parameters:

filename (string) – config file name

get_device() MappedDevice | None[source]

Instance of MappedDevice providing the raid device

Returns:

mapped raid device

Return type:

MappedDevice

is_loop() bool[source]

Check if storage provider is loop based

Return loop status from base storage provider

Returns:

True or False

Return type:

bool

storage_provider

the underlaying device provider

kiwi.storage.clone_device Module

class kiwi.storage.clone_device.CloneDevice(source_provider: DeviceProvider, root_dir: str)[source]

Bases: DeviceProvider

Implements device cloning

clone(target_devices: List[DeviceProvider])[source]

Clone source device to target device(s)

Parameters:

target_devices (list) – List of target DeviceProvider instances

kiwi.storage.setup Module

class kiwi.storage.setup.DiskSetup(xml_state: XMLState, root_dir: str)[source]

Bases: object

Implements disk setup methods

Methods from this class provides information required before building a disk image

Parameters:
  • xml_state (object) – Instance of XMLState

  • root_dir (string) – root directory path name

boot_partition_size() int[source]

Size of the boot partition in mbytes

Returns:

boot size mbytes

Return type:

int

static get_boot_label() str[source]

Filesystem Label to use for the boot partition

Returns:

label name

Return type:

str

get_disksize_mbytes(root_clone: int = 0, boot_clone: int = 0) int[source]

Precalculate disk size requirements in mbytes

Parameters:
  • root_clone (int) – root partition gets cloned, N+1 times the size is needed

  • boot_clone (int) – boot partition gets cloned, N+1 times the size is needed

Returns:

disk size mbytes

Return type:

int

static get_efi_label() str[source]

Filesystem Label to use for the EFI partition

Returns:

label name

Return type:

str

get_root_label() str[source]

Filesystem Label to use for the root partition

If not specified in the XML configuration the default root label is set to ‘ROOT’

Returns:

label name

Return type:

str

need_boot_partition()[source]

Decide if an extra boot partition is needed. This is done with the bootpartition attribute from the type, however if it is not set it depends on some other type configuration parameters if we need a boot partition or not

Returns:

True or False

Return type:

bool

Module Contents