kiwi.defaults

   1# Copyright (c) 2015 SUSE Linux GmbH.  All rights reserved.
   2#
   3# This file is part of kiwi.
   4#
   5# kiwi is free software: you can redistribute it and/or modify
   6# it under the terms of the GNU General Public License as published by
   7# the Free Software Foundation, either version 3 of the License, or
   8# (at your option) any later version.
   9#
  10# kiwi is distributed in the hope that it will be useful,
  11# but WITHOUT ANY WARRANTY; without even the implied warranty of
  12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13# GNU General Public License for more details.
  14#
  15# You should have received a copy of the GNU General Public License
  16# along with kiwi.  If not, see <http://www.gnu.org/licenses/>
  17#
  18import logging
  19import os
  20import glob
  21import importlib
  22from importlib.resources import as_file
  23from importlib.util import find_spec
  24from importlib.machinery import ModuleSpec
  25from collections import namedtuple
  26import platform
  27import yaml
  28from typing import (
  29    List, NamedTuple, Optional, Dict
  30)
  31
  32# project
  33from kiwi.path import Path
  34from kiwi.version import (
  35    __githash__,
  36    __version__
  37)
  38
  39from kiwi.exceptions import KiwiBootLoaderGrubDataError
  40
  41shim_loader_type = NamedTuple(
  42    'shim_loader_type', [
  43        ('filename', str),
  44        ('binaryname', str)
  45    ]
  46)
  47
  48grub_loader_type = NamedTuple(
  49    'grub_loader_type', [
  50        ('filename', str),
  51        ('binaryname', str),
  52        ('targetname', str)
  53    ]
  54)
  55
  56unit_type = NamedTuple(
  57    'unit_type', [
  58        ('byte', str),
  59        ('kb', str),
  60        ('mb', str),
  61        ('gb', str)
  62    ]
  63)
  64
  65
  66# Default module variables
  67DM_METADATA_FORMAT_VERSION = '1'
  68DM_METADATA_OFFSET = 4096  # 4kb
  69VERITY_DATA_BLOCKSIZE = 4096  # 4kb
  70VERITY_HASH_BLOCKSIZE = 4096  # 4kb
  71INTEGRITY_SECTOR_SIZE = 512
  72
  73INTEGRITY_ALGORITHM = 'sha256'
  74INTEGRITY_KEY_ALGORITHM = 'hmac-sha256'
  75
  76UNIT = unit_type(byte='b', kb='k', mb='m', gb='g')
  77POST_DISK_SYNC_SCRIPT = 'disk.sh'
  78PRE_DISK_SYNC_SCRIPT = 'pre_disk_sync.sh'
  79POST_BOOTSTRAP_SCRIPT = 'post_bootstrap.sh'
  80POST_PREPARE_SCRIPT = 'config.sh'
  81POST_PREPARE_OVERLAY_SCRIPT = 'config-overlay.sh'
  82POST_HOST_PREPARE_OVERLAY_SCRIPT = 'config-host-overlay.sh'
  83PRE_CREATE_SCRIPT = 'images.sh'
  84EDIT_BOOT_CONFIG_SCRIPT = 'edit_boot_config.sh'
  85EDIT_BOOT_INSTALL_SCRIPT = 'edit_boot_install.sh'
  86IMAGE_METADATA_DIR = 'image'
  87ROOT_VOLUME_NAME = 'LVRoot'
  88SHARED_CACHE_DIR = '/var/cache/kiwi'
  89MODULE_SPEC: Optional[ModuleSpec] = find_spec('kiwi')
  90RUNTIME_CHECKER_METADATA = '{}/runtime_checker_metadata.yml'.format(
  91    os.path.dirname(MODULE_SPEC.origin or 'unknown')
  92) if MODULE_SPEC else 'unknown'
  93
  94TEMP_DIR = '/var/tmp'
  95LOCAL_CONTAINERS = '/var/tmp/kiwi_containers'
  96CUSTOM_RUNTIME_CONFIG_FILE = None
  97ETC_RUNTIME_CONFIG_FILE = '/etc/kiwi.yml'
  98ETC_RUNTIME_CONFIG_DIR = '/etc/kiwi.yml.d'
  99USR_RUNTIME_CONFIG_FILE = '/usr/share/kiwi/kiwi.yml'
 100USR_RUNTIME_CONFIG_DIR = '/usr/share/kiwi/kiwi.yml.d'
 101PLATFORM_MACHINE = platform.machine()
 102EFI_FAT_IMAGE_SIZE = 20
 103
 104# optional package manager environment variables
 105PACKAGE_MANAGER_ENV_VARS = '/.kiwi.package_manager.env'
 106
 107# Distribution specific CA store and tooling
 108CA_UPDATE_MAP = {
 109    'suse': {
 110        'tool': 'update-ca-certificates',
 111        'destination_path': '/etc/pki/trust/anchors'
 112    },
 113    'redhat': {
 114        'tool': 'update-ca-trust',
 115        'destination_path': '/etc/pki/ca-trust/source/anchors/'
 116    },
 117    'debian': {
 118        'tool': 'update-ca-certificates',
 119        'destination_path': '/usr/local/share/ca-certificates/'
 120    },
 121    'archlinux': {
 122        'tool': 'update-ca-trust',
 123        'destination_path': '/etc/ca-certificates/trust-source/anchors/'
 124    }
 125}
 126
 127log = logging.getLogger('kiwi')
 128
 129
 130class Defaults:
 131    """
 132    **Implements default values**
 133
 134    Provides static methods for default values and state information
 135    """
 136
 137    def __init__(self):
 138        self.defaults = {
 139            # alignment in bytes
 140            'kiwi_align': 1048576,
 141            # start sector number
 142            'kiwi_startsector': 2048,
 143            # sectorsize in bytes
 144            'kiwi_sectorsize': 512,
 145            # inode size in bytes for inode based filesystems
 146            'kiwi_inode_size': 256,
 147            # inode ratio for inode based filesystems
 148            'kiwi_inode_ratio': 16384,
 149            # minimum inode number for inode based filesystems
 150            'kiwi_min_inodes': 20000,
 151            # kiwi git revision
 152            'kiwi_revision': __githash__
 153        }
 154        self.profile_key_list = [
 155            'kiwi_align',
 156            'kiwi_startsector',
 157            'kiwi_sectorsize',
 158            'kiwi_revision'
 159        ]
 160
 161    @staticmethod
 162    def get_luks_key_length():
 163        """
 164        Provides key length to use for random luks keys
 165        """
 166        return 256
 167
 168    @staticmethod
 169    def get_swapsize_mbytes():
 170        """
 171        Provides swapsize in MB
 172        """
 173        return 128
 174
 175    @staticmethod
 176    def get_xz_compression_options():
 177        """
 178        Provides compression options for the xz compressor
 179
 180        :return:
 181            Contains list of options
 182
 183            .. code:: python
 184
 185                ['--option=value']
 186
 187        :rtype: list
 188        """
 189        return [
 190            '--threads=0'
 191        ]
 192
 193    @staticmethod
 194    def get_platform_name():
 195        """
 196        Provides the machine architecture name as used by KIWI
 197
 198        This is the architecture name as it is returned by 'uname -m'
 199        with one exception for the 32bit x86 architecture which is
 200        handled as 'ix86' in general
 201
 202        :return: architecture name
 203
 204        :rtype: str
 205        """
 206        arch = PLATFORM_MACHINE
 207        if arch == 'i686' or arch == 'i586':
 208            arch = 'ix86'
 209        return arch
 210
 211    @staticmethod
 212    def set_platform_name(name: str):
 213        """
 214        Sets the platform architecture once
 215
 216        :param str name: an architecture name
 217        """
 218        global PLATFORM_MACHINE
 219        PLATFORM_MACHINE = name
 220
 221    @staticmethod
 222    def is_x86_arch(arch):
 223        """
 224        Checks if machine architecture is x86 based
 225
 226        Any arch that matches 32bit and 64bit x86 architecture
 227        causes the method to return True. Anything else will
 228        cause the method to return False
 229
 230        :rtype: bool
 231        """
 232        x86_arch_names = [
 233            'x86_64', 'i686', 'i586', 'ix86'
 234        ]
 235        if arch in x86_arch_names:
 236            return True
 237        return False
 238
 239    @staticmethod
 240    def is_ppc64_arch(arch):
 241        """
 242        Checks if machine architecture is ppc64 based
 243
 244        Any arch that matches little endian or big endian ppc64 architecture
 245        causes the method to return True. Anything else will
 246        cause the method to return False
 247
 248        :rtype: bool
 249        """
 250        ppc64_arch_names = [
 251            'ppc64', 'ppc64le'
 252        ]
 253        if arch in ppc64_arch_names:
 254            return True
 255        return False
 256
 257    @staticmethod
 258    def is_buildservice_worker():
 259        """
 260        Checks if build host is an open buildservice machine
 261
 262        The presence of /.buildenv on the build host indicates
 263        we are building inside of the open buildservice
 264
 265        :return: True if obs worker, else False
 266
 267        :rtype: bool
 268        """
 269        return os.path.exists(
 270            os.sep + Defaults.get_buildservice_env_name()
 271        )
 272
 273    @staticmethod
 274    def get_buildservice_env_name():
 275        """
 276        Provides the base name of the environment file in a
 277        buildservice worker
 278
 279        :return: file basename
 280
 281        :rtype: str
 282        """
 283        return '.buildenv'
 284
 285    @staticmethod
 286    def get_obs_download_server_url():
 287        """
 288        Provides the default download server url hosting the public open
 289        buildservice repositories
 290
 291        :return: url path
 292
 293        :rtype: str
 294        """
 295        return 'http://download.opensuse.org/repositories'
 296
 297    @staticmethod
 298    def get_obs_api_server_url():
 299        """
 300        Provides the default API server url to access the
 301        public open buildservice API
 302
 303        :return: url path
 304
 305        :rtype: str
 306        """
 307        return 'https://api.opensuse.org'
 308
 309    @staticmethod
 310    def get_solvable_location():
 311        """
 312        Provides the directory to store SAT solvables for repositories.
 313        The solvable files are used to perform package
 314        dependency and metadata resolution
 315
 316        :return: directory path
 317
 318        :rtype: str
 319        """
 320        return '/var/tmp/kiwi/satsolver'
 321
 322    @staticmethod
 323    def set_runtime_checker_metadata(filename):
 324        """
 325        Sets the runtime checker metadata filename
 326
 327        :param str filename: a file path name
 328        """
 329        global RUNTIME_CHECKER_METADATA
 330        RUNTIME_CHECKER_METADATA = filename
 331
 332    @staticmethod
 333    def set_shared_cache_location(location):
 334        """
 335        Sets the shared cache location once
 336
 337        :param str location: a location path
 338        """
 339        global SHARED_CACHE_DIR
 340        SHARED_CACHE_DIR = location
 341
 342    @staticmethod
 343    def set_custom_runtime_config_file(filename):
 344        """
 345        Sets the runtime config file once
 346
 347        :param str filename: a file path name
 348        """
 349        global CUSTOM_RUNTIME_CONFIG_FILE
 350        CUSTOM_RUNTIME_CONFIG_FILE = filename
 351
 352    @staticmethod
 353    def set_temp_location(location):
 354        """
 355        Sets the temp directory location once
 356
 357        :param str location: a location path
 358        """
 359        global TEMP_DIR
 360        TEMP_DIR = location
 361
 362    @staticmethod
 363    def get_shared_cache_location():
 364        """
 365        Provides the shared cache location
 366
 367        This is a directory which shares data from the image buildsystem
 368        host with the image root system. The location is returned as an
 369        absolute path stripped off by the leading '/'. This is because
 370        the path is transparently used on the host /<cache-dir> and
 371        inside of the image imageroot/<cache-dir>
 372
 373        :return: directory path
 374
 375        :rtype: str
 376        """
 377        return os.path.abspath(os.path.normpath(
 378            SHARED_CACHE_DIR
 379        )).lstrip(os.sep)
 380
 381    @staticmethod
 382    def get_temp_location():
 383        """
 384        Provides the base temp directory location
 385
 386        This is the directory used to store any temporary files
 387        and directories created by kiwi during runtime
 388
 389        :return: directory path
 390
 391        :rtype: str
 392        """
 393        return os.path.abspath(
 394            os.path.normpath(TEMP_DIR)
 395        )
 396
 397    @staticmethod
 398    def get_sync_options():
 399        """
 400        Provides list of default data sync options
 401
 402        :return: list of rsync options
 403
 404        :rtype: list
 405        """
 406        return [
 407            '--archive', '--hard-links', '--xattrs', '--acls',
 408            '--one-file-system', '--inplace'
 409        ]
 410
 411    @staticmethod
 412    def get_removed_files_name():
 413        """
 414        Provides base file name to store removed files
 415        in a delta root build
 416        """
 417        return 'removed'
 418
 419    @staticmethod
 420    def get_system_files_name():
 421        """
 422        Provides base file name to store system files
 423        in a container build
 424        """
 425        return 'systemfiles'
 426
 427    @staticmethod
 428    def get_exclude_list_for_removed_files_detection() -> List[str]:
 429        """
 430        Provides list of files/dirs to exclude from the removed
 431        files detection in a delta root build
 432        """
 433        return [
 434            'etc/hosts.kiwi',
 435            'etc/hosts.sha',
 436            'etc/resolv.conf.kiwi',
 437            'etc/resolv.conf.sha',
 438            'etc/sysconfig/proxy.kiwi',
 439            'etc/sysconfig/proxy.sha',
 440            'usr/lib/sysimage/rpm'
 441        ]
 442
 443    @staticmethod
 444    def get_exclude_list_for_root_data_sync(no_tmpdirs: bool = True):
 445        """
 446        Provides the list of files or folders that are created
 447        by KIWI for its own purposes. Those files should be not
 448        be included in the resulting image.
 449
 450        :return: list of file and directory names
 451
 452        :rtype: list
 453        """
 454        exclude_list = [
 455            'image', '.kconfig'
 456        ]
 457        if no_tmpdirs:
 458            exclude_list += ['run/*', 'tmp/*']
 459        exclude_list += [
 460            Defaults.get_buildservice_env_name(),
 461            Defaults.get_shared_cache_location()
 462        ]
 463        return exclude_list
 464
 465    @staticmethod
 466    def get_runtime_checker_metadata() -> Dict:
 467        with open(RUNTIME_CHECKER_METADATA) as meta:
 468            return yaml.safe_load(meta)
 469
 470    @staticmethod
 471    def _parse_exclude_file(root_dir: str, exclude_filename: str) -> List:
 472        """
 473        Retrieves an exclusion list from the provided metadata file
 474
 475        The file should contain a YAML dictionary with a top-level key
 476        named 'exclude' and the list of exclusions as its value.
 477
 478        The list of exclusions may include:
 479            * file paths
 480            * folder paths
 481            * glob patterns
 482
 483        Paths and patterns should be relative to the filesystem or
 484        directory that they're being excluded from.
 485
 486        :return: list of paths and glob patterns
 487
 488        :param string root_dir: image root directory
 489        :param string exclude_filename: file exclusion YAML metadata file
 490
 491        :rtype: list
 492        """
 493        exclude_file = os.sep.join(
 494            [root_dir, 'image', exclude_filename]
 495        )
 496        exclude_list = []
 497        if os.path.isfile(exclude_file):
 498            with open(exclude_file) as exclude:
 499                exclude_dict = yaml.safe_load(exclude)
 500                exclude_data = exclude_dict.get('exclude')
 501                if exclude_data and isinstance(exclude_data, list):
 502                    for exclude_file in exclude_data:
 503                        exclude_list.append(
 504                            exclude_file.lstrip(os.sep)
 505                        )
 506                else:
 507                    log.warning(
 508                        f'invalid yaml structure in {exclude_file}, ignored'
 509                    )
 510        return exclude_list
 511
 512    @staticmethod
 513    def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
 514        """
 515        Gets the list of excluded items for the root filesystem from
 516        the optional metadata file image/exclude_files.yaml
 517
 518        :return: list of paths and glob patterns
 519
 520        :param string root_dir: image root directory
 521
 522        :rtype: list
 523        """
 524        return Defaults._parse_exclude_file(root_dir, 'exclude_files.yaml')
 525
 526    @staticmethod
 527    def get_exclude_list_from_custom_exclude_files_for_efifatimage(root_dir: str) -> List:
 528        """
 529        Gets the list of excluded items for the ESP's EFI folder from
 530        the optional metadata file image/exclude_files_efifatimage.yaml
 531
 532        Excluded items must be relative to the ESP's /EFI directory.
 533
 534        :return: list of paths and glob patterns
 535
 536        :param string root_dir: EFI root directory
 537
 538        :rtype: list
 539        """
 540        return Defaults._parse_exclude_file(root_dir, 'exclude_files_efifatimage.yaml')
 541
 542    @staticmethod
 543    def get_exclude_list_for_non_physical_devices():
 544        """
 545        Provides the list of folders that are not associated
 546        with a physical device. KIWI returns the basename of
 547        the folders typically used as mountpoint for those
 548        devices.
 549
 550        :return: list of file and directory names
 551
 552        :rtype: list
 553        """
 554        exclude_list = [
 555            'proc', 'sys', 'dev'
 556        ]
 557        return exclude_list
 558
 559    @staticmethod
 560    def get_failsafe_kernel_options():
 561        """
 562        Provides failsafe boot kernel options
 563
 564        :return:
 565            list of kernel options
 566
 567            .. code:: python
 568
 569                ['option=value', 'option']
 570
 571        :rtype: list
 572        """
 573        return ' '.join(
 574            [
 575                'ide=nodma',
 576                'apm=off',
 577                'noresume',
 578                'edd=off',
 579                'nomodeset',
 580                '3'
 581            ]
 582        )
 583
 584    @staticmethod
 585    def get_video_mode_map():
 586        """
 587        Provides video mode map
 588
 589        Assign a tuple to each kernel vesa hex id for each of the
 590        supported bootloaders
 591
 592        :return:
 593            video type map
 594
 595            .. code:: python
 596
 597                {'kernel_hex_mode': video_type(grub2='mode')}
 598
 599        :rtype: dict
 600        """
 601        video_type = namedtuple(
 602            'video_type', ['grub2']
 603        )
 604        return {
 605            '0x301': video_type(grub2='640x480'),
 606            '0x310': video_type(grub2='640x480'),
 607            '0x311': video_type(grub2='640x480'),
 608            '0x312': video_type(grub2='640x480'),
 609            '0x303': video_type(grub2='800x600'),
 610            '0x313': video_type(grub2='800x600'),
 611            '0x314': video_type(grub2='800x600'),
 612            '0x315': video_type(grub2='800x600'),
 613            '0x305': video_type(grub2='1024x768'),
 614            '0x316': video_type(grub2='1024x768'),
 615            '0x317': video_type(grub2='1024x768'),
 616            '0x318': video_type(grub2='1024x768'),
 617            '0x307': video_type(grub2='1280x1024'),
 618            '0x319': video_type(grub2='1280x1024'),
 619            '0x31a': video_type(grub2='1280x1024'),
 620            '0x31b': video_type(grub2='1280x1024'),
 621            'auto': video_type(grub2='auto')
 622        }
 623
 624    @staticmethod
 625    def get_volume_id():
 626        """
 627        Provides default value for ISO volume ID
 628
 629        :return: name
 630
 631        :rtype: str
 632        """
 633        return 'CDROM'
 634
 635    @staticmethod
 636    def get_install_volume_id():
 637        """
 638        Provides default value for ISO volume ID for install media
 639
 640        :return: name
 641
 642        :rtype: str
 643        """
 644        return 'INSTALL'
 645
 646    @staticmethod
 647    def get_snapper_config_template_file(root: str) -> str:
 648        """
 649        Provides the default configuration template file for snapper.
 650        The location in etc/ are preferred over files in usr/
 651
 652        :return: file path
 653
 654        :rtype: str
 655        """
 656        snapper_templates = [
 657            'etc/snapper/config-templates/default',
 658            'usr/share/snapper/config-templates/default'
 659        ]
 660        snapper_default_conf = ''
 661        for snapper_template in snapper_templates:
 662            template_config = os.path.join(root, snapper_template)
 663            if os.path.exists(template_config):
 664                snapper_default_conf = template_config
 665                break
 666        return snapper_default_conf
 667
 668    @staticmethod
 669    def get_default_video_mode():
 670        """
 671        Uses auto mode for default video. See get_video_mode_map
 672        for details on the value depending which bootloader is
 673        used
 674
 675        :return: auto
 676
 677        :rtype: str
 678        """
 679        return 'auto'
 680
 681    @staticmethod
 682    def get_default_bootloader():
 683        """
 684        Return default bootloader name which is grub2
 685
 686        :return: bootloader name
 687
 688        :rtype: str
 689        """
 690        return 'grub2'
 691
 692    @staticmethod
 693    def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
 694        return {
 695            'grub_directory_name':
 696                Defaults.get_grub_boot_directory_name(root_dir),
 697            'grub_load_command':
 698                'configfile'
 699        }
 700
 701    @staticmethod
 702    def get_grub_boot_directory_name(lookup_path):
 703        """
 704        Provides grub2 data directory name in boot/ directory
 705
 706        Depending on the distribution the grub2 boot path could be
 707        either boot/grub2 or boot/grub. The method will decide for
 708        the correct base directory name according to the name pattern
 709        of the installed grub2 tools
 710
 711        :return: directory basename
 712
 713        :rtype: str
 714        """
 715        if Path.which(filename='grub2-install', root_dir=lookup_path):
 716            # the presence of grub2-install is an indicator to put all
 717            # grub2 data below boot/grub2
 718            return 'grub2'
 719        else:
 720            # in any other case the assumption is made that all grub
 721            # boot data should live below boot/grub
 722            return 'grub'
 723
 724    @staticmethod
 725    def get_grub_basic_modules(multiboot):
 726        """
 727        Provides list of basic grub modules
 728
 729        :param bool multiboot: grub multiboot mode
 730
 731        :return: list of module names
 732
 733        :rtype: list
 734        """
 735        modules = [
 736            'ext2',
 737            'iso9660',
 738            'linux',
 739            'echo',
 740            'configfile',
 741            'search_label',
 742            'search_fs_file',
 743            'search',
 744            'search_fs_uuid',
 745            'ls',
 746            'normal',
 747            'gzio',
 748            'png',
 749            'fat',
 750            'gettext',
 751            'font',
 752            'minicmd',
 753            'gfxterm',
 754            'gfxmenu',
 755            'all_video',
 756            'xfs',
 757            'btrfs',
 758            'squash4',
 759            'lvm',
 760            'luks',
 761            'gcry_rijndael',
 762            'gcry_sha256',
 763            'gcry_sha512',
 764            'crypto',
 765            'cryptodisk',
 766            'test',
 767            'true',
 768            'loadenv'
 769        ]
 770        if multiboot:
 771            modules.append('multiboot')
 772        return modules
 773
 774    @staticmethod
 775    def get_grub_efi_modules(multiboot=False):
 776        """
 777        Provides list of grub efi modules
 778
 779        :param bool multiboot: grub multiboot mode
 780
 781        :return: list of module names
 782
 783        :rtype: list
 784        """
 785        modules = Defaults.get_grub_basic_modules(multiboot) + [
 786            'part_gpt',
 787            'part_msdos',
 788            'efi_gop'
 789        ]
 790        return modules
 791
 792    @staticmethod
 793    def get_grub_platform_modules(multiboot=False):
 794        """
 795        Provides list of platform specific grub modules
 796
 797        :param bool multiboot: grub multiboot mode
 798
 799        :return: list of module names
 800
 801        :rtype: list
 802        """
 803        modules = Defaults.get_grub_basic_modules(multiboot)
 804        if Defaults.is_ppc64_arch(Defaults.get_platform_name()):
 805            return Defaults.get_grub_ofw_modules()
 806        else:
 807            modules += [
 808                'part_gpt',
 809                'part_msdos',
 810                'biosdisk',
 811                'vga',
 812                'vbe',
 813                'chain',
 814                'boot'
 815            ]
 816        return modules
 817
 818    @staticmethod
 819    def get_grub_ofw_modules():
 820        """
 821        Provides list of grub ofw modules (ppc)
 822
 823        :return: list of module names
 824
 825        :rtype: list
 826        """
 827        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
 828            'part_gpt',
 829            'part_msdos',
 830            'boot'
 831        ]
 832        return modules
 833
 834    @staticmethod
 835    def get_grub_s390_modules():
 836        """
 837        Provides list of grub ofw modules (s390)
 838
 839        :return: list of module names
 840
 841        :rtype: list
 842        """
 843        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
 844            'part_gpt',
 845            'part_msdos',
 846            'boot'
 847        ]
 848        return modules
 849
 850    @staticmethod
 851    def get_grub_path(
 852        root_path: str, filename: str, raise_on_error: bool = True
 853    ) -> str:
 854        """
 855        Provides grub path to given search file
 856
 857        Depending on the distribution grub could be installed below
 858        a grub2 or grub directory. grub could also reside in /usr/lib
 859        as well as in /usr/share. Therefore this information needs
 860        to be dynamically looked up
 861
 862        :param string root_path: root path to start the lookup from
 863        :param string filename: filename to search
 864        :param bool raise_on_error: raise on not found, defaults to True
 865
 866        The method returns the path to the given grub search file.
 867        By default it raises a KiwiBootLoaderGrubDataError exception
 868        if the file could not be found in any of the search locations.
 869        If raise_on_error is set to False and no file could be found
 870        the function returns None
 871
 872        :return: filepath
 873
 874        :rtype: str
 875        """
 876        log.debug(f'Searching grub file: {filename}')
 877        install_dirs = [
 878            'usr/share', 'usr/lib'
 879        ]
 880        lookup_list = []
 881        for grub_name in ['grub2', 'grub']:
 882            for install_dir in install_dirs:
 883                grub_path = os.path.join(
 884                    root_path, install_dir, grub_name, filename
 885                )
 886                log.debug(f'--> {grub_path}')
 887                if os.path.exists(grub_path):
 888                    log.debug(f'--> Found in: {grub_path}')
 889                    return grub_path
 890                lookup_list.append(grub_path)
 891        if raise_on_error:
 892            raise KiwiBootLoaderGrubDataError(
 893                'grub path {0} not found in {1}'.format(filename, lookup_list)
 894            )
 895        return ''
 896
 897    @staticmethod
 898    def get_preparer():
 899        """
 900        Provides ISO preparer name
 901
 902        :return: name
 903
 904        :rtype: str
 905        """
 906        return 'KIWI - https://github.com/OSInside/kiwi'
 907
 908    @staticmethod
 909    def get_publisher():
 910        """
 911        Provides ISO publisher name
 912
 913        :return: name
 914
 915        :rtype: str
 916        """
 917        return 'SUSE LINUX GmbH'
 918
 919    @staticmethod
 920    def get_shim_loader(root_path: str) -> List[shim_loader_type]:
 921        """
 922        Provides shim loader file path
 923
 924        Searches distribution specific locations to find shim.efi
 925        below the given root path
 926
 927        :param string root_path: image root path
 928
 929        :return: list of shim_loader_type
 930
 931        :rtype: list
 932        """
 933        result = []
 934        shim_pattern_type = namedtuple(
 935            'shim_pattern_type', ['pattern', 'binaryname']
 936        )
 937        shim_file_patterns = [
 938            shim_pattern_type(
 939                '/usr/lib/shim/shim*.efi.signed.latest',
 940                'bootx64.efi'
 941            ),
 942            shim_pattern_type(
 943                '/usr/lib/shim/shim*.efi.signed',
 944                'bootx64.efi'
 945            ),
 946            shim_pattern_type(
 947                '/usr/lib/grub/*-efi-signed',
 948                'bootx64.efi'
 949            ),
 950            shim_pattern_type(
 951                '/usr/share/efi/x86_64/shim.efi',
 952                'bootx64.efi'
 953            ),
 954            shim_pattern_type(
 955                '/usr/share/efi/aarch64/shim.efi',
 956                'bootaa64.efi'
 957            ),
 958            shim_pattern_type(
 959                '/usr/lib64/efi/shim.efi',
 960                'bootx64.efi'
 961            ),
 962            shim_pattern_type(
 963                '/boot/efi/EFI/*/shimx64.efi',
 964                'bootx64.efi'
 965            ),
 966            shim_pattern_type(
 967                '/boot/efi/EFI/*/shimia32.efi',
 968                'bootia32.efi'
 969            ),
 970            shim_pattern_type(
 971                '/boot/efi/EFI/*/shimaa64.efi',
 972                'bootaa64.efi'
 973            ),
 974            shim_pattern_type(
 975                '/boot/efi/EFI/*/shimriscv64.efi',
 976                'bootriscv64.efi'
 977            ),
 978            shim_pattern_type(
 979                '/boot/efi/EFI/*/shim.efi',
 980                'bootx64.efi'
 981            ),
 982            shim_pattern_type(
 983                '/usr/lib/shim/shim*.efi',
 984                'bootx64.efi'
 985            )
 986        ]
 987        for shim_file_pattern in shim_file_patterns:
 988            for shim_file in sorted(
 989                glob.iglob(root_path + shim_file_pattern.pattern), key=len
 990            ):
 991                result.append(
 992                    shim_loader_type(shim_file, shim_file_pattern.binaryname)
 993                )
 994                # one match only expected, per pattern
 995                break
 996        return result
 997
 998    @staticmethod
 999    def get_mok_manager(root_path: str) -> List[str]:
1000        """
1001        Provides Mok Manager file path
1002
1003        Searches distribution specific locations to find
1004        the Mok Manager EFI binary
1005
1006        :param str root_path: image root path
1007
1008        :return: file path or None
1009
1010        :rtype: str
1011        """
1012        result = []
1013        mok_manager_file_patterns = [
1014            '/usr/share/efi/*/MokManager.efi',
1015            '/usr/lib64/efi/MokManager.efi',
1016            '/boot/efi/EFI/*/mm*.efi',
1017            '/usr/lib/shim/mm*.efi'
1018        ]
1019        for mok_manager_file_pattern in mok_manager_file_patterns:
1020            for mm_file in glob.iglob(root_path + mok_manager_file_pattern):
1021                result.append(mm_file)
1022        return result
1023
1024    @staticmethod
1025    def get_grub_efi_font_directory(root_path):
1026        """
1027        Provides distribution specific EFI font directory used with grub.
1028
1029        :param string root_path: image root path
1030
1031        :return: file path or None
1032
1033        :rtype: str
1034        """
1035        font_dir_patterns = [
1036            '/boot/efi/EFI/*/fonts'
1037        ]
1038        for font_dir_pattern in font_dir_patterns:
1039            for font_dir in glob.iglob(root_path + font_dir_pattern):
1040                return font_dir
1041
1042    @staticmethod
1043    def get_unsigned_grub_loader(
1044        root_path: str, target_type: str = 'disk'
1045    ) -> List[grub_loader_type]:
1046        """
1047        Provides unsigned grub efi loader file path
1048
1049        Searches distribution specific locations to find a distro
1050        grub EFI binary within the given root path
1051
1052        :param string root_path: image root path
1053
1054        :return: list of grub_loader_type
1055
1056        :rtype: list
1057        """
1058        result = []
1059        grub_pattern_type = namedtuple(
1060            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1061        )
1062        unsigned_grub_file_patterns = {
1063            'disk': [
1064                grub_pattern_type(
1065                    '/usr/share/grub*/x86_64-efi/grub.efi',
1066                    'grub.efi',
1067                    'bootx64.efi'
1068                ),
1069                grub_pattern_type(
1070                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1071                    'grub.efi',
1072                    'bootx64.efi'
1073                ),
1074                grub_pattern_type(
1075                    '/boot/efi/EFI/*/grubx64.efi',
1076                    'grubx64.efi',
1077                    'bootx64.efi'
1078                ),
1079                grub_pattern_type(
1080                    '/boot/efi/EFI/*/grubia32.efi',
1081                    'grubia32.efi',
1082                    'bootia32.efi'
1083                ),
1084                grub_pattern_type(
1085                    '/boot/efi/EFI/*/grubaa64.efi',
1086                    'grubaa64.efi',
1087                    'bootaa64.efi'
1088                ),
1089                grub_pattern_type(
1090                    '/boot/efi/EFI/*/grubriscv64.efi',
1091                    'grubriscv64.efi',
1092                    'bootriscv64.efi'
1093                )
1094            ],
1095            'iso': [
1096                grub_pattern_type(
1097                    '/boot/efi/EFI/*/gcdx64.efi',
1098                    'grubx64.efi',
1099                    'bootx64.efi'
1100                ),
1101                grub_pattern_type(
1102                    '/usr/share/grub*/x86_64-efi/grub.efi',
1103                    'grub.efi',
1104                    'bootx64.efi'
1105                ),
1106                grub_pattern_type(
1107                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1108                    'grub.efi',
1109                    'bootx64.efi'
1110                ),
1111                grub_pattern_type(
1112                    '/boot/efi/EFI/*/grubx64.efi',
1113                    'grubx64.efi',
1114                    'bootx64.efi'
1115                ),
1116                grub_pattern_type(
1117                    '/boot/efi/EFI/*/grubia32.efi',
1118                    'grubia32.efi',
1119                    'bootia32.efi'
1120                ),
1121                grub_pattern_type(
1122                    '/boot/efi/EFI/*/grubaa64.efi',
1123                    'grubaa64.efi',
1124                    'bootaa64.efi'
1125                ),
1126                grub_pattern_type(
1127                    '/boot/efi/EFI/*/grubriscv64.efi',
1128                    'grubriscv64.efi',
1129                    'bootriscv64.efi'
1130                )
1131            ]
1132        }
1133        for unsigned_grub_file_pattern in unsigned_grub_file_patterns[target_type]:
1134            for unsigned_grub_file in glob.iglob(
1135                root_path + unsigned_grub_file_pattern.pattern
1136            ):
1137                result.append(
1138                    grub_loader_type(
1139                        unsigned_grub_file,
1140                        unsigned_grub_file_pattern.binaryname,
1141                        unsigned_grub_file_pattern.targetname
1142                    )
1143                )
1144                # one match only expected, per pattern
1145                break
1146        return result
1147
1148    @staticmethod
1149    def get_grub_chrp_loader(boot_path: str) -> str:
1150        """
1151        Lookup CHRP boot loader (ppc)
1152
1153        :param string boot_path: boot path
1154
1155        :return: file base name
1156
1157        :rtype: str
1158        """
1159        for chrp_loader in ['grub.elf', 'core.elf']:
1160            for grub_chrp in glob.iglob(
1161                os.sep.join(
1162                    [boot_path, 'boot/grub*/powerpc-ieee1275', chrp_loader]
1163                )
1164            ):
1165                log.info(f'Found CHRP loader at: {grub_chrp}')
1166                return os.path.basename(grub_chrp)
1167        raise KiwiBootLoaderGrubDataError(
1168            f'CHRP loader not found in {boot_path}'
1169        )
1170
1171    @staticmethod
1172    def get_grub_platform_core_loader(root_path):
1173        """
1174        Provides grub bios image
1175
1176        Searches distribution specific locations to find the
1177        core bios image below the given root path
1178
1179        :param string root_path: image root path
1180
1181        :return: file path or None
1182
1183        :rtype: str
1184        """
1185        bios_grub_core_patterns = [
1186            '/usr/share/grub*/{0}/{1}'.format(
1187                Defaults.get_grub_platform_module_directory_name(),
1188                Defaults.get_grub_platform_image_name()
1189            ),
1190            '/usr/lib/grub*/{0}/{1}'.format(
1191                Defaults.get_grub_platform_module_directory_name(),
1192                Defaults.get_grub_platform_image_name()
1193            )
1194        ]
1195        for bios_grub_core_pattern in bios_grub_core_patterns:
1196            for bios_grub_core in glob.iglob(
1197                root_path + bios_grub_core_pattern
1198            ):
1199                return bios_grub_core
1200
1201    @staticmethod
1202    def get_iso_grub_loader():
1203        """
1204        Return name of eltorito grub image used as ISO loader
1205
1206        :return: file base name
1207
1208        :rtype: str
1209        """
1210        return 'eltorito.img'
1211
1212    @staticmethod
1213    def get_iso_grub_mbr():
1214        """
1215        Return name of hybrid MBR image used as ISO boot record
1216
1217        :return: file base name
1218
1219        :rtype: str
1220        """
1221        return 'boot_hybrid.img'
1222
1223    @staticmethod
1224    def get_signed_grub_loader(
1225        root_path: str, target_type: str = 'disk'
1226    ) -> List[grub_loader_type]:
1227        """
1228        Provides shim signed grub loader file path
1229
1230        Searches distribution specific locations to find a grub
1231        EFI binary within the given root path
1232
1233        :param str root_path: image root path
1234
1235        :return: list of grub_loader_type
1236
1237        :rtype: list
1238        """
1239        result = []
1240        grub_pattern_type = namedtuple(
1241            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1242        )
1243        signed_grub_file_patterns = {
1244            'disk': [
1245                grub_pattern_type(
1246                    '/usr/share/efi/*/grub.efi',
1247                    'grub.efi',
1248                    'bootx64.efi'
1249                ),
1250                grub_pattern_type(
1251                    '/usr/lib64/efi/grub.efi',
1252                    'grub.efi',
1253                    'bootx64.efi'
1254                ),
1255                grub_pattern_type(
1256                    '/boot/efi/EFI/*/grubx64.efi',
1257                    'grubx64.efi',
1258                    'bootx64.efi'
1259                ),
1260                grub_pattern_type(
1261                    '/boot/efi/EFI/*/grubia32.efi',
1262                    'grubia32.efi',
1263                    'bootia32.efi'
1264                ),
1265                grub_pattern_type(
1266                    '/boot/efi/EFI/*/grubaa64.efi',
1267                    'grubaa64.efi',
1268                    'bootaa64.efi'
1269                ),
1270                grub_pattern_type(
1271                    '/boot/efi/EFI/*/grubriscv64.efi',
1272                    'grubriscv64.efi',
1273                    'bootriscv64.efi'
1274                ),
1275                grub_pattern_type(
1276                    '/usr/share/grub*/*-efi/grub.efi',
1277                    'grub.efi',
1278                    'bootx64.efi'
1279                ),
1280                grub_pattern_type(
1281                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1282                    'grubx64.efi',
1283                    'bootx64.efi'
1284                )
1285            ],
1286            'iso': [
1287                grub_pattern_type(
1288                    '/boot/efi/EFI/*/gcdx64.efi',
1289                    'grubx64.efi',
1290                    'bootx64.efi'
1291                ),
1292                grub_pattern_type(
1293                    '/boot/efi/EFI/*/gcdaa64.efi',
1294                    'grubaa64.efi',
1295                    'bootaa64.efi'
1296                ),
1297                grub_pattern_type(
1298                    '/usr/share/efi/x86_64/grub.efi',
1299                    'grub.efi',
1300                    'grubx64.efi'
1301                ),
1302                grub_pattern_type(
1303                    '/usr/share/efi/aarch64/grub.efi',
1304                    'grub.efi',
1305                    'grubaa64.efi'
1306                ),
1307                grub_pattern_type(
1308                    '/usr/lib64/efi/grub.efi',
1309                    'grub.efi',
1310                    'bootx64.efi'
1311                ),
1312                grub_pattern_type(
1313                    '/boot/efi/EFI/*/grubx64.efi',
1314                    'grubx64.efi',
1315                    'bootx64.efi'
1316                ),
1317                grub_pattern_type(
1318                    '/boot/efi/EFI/*/grubia32.efi',
1319                    'grubia32.efi',
1320                    'bootia32.efi'
1321                ),
1322                grub_pattern_type(
1323                    '/boot/efi/EFI/*/grubaa64.efi',
1324                    'grubaa64.efi',
1325                    'bootaa64.efi'
1326                ),
1327                grub_pattern_type(
1328                    '/boot/efi/EFI/*/grubriscv64.efi',
1329                    'grubriscv64.efi',
1330                    'bootriscv64.efi'
1331                ),
1332                grub_pattern_type(
1333                    '/usr/share/grub*/x86_64-efi/grub.efi',
1334                    'grub.efi',
1335                    'bootx64.efi'
1336                ),
1337                grub_pattern_type(
1338                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1339                    'grubx64.efi',
1340                    'bootx64.efi'
1341                )
1342            ]
1343        }
1344        for signed_grub in signed_grub_file_patterns[target_type]:
1345            for signed_grub_file in glob.iglob(root_path + signed_grub.pattern):
1346                result.append(
1347                    grub_loader_type(
1348                        signed_grub_file,
1349                        signed_grub.binaryname,
1350                        signed_grub.targetname
1351                    )
1352                )
1353                # one match only expected, per pattern
1354                break
1355        return result
1356
1357    @staticmethod
1358    def get_efi_vendor_directory(efi_path):
1359        """
1360        Provides EFI vendor directory if present
1361
1362        Looks up distribution specific EFI vendor directory
1363
1364        :param string root_path: path to efi mountpoint
1365
1366        :return: directory path or None
1367
1368        :rtype: str
1369        """
1370        efi_vendor_directories = [
1371            'EFI/fedora',
1372            'EFI/redhat',
1373            'EFI/centos',
1374            'EFI/almalinux',
1375            'EFI/opensuse',
1376            'EFI/ubuntu',
1377            'EFI/debian'
1378        ]
1379        for efi_vendor_directory in efi_vendor_directories:
1380            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1381            if os.path.exists(efi_vendor_directory):
1382                return efi_vendor_directory
1383
1384    @staticmethod
1385    def get_vendor_grubenv(efi_path):
1386        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1387        if efi_vendor_directory:
1388            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1389            if os.path.exists(grubenv):
1390                return grubenv
1391
1392    @staticmethod
1393    def get_shim_vendor_directory(root_path):
1394        """
1395        Provides shim vendor directory
1396
1397        Searches distribution specific locations to find shim.efi
1398        below the given root path and return the directory name
1399        to the file found
1400
1401        :param string root_path: image root path
1402
1403        :return: directory path or None
1404
1405        :rtype: str
1406        """
1407        shim_vendor_patterns = [
1408            '/boot/efi/EFI/*/shim*.efi',
1409            '/EFI/*/shim*.efi'
1410        ]
1411        for shim_vendor_pattern in shim_vendor_patterns:
1412            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1413                return os.path.dirname(shim_file)
1414
1415    @staticmethod
1416    def get_default_volume_group_name():
1417        """
1418        Provides default LVM volume group name
1419
1420        :return: name
1421
1422        :rtype: str
1423        """
1424        return 'systemVG'
1425
1426    @staticmethod
1427    def get_min_partition_mbytes():
1428        """
1429        Provides default minimum partition size in mbytes
1430
1431        :return: mbsize value
1432
1433        :rtype: int
1434        """
1435        return 10
1436
1437    @staticmethod
1438    def get_min_volume_mbytes(filesystem: str):
1439        """
1440        Provides default minimum LVM volume size in mbytes
1441        per filesystem
1442
1443        :return: mbsize value
1444
1445        :rtype: int
1446        """
1447        if filesystem == 'btrfs':
1448            return 120
1449        elif filesystem == 'xfs':
1450            return 300
1451        else:
1452            return 30
1453
1454    @staticmethod
1455    def get_lvm_overhead_mbytes():
1456        """
1457        Provides empiric LVM overhead size in mbytes
1458
1459        :return: mbsize value
1460
1461        :rtype: int
1462        """
1463        return 80
1464
1465    @staticmethod
1466    def get_default_boot_mbytes():
1467        """
1468        Provides default boot partition size in mbytes
1469
1470        :return: mbsize value
1471
1472        :rtype: int
1473        """
1474        return 300
1475
1476    @staticmethod
1477    def get_default_efi_boot_mbytes():
1478        """
1479        Provides default EFI partition size in mbytes
1480
1481        :return: mbsize value
1482
1483        :rtype: int
1484        """
1485        return 20
1486
1487    @staticmethod
1488    def get_recovery_spare_mbytes():
1489        """
1490        Provides spare size of recovery partition in mbytes
1491
1492        :return: mbsize value
1493
1494        :rtype: int
1495        """
1496        return 300
1497
1498    @staticmethod
1499    def get_default_legacy_bios_mbytes():
1500        """
1501        Provides default size of bios_grub partition in mbytes
1502
1503        :return: mbsize value
1504
1505        :rtype: int
1506        """
1507        return 2
1508
1509    @staticmethod
1510    def get_default_prep_mbytes():
1511        """
1512        Provides default size of prep partition in mbytes
1513
1514        :return: mbsize value
1515
1516        :rtype: int
1517        """
1518        return 8
1519
1520    @staticmethod
1521    def get_disk_format_types():
1522        """
1523        Provides supported disk format types
1524
1525        :return: disk types
1526
1527        :rtype: list
1528        """
1529        return [
1530            'gce',
1531            'qcow2',
1532            'vmdk',
1533            'ova',
1534            'meta',
1535            'vmx',
1536            'vhd',
1537            'vhdx',
1538            'vhdfixed',
1539            'vdi',
1540            'vagrant.libvirt.box',
1541            'vagrant.virtualbox.box',
1542            'oci'
1543        ]
1544
1545    @staticmethod
1546    def get_vagrant_config_virtualbox_guest_additions():
1547        """
1548        Provides the default value for
1549        ``vagrantconfig.virtualbox_guest_additions_present``
1550
1551        :return: whether guest additions are expected to be present in the
1552            vagrant box
1553
1554        :rtype: bool
1555        """
1556        return False
1557
1558    @staticmethod
1559    def get_firmware_types():
1560        """
1561        Provides supported architecture specific firmware types
1562
1563        :return: firmware types per architecture
1564
1565        :rtype: dict
1566        """
1567        return {
1568            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1569            'i586': ['bios'],
1570            'i686': ['bios'],
1571            'ix86': ['bios'],
1572            'aarch64': ['efi', 'uefi'],
1573            'arm64': ['efi', 'uefi'],
1574            'armv5el': ['efi', 'uefi'],
1575            'armv5tel': ['efi', 'uefi'],
1576            'armv6hl': ['efi', 'uefi'],
1577            'armv6l': ['efi', 'uefi'],
1578            'armv7hl': ['efi', 'uefi'],
1579            'armv7l': ['efi', 'uefi'],
1580            'armv8l': ['efi', 'uefi'],
1581            'loongarch64': ['efi', 'uefi'],
1582            'ppc': ['ofw'],
1583            'ppc64': ['ofw', 'opal'],
1584            'ppc64le': ['ofw', 'opal'],
1585            'riscv64': ['efi', 'uefi'],
1586            's390': [],
1587            's390x': []
1588        }
1589
1590    @staticmethod
1591    def get_default_firmware(arch):
1592        """
1593        Provides default firmware for specified architecture
1594
1595        :param string arch: machine architecture name
1596
1597        :return: firmware name
1598
1599        :rtype: str
1600        """
1601        default_firmware = {
1602            'x86_64': 'bios',
1603            'i586': 'bios',
1604            'i686': 'bios',
1605            'ix86': 'bios',
1606            'loongarch64': 'efi',
1607            'ppc': 'ofw',
1608            'ppc64': 'ofw',
1609            'ppc64le': 'ofw',
1610            'arm64': 'efi',
1611            'aarch64': 'efi',
1612            'armv5el': 'efi',
1613            'armv5tel': 'efi',
1614            'armv6hl': 'efi',
1615            'armv6l': 'efi',
1616            'armv7hl': 'efi',
1617            'armv7l': 'efi',
1618            'armv8l': 'efi',
1619            'riscv64': 'efi'
1620        }
1621        if arch in default_firmware:
1622            return default_firmware[arch]
1623
1624    @staticmethod
1625    def get_efi_capable_firmware_names():
1626        """
1627        Provides list of EFI capable firmware names. These are
1628        those for which kiwi supports the creation of an EFI
1629        bootable disk image
1630
1631        :return: firmware names
1632
1633        :rtype: list
1634        """
1635        return ['efi', 'uefi']
1636
1637    @staticmethod
1638    def get_ec2_capable_firmware_names():
1639        """
1640        Provides list of EC2 capable firmware names. These are
1641        those for which kiwi supports the creation of disk images
1642        bootable within the Amazon EC2 public cloud
1643
1644        :return: firmware names
1645
1646        :rtype: list
1647        """
1648        return ['ec2']
1649
1650    @staticmethod
1651    def get_efi_module_directory_name(arch):
1652        """
1653        Provides architecture specific EFI directory name which
1654        stores the EFI binaries for the desired architecture.
1655
1656        :param string arch: machine architecture name
1657
1658        :return: directory name
1659
1660        :rtype: str
1661        """
1662        default_module_directory_names = {
1663            'x86_64': 'x86_64-efi',
1664            'i386': 'i386-efi',
1665
1666            # There is no dedicated xen architecture but there are
1667            # modules provided for xen. Thus we treat it as an
1668            # architecture
1669            'x86_64_xen': 'x86_64-xen',
1670
1671            'aarch64': 'arm64-efi',
1672            'arm64': 'arm64-efi',
1673            'armv5el': 'arm-efi',
1674            'armv5tel': 'arm-efi',
1675            'armv6l': 'arm-efi',
1676            'armv7l': 'arm-efi',
1677            'armv8l': 'arm-efi',
1678            'loongarch64': 'loongarch64-efi',
1679            'riscv64': 'riscv64-efi'
1680        }
1681        if arch in default_module_directory_names:
1682            return default_module_directory_names[arch]
1683
1684    @staticmethod
1685    def get_grub_platform_module_directory_name():
1686        """
1687        Provides grub platform specific directory name which
1688        stores the grub module binaries
1689
1690        :return: directory name
1691
1692        :rtype: str
1693        """
1694        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1695            Defaults.get_platform_name()
1696        ) else 'i386-pc'
1697
1698    @staticmethod
1699    def get_efi_image_name(arch):
1700        """
1701        Provides architecture specific EFI boot binary name
1702
1703        :param string arch: machine architecture name
1704
1705        :return: name
1706
1707        :rtype: str
1708        """
1709        default_efi_image_names = {
1710            'x86_64': 'bootx64.efi',
1711            'i386': 'bootia32.efi',
1712            'aarch64': 'bootaa64.efi',
1713            'arm64': 'bootaa64.efi',
1714            'armv5el': 'bootarm.efi',
1715            'armv5tel': 'bootarm.efi',
1716            'armv6l': 'bootarm.efi',
1717            'armv7l': 'bootarm.efi',
1718            'armv8l': 'bootarm.efi',
1719            'loongarch64': 'bootloongarch64.efi',
1720            'riscv64': 'bootriscv64.efi'
1721        }
1722        if arch in default_efi_image_names:
1723            return default_efi_image_names[arch]
1724
1725    @staticmethod
1726    def get_grub_platform_image_name():
1727        """
1728        Provides platform specific core boot binary name
1729
1730        :return: name
1731
1732        :rtype: str
1733        """
1734        return 'grub.elf' if Defaults.is_ppc64_arch(
1735            Defaults.get_platform_name()
1736        ) else 'core.img'
1737
1738    @staticmethod
1739    def get_default_boot_timeout_seconds():
1740        """
1741        Provides default boot timeout in seconds
1742
1743        :return: seconds
1744
1745        :rtype: int
1746        """
1747        return 10
1748
1749    @staticmethod
1750    def get_default_disk_start_sector():
1751        """
1752        Provides the default initial disk sector for the first disk
1753        partition.
1754
1755        :return: sector value
1756
1757        :rtype: int
1758        """
1759        return Defaults().defaults['kiwi_startsector']
1760
1761    @staticmethod
1762    def get_default_efi_partition_table_type():
1763        """
1764        Provides the default partition table type for efi firmwares.
1765
1766        :return: partition table type name
1767
1768        :rtype: str
1769        """
1770        return 'gpt'
1771
1772    @staticmethod
1773    def get_default_inode_size():
1774        """
1775        Provides default size of inodes in bytes. This is only
1776        relevant for inode based filesystems
1777
1778        :return: bytesize value
1779
1780        :rtype: int
1781        """
1782        return Defaults().defaults['kiwi_inode_size']
1783
1784    @staticmethod
1785    def get_archive_image_types():
1786        """
1787        Provides list of supported archive image types
1788
1789        :return: archive names
1790
1791        :rtype: list
1792        """
1793        return ['tbz', 'cpio']
1794
1795    @staticmethod
1796    def get_container_image_types():
1797        """
1798        Provides list of supported container image types
1799
1800        :return: container names
1801
1802        :rtype: list
1803        """
1804        return ['docker', 'oci', 'appx', 'wsl']
1805
1806    @staticmethod
1807    def get_filesystem_image_types():
1808        """
1809        Provides list of supported filesystem image types
1810
1811        :return: filesystem names
1812
1813        :rtype: list
1814        """
1815        return [
1816            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1817            'xfs', 'fat16', 'fat32', 'erofs'
1818        ]
1819
1820    @staticmethod
1821    def get_default_live_iso_type():
1822        """
1823        Provides default live iso union type
1824
1825        :return: live iso type
1826
1827        :rtype: str
1828        """
1829        return 'overlay'
1830
1831    @staticmethod
1832    def get_default_uri_type():
1833        """
1834        Provides default URI type
1835
1836        Absolute path specifications used in the context of an URI
1837        will apply the specified default mime type
1838
1839        :return: URI mime type
1840
1841        :rtype: str
1842        """
1843        return 'dir:/'
1844
1845    @staticmethod
1846    def get_dracut_conf_name():
1847        """
1848        Provides file path of dracut config file to be used with KIWI
1849
1850        :return: file path name
1851
1852        :rtype: str
1853        """
1854        return '/etc/dracut.conf.d/02-kiwi.conf'
1855
1856    @staticmethod
1857    def get_live_dracut_modules_from_flag(flag_name):
1858        """
1859        Provides flag_name to dracut modules name map
1860
1861        Depending on the value of the flag attribute in the KIWI image
1862        description specific dracut modules need to be selected
1863
1864        :return: dracut module names as list
1865
1866        :rtype: list
1867        """
1868        live_modules = {
1869            'overlay': ['kiwi-live'],
1870            'dmsquash': ['dmsquash-live', 'livenet']
1871        }
1872        if flag_name in live_modules:
1873            return live_modules[flag_name]
1874        else:
1875            return ['kiwi-live']
1876
1877    @staticmethod
1878    def get_default_live_iso_root_filesystem():
1879        """
1880        Provides default live iso root filesystem type
1881
1882        :return: filesystem name
1883
1884        :rtype: str
1885        """
1886        return 'ext4'
1887
1888    @staticmethod
1889    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1890        """
1891        Provides list of boot options passed to the dracut
1892        kiwi-live module to setup persistent writing
1893
1894        :return: list of boot options
1895
1896        :rtype: list
1897        """
1898        live_iso_persistent_boot_options = [
1899            'rd.live.overlay.persistent'
1900        ]
1901        if persistent_filesystem:
1902            live_iso_persistent_boot_options.append(
1903                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1904            )
1905        return live_iso_persistent_boot_options
1906
1907    @staticmethod
1908    def get_disk_image_types():
1909        """
1910        Provides supported disk image types
1911
1912        :return: disk image type names
1913
1914        :rtype: list
1915        """
1916        return ['oem']
1917
1918    @staticmethod
1919    def get_live_image_types():
1920        """
1921        Provides supported live image types
1922
1923        :return: live image type names
1924
1925        :rtype: list
1926        """
1927        return ['iso']
1928
1929    @staticmethod
1930    def get_kis_image_types():
1931        """
1932        Provides supported kis image types
1933
1934        :return: kis image type names
1935
1936        :rtype: list
1937        """
1938        return ['kis', 'pxe']
1939
1940    @staticmethod
1941    def get_enclaves_image_types():
1942        """
1943        Provides supported enclave(initrd-only) image types
1944
1945        :return: enclave image type names
1946
1947        :rtype: list
1948        """
1949        return ['enclave']
1950
1951    @staticmethod
1952    def get_boot_image_description_path():
1953        """
1954        Provides the path to find custom kiwi boot descriptions
1955
1956        :return: directory path
1957
1958        :rtype: str
1959        """
1960        return '/usr/share/kiwi/custom_boot'
1961
1962    @staticmethod
1963    def get_boot_image_strip_file():
1964        """
1965        Provides the file path to bootloader strip metadata.
1966        This file contains information about the files and directories
1967        automatically striped out from the kiwi initrd
1968
1969        :return: file path
1970
1971        :rtype: str
1972        """
1973        return Defaults.project_file('config/strip.xml')
1974
1975    @staticmethod
1976    def get_schema_file():
1977        """
1978        Provides file path to kiwi RelaxNG schema
1979
1980        :return: file path
1981
1982        :rtype: str
1983        """
1984        return Defaults.project_file('schema/kiwi.rng')
1985
1986    @staticmethod
1987    def get_common_functions_file():
1988        """
1989        Provides the file path to config functions metadata.
1990
1991        This file contains bash functions used for system
1992        configuration or in the boot code from the kiwi initrd
1993
1994        :return: file path
1995
1996        :rtype: str
1997        """
1998        return Defaults.project_file('config/functions.sh')
1999
2000    @staticmethod
2001    def get_xsl_stylesheet_file():
2002        """
2003        Provides the file path to the KIWI XSLT style sheets
2004
2005        :return: file path
2006
2007        :rtype: str
2008        """
2009        return Defaults.project_file('xsl/master.xsl')
2010
2011    @staticmethod
2012    def get_schematron_module_name():
2013        """
2014        Provides module name for XML SchemaTron validations
2015
2016        :return: python module name
2017
2018        :rtype: str
2019        """
2020        return 'lxml.isoschematron'
2021
2022    @staticmethod
2023    def project_file(filename):
2024        """
2025        Provides the python module base directory search path
2026
2027        The method uses the importlib.resources.path method to identify
2028        files and directories from the application
2029
2030        :param string filename: relative project file
2031
2032        :return: absolute file path name
2033
2034        :rtype: str
2035        """
2036        with as_file(importlib.resources.files('kiwi')) as path:
2037            return f'{path}/{filename}'
2038
2039    @staticmethod
2040    def get_imported_root_image(root_dir):
2041        """
2042        Provides the path to an imported root system image
2043
2044        If the image description specified a derived_from attribute
2045        the file from this attribute is copied into the root_dir
2046        using the name as provided by this method
2047
2048        :param string root_dir: image root directory
2049
2050        :return: file path name
2051
2052        :rtype: str
2053        """
2054        return os.sep.join([root_dir, 'image', 'imported_root'])
2055
2056    @staticmethod
2057    def get_iso_boot_path():
2058        """
2059        Provides arch specific relative path to boot files
2060        on kiwi iso filesystems
2061
2062        :return: relative path name
2063
2064        :rtype: str
2065        """
2066        return os.sep.join(
2067            ['boot', Defaults.get_platform_name()]
2068        )
2069
2070    @staticmethod
2071    def get_iso_tool_category():
2072        """
2073        Provides default iso tool category
2074
2075        :return: name
2076
2077        :rtype: str
2078        """
2079        return 'xorriso'
2080
2081    @staticmethod
2082    def get_iso_media_tag_tool():
2083        """
2084        Provides default iso media tag tool
2085
2086        :return: name
2087
2088        :rtype: str
2089        """
2090        return 'checkmedia'
2091
2092    @staticmethod
2093    def get_container_compression():
2094        """
2095        Provides default container compression
2096
2097        :return: True
2098
2099        :rtype: bool
2100        """
2101        return True
2102
2103    @staticmethod
2104    def get_default_container_name():
2105        """
2106        Provides the default container name.
2107
2108        :return: name
2109
2110        :rtype: str
2111        """
2112        return 'kiwi-container'
2113
2114    @staticmethod
2115    def get_container_base_image_tag():
2116        """
2117        Provides the tag used to identify base layers during the build
2118        of derived images.
2119
2120        :return: tag
2121
2122        :rtype: str
2123        """
2124        return 'base_layer'
2125
2126    @staticmethod
2127    def get_oci_archive_tool():
2128        """
2129        Provides the default OCI archive tool name.
2130
2131        :return: name
2132
2133        :rtype: str
2134        """
2135        return 'umoci'
2136
2137    @staticmethod
2138    def get_part_mapper_tool():
2139        """
2140        Provides the default partition mapper tool name.
2141
2142        :return: name
2143
2144        :rtype: str
2145        """
2146        host_architecture = Defaults.get_platform_name()
2147        if 's390' in host_architecture:
2148            return 'kpartx'
2149        return 'partx'
2150
2151    @staticmethod
2152    def get_default_container_tag():
2153        """
2154        Provides the default container tag.
2155
2156        :return: tag
2157
2158        :rtype: str
2159        """
2160        return 'latest'
2161
2162    @staticmethod
2163    def get_default_container_subcommand():
2164        """
2165        Provides the default container subcommand.
2166
2167        :return: command as a list of arguments
2168
2169        :rtype: list
2170        """
2171        return ['/bin/bash']
2172
2173    @staticmethod
2174    def get_default_container_created_by():
2175        """
2176        Provides the default 'created by' history entry for containers.
2177
2178        :return: the specific kiwi version used for the build
2179
2180        :rtype: str
2181        """
2182        return 'KIWI {0}'.format(__version__)
2183
2184    @staticmethod
2185    def get_custom_rpm_macros_path():
2186        """
2187        Returns the custom macros directory for the rpm database.
2188
2189        :return: path name
2190
2191        :rtype: str
2192        """
2193        return 'usr/lib/rpm/macros.d'
2194
2195    @staticmethod
2196    def get_custom_rpm_bootstrap_macro_name():
2197        """
2198        Returns the rpm bootstrap macro file name created
2199        in the custom rpm macros path
2200
2201        :return: filename
2202
2203        :rtype: str
2204        """
2205        return 'macros.kiwi-bootstrap-config'
2206
2207    @staticmethod
2208    def get_custom_rpm_image_macro_name():
2209        """
2210        Returns the rpm image macro file name created
2211        in the custom rpm macros path
2212
2213        :return: filename
2214
2215        :rtype: str
2216        """
2217        return 'macros.kiwi-image-config'
2218
2219    @staticmethod
2220    def get_default_package_manager() -> str:
2221        """
2222        Returns the default package manager name if none
2223        is configured in the image description
2224
2225        :return: package manager name
2226
2227        :rtype: str
2228        """
2229        return 'dnf4'
2230
2231    @staticmethod
2232    def get_default_packager_tool(package_manager):
2233        """
2234        Provides the packager tool according to the package manager
2235
2236        :param string package_manager: package manger name
2237
2238        :return: packager tool binary name
2239
2240        :rtype: str
2241        """
2242        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2243        deb_based = ['apt']
2244        if package_manager in rpm_based:
2245            return 'rpm'
2246        elif package_manager in deb_based:
2247            return 'dpkg'
2248        elif package_manager == 'pacman':
2249            return 'pacman'
2250
2251    @staticmethod
2252    def get_discoverable_partition_ids() -> Dict[str, str]:
2253        """
2254        Provides arch specific partition UUIDs as defined
2255        by the UAPI group
2256
2257        :return: partition UUIDs
2258
2259        :rtype: dict
2260        """
2261        arch = Defaults.get_platform_name()
2262        part_uuids_archs = {
2263            'x86_64': {
2264                'root':
2265                    '4f68bce3e8cd4db196e7fbcaf984b709',
2266                'usr':
2267                    '8484680c952148c69c11b0720656f69e',
2268                'usr-verity':
2269                    '77ff5f63e7b64633acf41565b864c0e6'
2270            },
2271            'ix86': {
2272                'root':
2273                    '44479540f29741b29af7d131d5f0458a',
2274                'usr':
2275                    '75250d768cc6458ebd66bd47cc81a812',
2276                'usr-verity':
2277                    '8f461b0d14ee4e819aa9049b6fb97abd'
2278            },
2279            'aarch64': {
2280                'root':
2281                    'b921b0451df041c3af444c6f280d3fae',
2282                'usr':
2283                    'b0e01050ee5f4390949a9101b17104e9',
2284                'usr-verity':
2285                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2286            },
2287            'riscv64': {
2288                'root':
2289                    '72ec70a6cf7440e6bd494bda08e8f224',
2290                'usr':
2291                    'beaec34b8442439ba40b984381ed097d',
2292                'usr-verity':
2293                    '8f1056be9b0547c481d6be53128e5b54'
2294            }
2295        }
2296        part_uuids_arch = part_uuids_archs.get(arch) or {}
2297        return {
2298            'root':
2299                part_uuids_arch.get('root') or '',
2300            'usr':
2301                part_uuids_arch.get('usr') or '',
2302            'usr-verity':
2303                part_uuids_arch.get('usr-verity') or '',
2304            'usr-secondary':
2305                '75250d768cc6458ebd66bd47cc81a812',
2306            'usr-secondary-verity':
2307                '8f461b0d14ee4e819aa9049b6fb97abd',
2308            'esp':
2309                'c12a7328f81f11d2ba4b00a0c93ec93b',
2310            'xbootldr':
2311                'bc13c2ff59e64262a352b275fd6f7172',
2312            'swap':
2313                '0657fd6da4ab43c484e50933c84b4f4f',
2314            'home':
2315                '933ac7e12eb44f13b8440e14e2aef915',
2316            'srv':
2317                '3b8f842520e04f3b907f1a25a76f98e8',
2318            'var':
2319                '4d21b016b53445c2a9fb5c16e091fd2d',
2320            'tmp':
2321                '7ec6f5573bc54acab29316ef5df639d1',
2322            'user-home':
2323                '773f91ef66d449b5bd83d683bf40ad16',
2324            'linux-generic':
2325                '0fc63daf848347728e793d69d8477de4'
2326        }
2327
2328    @staticmethod
2329    def get_bls_loader_entries_dir() -> str:
2330        """
2331        Provide default loader entries directory for BLS loaders
2332
2333        :return: directory name
2334
2335        :rtype: str
2336        """
2337        return '/boot/loader/entries'
2338
2339    @staticmethod
2340    def get_apk_repo_config() -> str:
2341        """
2342        Repository file for apk
2343
2344        :return: file path name
2345
2346        :rtype: str
2347        """
2348        return '/etc/apk/repositories'
2349
2350    @staticmethod
2351    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2352        return CA_UPDATE_MAP.get(target_distribution)
2353
2354    @staticmethod
2355    def get_ca_target_distributions() -> List[str]:
2356        return sorted(CA_UPDATE_MAP.keys())
2357
2358    def get(self, key):
2359        """
2360        Implements get method for profile elements
2361
2362        :param string key: profile keyname
2363
2364        :return: key value
2365
2366        :rtype: str
2367        """
2368        if key in self.defaults:
2369            return self.defaults[key]
2370
2371    @staticmethod
2372    def get_profile_file(root_dir):
2373        """
2374        Return name of profile file for given root directory
2375        """
2376        return root_dir + '/.profile'
2377
2378    def to_profile(self, profile):
2379        """
2380        Implements method to add list of profile keys and their values
2381        to the specified instance of a Profile class
2382
2383        :param object profile: Profile instance
2384        """
2385        for key in sorted(self.profile_key_list):
2386            # Do not apply default values to any variable that was
2387            # already defined in the profile instance.
2388            cur_profile = profile.dot_profile
2389            if key not in cur_profile or cur_profile[key] is None:
2390                profile.add(key, self.get(key))
class shim_loader_type(builtins.tuple):

shim_loader_type(filename, binaryname)

shim_loader_type(filename: str, binaryname: str)

Create new instance of shim_loader_type(filename, binaryname)

filename: str

Alias for field number 0

binaryname: str

Alias for field number 1

class grub_loader_type(builtins.tuple):

grub_loader_type(filename, binaryname, targetname)

grub_loader_type(filename: str, binaryname: str, targetname: str)

Create new instance of grub_loader_type(filename, binaryname, targetname)

filename: str

Alias for field number 0

binaryname: str

Alias for field number 1

targetname: str

Alias for field number 2

class unit_type(builtins.tuple):

unit_type(byte, kb, mb, gb)

unit_type(byte: str, kb: str, mb: str, gb: str)

Create new instance of unit_type(byte, kb, mb, gb)

byte: str

Alias for field number 0

kb: str

Alias for field number 1

mb: str

Alias for field number 2

gb: str

Alias for field number 3

DM_METADATA_FORMAT_VERSION = '1'
DM_METADATA_OFFSET = 4096
VERITY_DATA_BLOCKSIZE = 4096
VERITY_HASH_BLOCKSIZE = 4096
INTEGRITY_SECTOR_SIZE = 512
INTEGRITY_ALGORITHM = 'sha256'
INTEGRITY_KEY_ALGORITHM = 'hmac-sha256'
UNIT = unit_type(byte='b', kb='k', mb='m', gb='g')
POST_DISK_SYNC_SCRIPT = 'disk.sh'
PRE_DISK_SYNC_SCRIPT = 'pre_disk_sync.sh'
POST_BOOTSTRAP_SCRIPT = 'post_bootstrap.sh'
POST_PREPARE_SCRIPT = 'config.sh'
POST_PREPARE_OVERLAY_SCRIPT = 'config-overlay.sh'
POST_HOST_PREPARE_OVERLAY_SCRIPT = 'config-host-overlay.sh'
PRE_CREATE_SCRIPT = 'images.sh'
EDIT_BOOT_CONFIG_SCRIPT = 'edit_boot_config.sh'
EDIT_BOOT_INSTALL_SCRIPT = 'edit_boot_install.sh'
IMAGE_METADATA_DIR = 'image'
ROOT_VOLUME_NAME = 'LVRoot'
SHARED_CACHE_DIR = '/var/cache/kiwi'
MODULE_SPEC: Optional[_frozen_importlib.ModuleSpec] = ModuleSpec(name='kiwi', loader=<_frozen_importlib_external.SourceFileLoader object>, origin='/home/runner/work/kiwi/kiwi/kiwi/__init__.py', submodule_search_locations=['/home/runner/work/kiwi/kiwi/kiwi'])
RUNTIME_CHECKER_METADATA = '/home/runner/work/kiwi/kiwi/kiwi/runtime_checker_metadata.yml'
TEMP_DIR = '/var/tmp'
LOCAL_CONTAINERS = '/var/tmp/kiwi_containers'
CUSTOM_RUNTIME_CONFIG_FILE = None
ETC_RUNTIME_CONFIG_FILE = '/etc/kiwi.yml'
ETC_RUNTIME_CONFIG_DIR = '/etc/kiwi.yml.d'
USR_RUNTIME_CONFIG_FILE = '/usr/share/kiwi/kiwi.yml'
USR_RUNTIME_CONFIG_DIR = '/usr/share/kiwi/kiwi.yml.d'
PLATFORM_MACHINE = 'x86_64'
EFI_FAT_IMAGE_SIZE = 20
PACKAGE_MANAGER_ENV_VARS = '/.kiwi.package_manager.env'
CA_UPDATE_MAP = {'suse': {'tool': 'update-ca-certificates', 'destination_path': '/etc/pki/trust/anchors'}, 'redhat': {'tool': 'update-ca-trust', 'destination_path': '/etc/pki/ca-trust/source/anchors/'}, 'debian': {'tool': 'update-ca-certificates', 'destination_path': '/usr/local/share/ca-certificates/'}, 'archlinux': {'tool': 'update-ca-trust', 'destination_path': '/etc/ca-certificates/trust-source/anchors/'}}
log = <Logger kiwi (DEBUG)>
class Defaults:
 131class Defaults:
 132    """
 133    **Implements default values**
 134
 135    Provides static methods for default values and state information
 136    """
 137
 138    def __init__(self):
 139        self.defaults = {
 140            # alignment in bytes
 141            'kiwi_align': 1048576,
 142            # start sector number
 143            'kiwi_startsector': 2048,
 144            # sectorsize in bytes
 145            'kiwi_sectorsize': 512,
 146            # inode size in bytes for inode based filesystems
 147            'kiwi_inode_size': 256,
 148            # inode ratio for inode based filesystems
 149            'kiwi_inode_ratio': 16384,
 150            # minimum inode number for inode based filesystems
 151            'kiwi_min_inodes': 20000,
 152            # kiwi git revision
 153            'kiwi_revision': __githash__
 154        }
 155        self.profile_key_list = [
 156            'kiwi_align',
 157            'kiwi_startsector',
 158            'kiwi_sectorsize',
 159            'kiwi_revision'
 160        ]
 161
 162    @staticmethod
 163    def get_luks_key_length():
 164        """
 165        Provides key length to use for random luks keys
 166        """
 167        return 256
 168
 169    @staticmethod
 170    def get_swapsize_mbytes():
 171        """
 172        Provides swapsize in MB
 173        """
 174        return 128
 175
 176    @staticmethod
 177    def get_xz_compression_options():
 178        """
 179        Provides compression options for the xz compressor
 180
 181        :return:
 182            Contains list of options
 183
 184            .. code:: python
 185
 186                ['--option=value']
 187
 188        :rtype: list
 189        """
 190        return [
 191            '--threads=0'
 192        ]
 193
 194    @staticmethod
 195    def get_platform_name():
 196        """
 197        Provides the machine architecture name as used by KIWI
 198
 199        This is the architecture name as it is returned by 'uname -m'
 200        with one exception for the 32bit x86 architecture which is
 201        handled as 'ix86' in general
 202
 203        :return: architecture name
 204
 205        :rtype: str
 206        """
 207        arch = PLATFORM_MACHINE
 208        if arch == 'i686' or arch == 'i586':
 209            arch = 'ix86'
 210        return arch
 211
 212    @staticmethod
 213    def set_platform_name(name: str):
 214        """
 215        Sets the platform architecture once
 216
 217        :param str name: an architecture name
 218        """
 219        global PLATFORM_MACHINE
 220        PLATFORM_MACHINE = name
 221
 222    @staticmethod
 223    def is_x86_arch(arch):
 224        """
 225        Checks if machine architecture is x86 based
 226
 227        Any arch that matches 32bit and 64bit x86 architecture
 228        causes the method to return True. Anything else will
 229        cause the method to return False
 230
 231        :rtype: bool
 232        """
 233        x86_arch_names = [
 234            'x86_64', 'i686', 'i586', 'ix86'
 235        ]
 236        if arch in x86_arch_names:
 237            return True
 238        return False
 239
 240    @staticmethod
 241    def is_ppc64_arch(arch):
 242        """
 243        Checks if machine architecture is ppc64 based
 244
 245        Any arch that matches little endian or big endian ppc64 architecture
 246        causes the method to return True. Anything else will
 247        cause the method to return False
 248
 249        :rtype: bool
 250        """
 251        ppc64_arch_names = [
 252            'ppc64', 'ppc64le'
 253        ]
 254        if arch in ppc64_arch_names:
 255            return True
 256        return False
 257
 258    @staticmethod
 259    def is_buildservice_worker():
 260        """
 261        Checks if build host is an open buildservice machine
 262
 263        The presence of /.buildenv on the build host indicates
 264        we are building inside of the open buildservice
 265
 266        :return: True if obs worker, else False
 267
 268        :rtype: bool
 269        """
 270        return os.path.exists(
 271            os.sep + Defaults.get_buildservice_env_name()
 272        )
 273
 274    @staticmethod
 275    def get_buildservice_env_name():
 276        """
 277        Provides the base name of the environment file in a
 278        buildservice worker
 279
 280        :return: file basename
 281
 282        :rtype: str
 283        """
 284        return '.buildenv'
 285
 286    @staticmethod
 287    def get_obs_download_server_url():
 288        """
 289        Provides the default download server url hosting the public open
 290        buildservice repositories
 291
 292        :return: url path
 293
 294        :rtype: str
 295        """
 296        return 'http://download.opensuse.org/repositories'
 297
 298    @staticmethod
 299    def get_obs_api_server_url():
 300        """
 301        Provides the default API server url to access the
 302        public open buildservice API
 303
 304        :return: url path
 305
 306        :rtype: str
 307        """
 308        return 'https://api.opensuse.org'
 309
 310    @staticmethod
 311    def get_solvable_location():
 312        """
 313        Provides the directory to store SAT solvables for repositories.
 314        The solvable files are used to perform package
 315        dependency and metadata resolution
 316
 317        :return: directory path
 318
 319        :rtype: str
 320        """
 321        return '/var/tmp/kiwi/satsolver'
 322
 323    @staticmethod
 324    def set_runtime_checker_metadata(filename):
 325        """
 326        Sets the runtime checker metadata filename
 327
 328        :param str filename: a file path name
 329        """
 330        global RUNTIME_CHECKER_METADATA
 331        RUNTIME_CHECKER_METADATA = filename
 332
 333    @staticmethod
 334    def set_shared_cache_location(location):
 335        """
 336        Sets the shared cache location once
 337
 338        :param str location: a location path
 339        """
 340        global SHARED_CACHE_DIR
 341        SHARED_CACHE_DIR = location
 342
 343    @staticmethod
 344    def set_custom_runtime_config_file(filename):
 345        """
 346        Sets the runtime config file once
 347
 348        :param str filename: a file path name
 349        """
 350        global CUSTOM_RUNTIME_CONFIG_FILE
 351        CUSTOM_RUNTIME_CONFIG_FILE = filename
 352
 353    @staticmethod
 354    def set_temp_location(location):
 355        """
 356        Sets the temp directory location once
 357
 358        :param str location: a location path
 359        """
 360        global TEMP_DIR
 361        TEMP_DIR = location
 362
 363    @staticmethod
 364    def get_shared_cache_location():
 365        """
 366        Provides the shared cache location
 367
 368        This is a directory which shares data from the image buildsystem
 369        host with the image root system. The location is returned as an
 370        absolute path stripped off by the leading '/'. This is because
 371        the path is transparently used on the host /<cache-dir> and
 372        inside of the image imageroot/<cache-dir>
 373
 374        :return: directory path
 375
 376        :rtype: str
 377        """
 378        return os.path.abspath(os.path.normpath(
 379            SHARED_CACHE_DIR
 380        )).lstrip(os.sep)
 381
 382    @staticmethod
 383    def get_temp_location():
 384        """
 385        Provides the base temp directory location
 386
 387        This is the directory used to store any temporary files
 388        and directories created by kiwi during runtime
 389
 390        :return: directory path
 391
 392        :rtype: str
 393        """
 394        return os.path.abspath(
 395            os.path.normpath(TEMP_DIR)
 396        )
 397
 398    @staticmethod
 399    def get_sync_options():
 400        """
 401        Provides list of default data sync options
 402
 403        :return: list of rsync options
 404
 405        :rtype: list
 406        """
 407        return [
 408            '--archive', '--hard-links', '--xattrs', '--acls',
 409            '--one-file-system', '--inplace'
 410        ]
 411
 412    @staticmethod
 413    def get_removed_files_name():
 414        """
 415        Provides base file name to store removed files
 416        in a delta root build
 417        """
 418        return 'removed'
 419
 420    @staticmethod
 421    def get_system_files_name():
 422        """
 423        Provides base file name to store system files
 424        in a container build
 425        """
 426        return 'systemfiles'
 427
 428    @staticmethod
 429    def get_exclude_list_for_removed_files_detection() -> List[str]:
 430        """
 431        Provides list of files/dirs to exclude from the removed
 432        files detection in a delta root build
 433        """
 434        return [
 435            'etc/hosts.kiwi',
 436            'etc/hosts.sha',
 437            'etc/resolv.conf.kiwi',
 438            'etc/resolv.conf.sha',
 439            'etc/sysconfig/proxy.kiwi',
 440            'etc/sysconfig/proxy.sha',
 441            'usr/lib/sysimage/rpm'
 442        ]
 443
 444    @staticmethod
 445    def get_exclude_list_for_root_data_sync(no_tmpdirs: bool = True):
 446        """
 447        Provides the list of files or folders that are created
 448        by KIWI for its own purposes. Those files should be not
 449        be included in the resulting image.
 450
 451        :return: list of file and directory names
 452
 453        :rtype: list
 454        """
 455        exclude_list = [
 456            'image', '.kconfig'
 457        ]
 458        if no_tmpdirs:
 459            exclude_list += ['run/*', 'tmp/*']
 460        exclude_list += [
 461            Defaults.get_buildservice_env_name(),
 462            Defaults.get_shared_cache_location()
 463        ]
 464        return exclude_list
 465
 466    @staticmethod
 467    def get_runtime_checker_metadata() -> Dict:
 468        with open(RUNTIME_CHECKER_METADATA) as meta:
 469            return yaml.safe_load(meta)
 470
 471    @staticmethod
 472    def _parse_exclude_file(root_dir: str, exclude_filename: str) -> List:
 473        """
 474        Retrieves an exclusion list from the provided metadata file
 475
 476        The file should contain a YAML dictionary with a top-level key
 477        named 'exclude' and the list of exclusions as its value.
 478
 479        The list of exclusions may include:
 480            * file paths
 481            * folder paths
 482            * glob patterns
 483
 484        Paths and patterns should be relative to the filesystem or
 485        directory that they're being excluded from.
 486
 487        :return: list of paths and glob patterns
 488
 489        :param string root_dir: image root directory
 490        :param string exclude_filename: file exclusion YAML metadata file
 491
 492        :rtype: list
 493        """
 494        exclude_file = os.sep.join(
 495            [root_dir, 'image', exclude_filename]
 496        )
 497        exclude_list = []
 498        if os.path.isfile(exclude_file):
 499            with open(exclude_file) as exclude:
 500                exclude_dict = yaml.safe_load(exclude)
 501                exclude_data = exclude_dict.get('exclude')
 502                if exclude_data and isinstance(exclude_data, list):
 503                    for exclude_file in exclude_data:
 504                        exclude_list.append(
 505                            exclude_file.lstrip(os.sep)
 506                        )
 507                else:
 508                    log.warning(
 509                        f'invalid yaml structure in {exclude_file}, ignored'
 510                    )
 511        return exclude_list
 512
 513    @staticmethod
 514    def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
 515        """
 516        Gets the list of excluded items for the root filesystem from
 517        the optional metadata file image/exclude_files.yaml
 518
 519        :return: list of paths and glob patterns
 520
 521        :param string root_dir: image root directory
 522
 523        :rtype: list
 524        """
 525        return Defaults._parse_exclude_file(root_dir, 'exclude_files.yaml')
 526
 527    @staticmethod
 528    def get_exclude_list_from_custom_exclude_files_for_efifatimage(root_dir: str) -> List:
 529        """
 530        Gets the list of excluded items for the ESP's EFI folder from
 531        the optional metadata file image/exclude_files_efifatimage.yaml
 532
 533        Excluded items must be relative to the ESP's /EFI directory.
 534
 535        :return: list of paths and glob patterns
 536
 537        :param string root_dir: EFI root directory
 538
 539        :rtype: list
 540        """
 541        return Defaults._parse_exclude_file(root_dir, 'exclude_files_efifatimage.yaml')
 542
 543    @staticmethod
 544    def get_exclude_list_for_non_physical_devices():
 545        """
 546        Provides the list of folders that are not associated
 547        with a physical device. KIWI returns the basename of
 548        the folders typically used as mountpoint for those
 549        devices.
 550
 551        :return: list of file and directory names
 552
 553        :rtype: list
 554        """
 555        exclude_list = [
 556            'proc', 'sys', 'dev'
 557        ]
 558        return exclude_list
 559
 560    @staticmethod
 561    def get_failsafe_kernel_options():
 562        """
 563        Provides failsafe boot kernel options
 564
 565        :return:
 566            list of kernel options
 567
 568            .. code:: python
 569
 570                ['option=value', 'option']
 571
 572        :rtype: list
 573        """
 574        return ' '.join(
 575            [
 576                'ide=nodma',
 577                'apm=off',
 578                'noresume',
 579                'edd=off',
 580                'nomodeset',
 581                '3'
 582            ]
 583        )
 584
 585    @staticmethod
 586    def get_video_mode_map():
 587        """
 588        Provides video mode map
 589
 590        Assign a tuple to each kernel vesa hex id for each of the
 591        supported bootloaders
 592
 593        :return:
 594            video type map
 595
 596            .. code:: python
 597
 598                {'kernel_hex_mode': video_type(grub2='mode')}
 599
 600        :rtype: dict
 601        """
 602        video_type = namedtuple(
 603            'video_type', ['grub2']
 604        )
 605        return {
 606            '0x301': video_type(grub2='640x480'),
 607            '0x310': video_type(grub2='640x480'),
 608            '0x311': video_type(grub2='640x480'),
 609            '0x312': video_type(grub2='640x480'),
 610            '0x303': video_type(grub2='800x600'),
 611            '0x313': video_type(grub2='800x600'),
 612            '0x314': video_type(grub2='800x600'),
 613            '0x315': video_type(grub2='800x600'),
 614            '0x305': video_type(grub2='1024x768'),
 615            '0x316': video_type(grub2='1024x768'),
 616            '0x317': video_type(grub2='1024x768'),
 617            '0x318': video_type(grub2='1024x768'),
 618            '0x307': video_type(grub2='1280x1024'),
 619            '0x319': video_type(grub2='1280x1024'),
 620            '0x31a': video_type(grub2='1280x1024'),
 621            '0x31b': video_type(grub2='1280x1024'),
 622            'auto': video_type(grub2='auto')
 623        }
 624
 625    @staticmethod
 626    def get_volume_id():
 627        """
 628        Provides default value for ISO volume ID
 629
 630        :return: name
 631
 632        :rtype: str
 633        """
 634        return 'CDROM'
 635
 636    @staticmethod
 637    def get_install_volume_id():
 638        """
 639        Provides default value for ISO volume ID for install media
 640
 641        :return: name
 642
 643        :rtype: str
 644        """
 645        return 'INSTALL'
 646
 647    @staticmethod
 648    def get_snapper_config_template_file(root: str) -> str:
 649        """
 650        Provides the default configuration template file for snapper.
 651        The location in etc/ are preferred over files in usr/
 652
 653        :return: file path
 654
 655        :rtype: str
 656        """
 657        snapper_templates = [
 658            'etc/snapper/config-templates/default',
 659            'usr/share/snapper/config-templates/default'
 660        ]
 661        snapper_default_conf = ''
 662        for snapper_template in snapper_templates:
 663            template_config = os.path.join(root, snapper_template)
 664            if os.path.exists(template_config):
 665                snapper_default_conf = template_config
 666                break
 667        return snapper_default_conf
 668
 669    @staticmethod
 670    def get_default_video_mode():
 671        """
 672        Uses auto mode for default video. See get_video_mode_map
 673        for details on the value depending which bootloader is
 674        used
 675
 676        :return: auto
 677
 678        :rtype: str
 679        """
 680        return 'auto'
 681
 682    @staticmethod
 683    def get_default_bootloader():
 684        """
 685        Return default bootloader name which is grub2
 686
 687        :return: bootloader name
 688
 689        :rtype: str
 690        """
 691        return 'grub2'
 692
 693    @staticmethod
 694    def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
 695        return {
 696            'grub_directory_name':
 697                Defaults.get_grub_boot_directory_name(root_dir),
 698            'grub_load_command':
 699                'configfile'
 700        }
 701
 702    @staticmethod
 703    def get_grub_boot_directory_name(lookup_path):
 704        """
 705        Provides grub2 data directory name in boot/ directory
 706
 707        Depending on the distribution the grub2 boot path could be
 708        either boot/grub2 or boot/grub. The method will decide for
 709        the correct base directory name according to the name pattern
 710        of the installed grub2 tools
 711
 712        :return: directory basename
 713
 714        :rtype: str
 715        """
 716        if Path.which(filename='grub2-install', root_dir=lookup_path):
 717            # the presence of grub2-install is an indicator to put all
 718            # grub2 data below boot/grub2
 719            return 'grub2'
 720        else:
 721            # in any other case the assumption is made that all grub
 722            # boot data should live below boot/grub
 723            return 'grub'
 724
 725    @staticmethod
 726    def get_grub_basic_modules(multiboot):
 727        """
 728        Provides list of basic grub modules
 729
 730        :param bool multiboot: grub multiboot mode
 731
 732        :return: list of module names
 733
 734        :rtype: list
 735        """
 736        modules = [
 737            'ext2',
 738            'iso9660',
 739            'linux',
 740            'echo',
 741            'configfile',
 742            'search_label',
 743            'search_fs_file',
 744            'search',
 745            'search_fs_uuid',
 746            'ls',
 747            'normal',
 748            'gzio',
 749            'png',
 750            'fat',
 751            'gettext',
 752            'font',
 753            'minicmd',
 754            'gfxterm',
 755            'gfxmenu',
 756            'all_video',
 757            'xfs',
 758            'btrfs',
 759            'squash4',
 760            'lvm',
 761            'luks',
 762            'gcry_rijndael',
 763            'gcry_sha256',
 764            'gcry_sha512',
 765            'crypto',
 766            'cryptodisk',
 767            'test',
 768            'true',
 769            'loadenv'
 770        ]
 771        if multiboot:
 772            modules.append('multiboot')
 773        return modules
 774
 775    @staticmethod
 776    def get_grub_efi_modules(multiboot=False):
 777        """
 778        Provides list of grub efi modules
 779
 780        :param bool multiboot: grub multiboot mode
 781
 782        :return: list of module names
 783
 784        :rtype: list
 785        """
 786        modules = Defaults.get_grub_basic_modules(multiboot) + [
 787            'part_gpt',
 788            'part_msdos',
 789            'efi_gop'
 790        ]
 791        return modules
 792
 793    @staticmethod
 794    def get_grub_platform_modules(multiboot=False):
 795        """
 796        Provides list of platform specific grub modules
 797
 798        :param bool multiboot: grub multiboot mode
 799
 800        :return: list of module names
 801
 802        :rtype: list
 803        """
 804        modules = Defaults.get_grub_basic_modules(multiboot)
 805        if Defaults.is_ppc64_arch(Defaults.get_platform_name()):
 806            return Defaults.get_grub_ofw_modules()
 807        else:
 808            modules += [
 809                'part_gpt',
 810                'part_msdos',
 811                'biosdisk',
 812                'vga',
 813                'vbe',
 814                'chain',
 815                'boot'
 816            ]
 817        return modules
 818
 819    @staticmethod
 820    def get_grub_ofw_modules():
 821        """
 822        Provides list of grub ofw modules (ppc)
 823
 824        :return: list of module names
 825
 826        :rtype: list
 827        """
 828        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
 829            'part_gpt',
 830            'part_msdos',
 831            'boot'
 832        ]
 833        return modules
 834
 835    @staticmethod
 836    def get_grub_s390_modules():
 837        """
 838        Provides list of grub ofw modules (s390)
 839
 840        :return: list of module names
 841
 842        :rtype: list
 843        """
 844        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
 845            'part_gpt',
 846            'part_msdos',
 847            'boot'
 848        ]
 849        return modules
 850
 851    @staticmethod
 852    def get_grub_path(
 853        root_path: str, filename: str, raise_on_error: bool = True
 854    ) -> str:
 855        """
 856        Provides grub path to given search file
 857
 858        Depending on the distribution grub could be installed below
 859        a grub2 or grub directory. grub could also reside in /usr/lib
 860        as well as in /usr/share. Therefore this information needs
 861        to be dynamically looked up
 862
 863        :param string root_path: root path to start the lookup from
 864        :param string filename: filename to search
 865        :param bool raise_on_error: raise on not found, defaults to True
 866
 867        The method returns the path to the given grub search file.
 868        By default it raises a KiwiBootLoaderGrubDataError exception
 869        if the file could not be found in any of the search locations.
 870        If raise_on_error is set to False and no file could be found
 871        the function returns None
 872
 873        :return: filepath
 874
 875        :rtype: str
 876        """
 877        log.debug(f'Searching grub file: {filename}')
 878        install_dirs = [
 879            'usr/share', 'usr/lib'
 880        ]
 881        lookup_list = []
 882        for grub_name in ['grub2', 'grub']:
 883            for install_dir in install_dirs:
 884                grub_path = os.path.join(
 885                    root_path, install_dir, grub_name, filename
 886                )
 887                log.debug(f'--> {grub_path}')
 888                if os.path.exists(grub_path):
 889                    log.debug(f'--> Found in: {grub_path}')
 890                    return grub_path
 891                lookup_list.append(grub_path)
 892        if raise_on_error:
 893            raise KiwiBootLoaderGrubDataError(
 894                'grub path {0} not found in {1}'.format(filename, lookup_list)
 895            )
 896        return ''
 897
 898    @staticmethod
 899    def get_preparer():
 900        """
 901        Provides ISO preparer name
 902
 903        :return: name
 904
 905        :rtype: str
 906        """
 907        return 'KIWI - https://github.com/OSInside/kiwi'
 908
 909    @staticmethod
 910    def get_publisher():
 911        """
 912        Provides ISO publisher name
 913
 914        :return: name
 915
 916        :rtype: str
 917        """
 918        return 'SUSE LINUX GmbH'
 919
 920    @staticmethod
 921    def get_shim_loader(root_path: str) -> List[shim_loader_type]:
 922        """
 923        Provides shim loader file path
 924
 925        Searches distribution specific locations to find shim.efi
 926        below the given root path
 927
 928        :param string root_path: image root path
 929
 930        :return: list of shim_loader_type
 931
 932        :rtype: list
 933        """
 934        result = []
 935        shim_pattern_type = namedtuple(
 936            'shim_pattern_type', ['pattern', 'binaryname']
 937        )
 938        shim_file_patterns = [
 939            shim_pattern_type(
 940                '/usr/lib/shim/shim*.efi.signed.latest',
 941                'bootx64.efi'
 942            ),
 943            shim_pattern_type(
 944                '/usr/lib/shim/shim*.efi.signed',
 945                'bootx64.efi'
 946            ),
 947            shim_pattern_type(
 948                '/usr/lib/grub/*-efi-signed',
 949                'bootx64.efi'
 950            ),
 951            shim_pattern_type(
 952                '/usr/share/efi/x86_64/shim.efi',
 953                'bootx64.efi'
 954            ),
 955            shim_pattern_type(
 956                '/usr/share/efi/aarch64/shim.efi',
 957                'bootaa64.efi'
 958            ),
 959            shim_pattern_type(
 960                '/usr/lib64/efi/shim.efi',
 961                'bootx64.efi'
 962            ),
 963            shim_pattern_type(
 964                '/boot/efi/EFI/*/shimx64.efi',
 965                'bootx64.efi'
 966            ),
 967            shim_pattern_type(
 968                '/boot/efi/EFI/*/shimia32.efi',
 969                'bootia32.efi'
 970            ),
 971            shim_pattern_type(
 972                '/boot/efi/EFI/*/shimaa64.efi',
 973                'bootaa64.efi'
 974            ),
 975            shim_pattern_type(
 976                '/boot/efi/EFI/*/shimriscv64.efi',
 977                'bootriscv64.efi'
 978            ),
 979            shim_pattern_type(
 980                '/boot/efi/EFI/*/shim.efi',
 981                'bootx64.efi'
 982            ),
 983            shim_pattern_type(
 984                '/usr/lib/shim/shim*.efi',
 985                'bootx64.efi'
 986            )
 987        ]
 988        for shim_file_pattern in shim_file_patterns:
 989            for shim_file in sorted(
 990                glob.iglob(root_path + shim_file_pattern.pattern), key=len
 991            ):
 992                result.append(
 993                    shim_loader_type(shim_file, shim_file_pattern.binaryname)
 994                )
 995                # one match only expected, per pattern
 996                break
 997        return result
 998
 999    @staticmethod
1000    def get_mok_manager(root_path: str) -> List[str]:
1001        """
1002        Provides Mok Manager file path
1003
1004        Searches distribution specific locations to find
1005        the Mok Manager EFI binary
1006
1007        :param str root_path: image root path
1008
1009        :return: file path or None
1010
1011        :rtype: str
1012        """
1013        result = []
1014        mok_manager_file_patterns = [
1015            '/usr/share/efi/*/MokManager.efi',
1016            '/usr/lib64/efi/MokManager.efi',
1017            '/boot/efi/EFI/*/mm*.efi',
1018            '/usr/lib/shim/mm*.efi'
1019        ]
1020        for mok_manager_file_pattern in mok_manager_file_patterns:
1021            for mm_file in glob.iglob(root_path + mok_manager_file_pattern):
1022                result.append(mm_file)
1023        return result
1024
1025    @staticmethod
1026    def get_grub_efi_font_directory(root_path):
1027        """
1028        Provides distribution specific EFI font directory used with grub.
1029
1030        :param string root_path: image root path
1031
1032        :return: file path or None
1033
1034        :rtype: str
1035        """
1036        font_dir_patterns = [
1037            '/boot/efi/EFI/*/fonts'
1038        ]
1039        for font_dir_pattern in font_dir_patterns:
1040            for font_dir in glob.iglob(root_path + font_dir_pattern):
1041                return font_dir
1042
1043    @staticmethod
1044    def get_unsigned_grub_loader(
1045        root_path: str, target_type: str = 'disk'
1046    ) -> List[grub_loader_type]:
1047        """
1048        Provides unsigned grub efi loader file path
1049
1050        Searches distribution specific locations to find a distro
1051        grub EFI binary within the given root path
1052
1053        :param string root_path: image root path
1054
1055        :return: list of grub_loader_type
1056
1057        :rtype: list
1058        """
1059        result = []
1060        grub_pattern_type = namedtuple(
1061            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1062        )
1063        unsigned_grub_file_patterns = {
1064            'disk': [
1065                grub_pattern_type(
1066                    '/usr/share/grub*/x86_64-efi/grub.efi',
1067                    'grub.efi',
1068                    'bootx64.efi'
1069                ),
1070                grub_pattern_type(
1071                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1072                    'grub.efi',
1073                    'bootx64.efi'
1074                ),
1075                grub_pattern_type(
1076                    '/boot/efi/EFI/*/grubx64.efi',
1077                    'grubx64.efi',
1078                    'bootx64.efi'
1079                ),
1080                grub_pattern_type(
1081                    '/boot/efi/EFI/*/grubia32.efi',
1082                    'grubia32.efi',
1083                    'bootia32.efi'
1084                ),
1085                grub_pattern_type(
1086                    '/boot/efi/EFI/*/grubaa64.efi',
1087                    'grubaa64.efi',
1088                    'bootaa64.efi'
1089                ),
1090                grub_pattern_type(
1091                    '/boot/efi/EFI/*/grubriscv64.efi',
1092                    'grubriscv64.efi',
1093                    'bootriscv64.efi'
1094                )
1095            ],
1096            'iso': [
1097                grub_pattern_type(
1098                    '/boot/efi/EFI/*/gcdx64.efi',
1099                    'grubx64.efi',
1100                    'bootx64.efi'
1101                ),
1102                grub_pattern_type(
1103                    '/usr/share/grub*/x86_64-efi/grub.efi',
1104                    'grub.efi',
1105                    'bootx64.efi'
1106                ),
1107                grub_pattern_type(
1108                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1109                    'grub.efi',
1110                    'bootx64.efi'
1111                ),
1112                grub_pattern_type(
1113                    '/boot/efi/EFI/*/grubx64.efi',
1114                    'grubx64.efi',
1115                    'bootx64.efi'
1116                ),
1117                grub_pattern_type(
1118                    '/boot/efi/EFI/*/grubia32.efi',
1119                    'grubia32.efi',
1120                    'bootia32.efi'
1121                ),
1122                grub_pattern_type(
1123                    '/boot/efi/EFI/*/grubaa64.efi',
1124                    'grubaa64.efi',
1125                    'bootaa64.efi'
1126                ),
1127                grub_pattern_type(
1128                    '/boot/efi/EFI/*/grubriscv64.efi',
1129                    'grubriscv64.efi',
1130                    'bootriscv64.efi'
1131                )
1132            ]
1133        }
1134        for unsigned_grub_file_pattern in unsigned_grub_file_patterns[target_type]:
1135            for unsigned_grub_file in glob.iglob(
1136                root_path + unsigned_grub_file_pattern.pattern
1137            ):
1138                result.append(
1139                    grub_loader_type(
1140                        unsigned_grub_file,
1141                        unsigned_grub_file_pattern.binaryname,
1142                        unsigned_grub_file_pattern.targetname
1143                    )
1144                )
1145                # one match only expected, per pattern
1146                break
1147        return result
1148
1149    @staticmethod
1150    def get_grub_chrp_loader(boot_path: str) -> str:
1151        """
1152        Lookup CHRP boot loader (ppc)
1153
1154        :param string boot_path: boot path
1155
1156        :return: file base name
1157
1158        :rtype: str
1159        """
1160        for chrp_loader in ['grub.elf', 'core.elf']:
1161            for grub_chrp in glob.iglob(
1162                os.sep.join(
1163                    [boot_path, 'boot/grub*/powerpc-ieee1275', chrp_loader]
1164                )
1165            ):
1166                log.info(f'Found CHRP loader at: {grub_chrp}')
1167                return os.path.basename(grub_chrp)
1168        raise KiwiBootLoaderGrubDataError(
1169            f'CHRP loader not found in {boot_path}'
1170        )
1171
1172    @staticmethod
1173    def get_grub_platform_core_loader(root_path):
1174        """
1175        Provides grub bios image
1176
1177        Searches distribution specific locations to find the
1178        core bios image below the given root path
1179
1180        :param string root_path: image root path
1181
1182        :return: file path or None
1183
1184        :rtype: str
1185        """
1186        bios_grub_core_patterns = [
1187            '/usr/share/grub*/{0}/{1}'.format(
1188                Defaults.get_grub_platform_module_directory_name(),
1189                Defaults.get_grub_platform_image_name()
1190            ),
1191            '/usr/lib/grub*/{0}/{1}'.format(
1192                Defaults.get_grub_platform_module_directory_name(),
1193                Defaults.get_grub_platform_image_name()
1194            )
1195        ]
1196        for bios_grub_core_pattern in bios_grub_core_patterns:
1197            for bios_grub_core in glob.iglob(
1198                root_path + bios_grub_core_pattern
1199            ):
1200                return bios_grub_core
1201
1202    @staticmethod
1203    def get_iso_grub_loader():
1204        """
1205        Return name of eltorito grub image used as ISO loader
1206
1207        :return: file base name
1208
1209        :rtype: str
1210        """
1211        return 'eltorito.img'
1212
1213    @staticmethod
1214    def get_iso_grub_mbr():
1215        """
1216        Return name of hybrid MBR image used as ISO boot record
1217
1218        :return: file base name
1219
1220        :rtype: str
1221        """
1222        return 'boot_hybrid.img'
1223
1224    @staticmethod
1225    def get_signed_grub_loader(
1226        root_path: str, target_type: str = 'disk'
1227    ) -> List[grub_loader_type]:
1228        """
1229        Provides shim signed grub loader file path
1230
1231        Searches distribution specific locations to find a grub
1232        EFI binary within the given root path
1233
1234        :param str root_path: image root path
1235
1236        :return: list of grub_loader_type
1237
1238        :rtype: list
1239        """
1240        result = []
1241        grub_pattern_type = namedtuple(
1242            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1243        )
1244        signed_grub_file_patterns = {
1245            'disk': [
1246                grub_pattern_type(
1247                    '/usr/share/efi/*/grub.efi',
1248                    'grub.efi',
1249                    'bootx64.efi'
1250                ),
1251                grub_pattern_type(
1252                    '/usr/lib64/efi/grub.efi',
1253                    'grub.efi',
1254                    'bootx64.efi'
1255                ),
1256                grub_pattern_type(
1257                    '/boot/efi/EFI/*/grubx64.efi',
1258                    'grubx64.efi',
1259                    'bootx64.efi'
1260                ),
1261                grub_pattern_type(
1262                    '/boot/efi/EFI/*/grubia32.efi',
1263                    'grubia32.efi',
1264                    'bootia32.efi'
1265                ),
1266                grub_pattern_type(
1267                    '/boot/efi/EFI/*/grubaa64.efi',
1268                    'grubaa64.efi',
1269                    'bootaa64.efi'
1270                ),
1271                grub_pattern_type(
1272                    '/boot/efi/EFI/*/grubriscv64.efi',
1273                    'grubriscv64.efi',
1274                    'bootriscv64.efi'
1275                ),
1276                grub_pattern_type(
1277                    '/usr/share/grub*/*-efi/grub.efi',
1278                    'grub.efi',
1279                    'bootx64.efi'
1280                ),
1281                grub_pattern_type(
1282                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1283                    'grubx64.efi',
1284                    'bootx64.efi'
1285                )
1286            ],
1287            'iso': [
1288                grub_pattern_type(
1289                    '/boot/efi/EFI/*/gcdx64.efi',
1290                    'grubx64.efi',
1291                    'bootx64.efi'
1292                ),
1293                grub_pattern_type(
1294                    '/boot/efi/EFI/*/gcdaa64.efi',
1295                    'grubaa64.efi',
1296                    'bootaa64.efi'
1297                ),
1298                grub_pattern_type(
1299                    '/usr/share/efi/x86_64/grub.efi',
1300                    'grub.efi',
1301                    'grubx64.efi'
1302                ),
1303                grub_pattern_type(
1304                    '/usr/share/efi/aarch64/grub.efi',
1305                    'grub.efi',
1306                    'grubaa64.efi'
1307                ),
1308                grub_pattern_type(
1309                    '/usr/lib64/efi/grub.efi',
1310                    'grub.efi',
1311                    'bootx64.efi'
1312                ),
1313                grub_pattern_type(
1314                    '/boot/efi/EFI/*/grubx64.efi',
1315                    'grubx64.efi',
1316                    'bootx64.efi'
1317                ),
1318                grub_pattern_type(
1319                    '/boot/efi/EFI/*/grubia32.efi',
1320                    'grubia32.efi',
1321                    'bootia32.efi'
1322                ),
1323                grub_pattern_type(
1324                    '/boot/efi/EFI/*/grubaa64.efi',
1325                    'grubaa64.efi',
1326                    'bootaa64.efi'
1327                ),
1328                grub_pattern_type(
1329                    '/boot/efi/EFI/*/grubriscv64.efi',
1330                    'grubriscv64.efi',
1331                    'bootriscv64.efi'
1332                ),
1333                grub_pattern_type(
1334                    '/usr/share/grub*/x86_64-efi/grub.efi',
1335                    'grub.efi',
1336                    'bootx64.efi'
1337                ),
1338                grub_pattern_type(
1339                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1340                    'grubx64.efi',
1341                    'bootx64.efi'
1342                )
1343            ]
1344        }
1345        for signed_grub in signed_grub_file_patterns[target_type]:
1346            for signed_grub_file in glob.iglob(root_path + signed_grub.pattern):
1347                result.append(
1348                    grub_loader_type(
1349                        signed_grub_file,
1350                        signed_grub.binaryname,
1351                        signed_grub.targetname
1352                    )
1353                )
1354                # one match only expected, per pattern
1355                break
1356        return result
1357
1358    @staticmethod
1359    def get_efi_vendor_directory(efi_path):
1360        """
1361        Provides EFI vendor directory if present
1362
1363        Looks up distribution specific EFI vendor directory
1364
1365        :param string root_path: path to efi mountpoint
1366
1367        :return: directory path or None
1368
1369        :rtype: str
1370        """
1371        efi_vendor_directories = [
1372            'EFI/fedora',
1373            'EFI/redhat',
1374            'EFI/centos',
1375            'EFI/almalinux',
1376            'EFI/opensuse',
1377            'EFI/ubuntu',
1378            'EFI/debian'
1379        ]
1380        for efi_vendor_directory in efi_vendor_directories:
1381            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1382            if os.path.exists(efi_vendor_directory):
1383                return efi_vendor_directory
1384
1385    @staticmethod
1386    def get_vendor_grubenv(efi_path):
1387        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1388        if efi_vendor_directory:
1389            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1390            if os.path.exists(grubenv):
1391                return grubenv
1392
1393    @staticmethod
1394    def get_shim_vendor_directory(root_path):
1395        """
1396        Provides shim vendor directory
1397
1398        Searches distribution specific locations to find shim.efi
1399        below the given root path and return the directory name
1400        to the file found
1401
1402        :param string root_path: image root path
1403
1404        :return: directory path or None
1405
1406        :rtype: str
1407        """
1408        shim_vendor_patterns = [
1409            '/boot/efi/EFI/*/shim*.efi',
1410            '/EFI/*/shim*.efi'
1411        ]
1412        for shim_vendor_pattern in shim_vendor_patterns:
1413            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1414                return os.path.dirname(shim_file)
1415
1416    @staticmethod
1417    def get_default_volume_group_name():
1418        """
1419        Provides default LVM volume group name
1420
1421        :return: name
1422
1423        :rtype: str
1424        """
1425        return 'systemVG'
1426
1427    @staticmethod
1428    def get_min_partition_mbytes():
1429        """
1430        Provides default minimum partition size in mbytes
1431
1432        :return: mbsize value
1433
1434        :rtype: int
1435        """
1436        return 10
1437
1438    @staticmethod
1439    def get_min_volume_mbytes(filesystem: str):
1440        """
1441        Provides default minimum LVM volume size in mbytes
1442        per filesystem
1443
1444        :return: mbsize value
1445
1446        :rtype: int
1447        """
1448        if filesystem == 'btrfs':
1449            return 120
1450        elif filesystem == 'xfs':
1451            return 300
1452        else:
1453            return 30
1454
1455    @staticmethod
1456    def get_lvm_overhead_mbytes():
1457        """
1458        Provides empiric LVM overhead size in mbytes
1459
1460        :return: mbsize value
1461
1462        :rtype: int
1463        """
1464        return 80
1465
1466    @staticmethod
1467    def get_default_boot_mbytes():
1468        """
1469        Provides default boot partition size in mbytes
1470
1471        :return: mbsize value
1472
1473        :rtype: int
1474        """
1475        return 300
1476
1477    @staticmethod
1478    def get_default_efi_boot_mbytes():
1479        """
1480        Provides default EFI partition size in mbytes
1481
1482        :return: mbsize value
1483
1484        :rtype: int
1485        """
1486        return 20
1487
1488    @staticmethod
1489    def get_recovery_spare_mbytes():
1490        """
1491        Provides spare size of recovery partition in mbytes
1492
1493        :return: mbsize value
1494
1495        :rtype: int
1496        """
1497        return 300
1498
1499    @staticmethod
1500    def get_default_legacy_bios_mbytes():
1501        """
1502        Provides default size of bios_grub partition in mbytes
1503
1504        :return: mbsize value
1505
1506        :rtype: int
1507        """
1508        return 2
1509
1510    @staticmethod
1511    def get_default_prep_mbytes():
1512        """
1513        Provides default size of prep partition in mbytes
1514
1515        :return: mbsize value
1516
1517        :rtype: int
1518        """
1519        return 8
1520
1521    @staticmethod
1522    def get_disk_format_types():
1523        """
1524        Provides supported disk format types
1525
1526        :return: disk types
1527
1528        :rtype: list
1529        """
1530        return [
1531            'gce',
1532            'qcow2',
1533            'vmdk',
1534            'ova',
1535            'meta',
1536            'vmx',
1537            'vhd',
1538            'vhdx',
1539            'vhdfixed',
1540            'vdi',
1541            'vagrant.libvirt.box',
1542            'vagrant.virtualbox.box',
1543            'oci'
1544        ]
1545
1546    @staticmethod
1547    def get_vagrant_config_virtualbox_guest_additions():
1548        """
1549        Provides the default value for
1550        ``vagrantconfig.virtualbox_guest_additions_present``
1551
1552        :return: whether guest additions are expected to be present in the
1553            vagrant box
1554
1555        :rtype: bool
1556        """
1557        return False
1558
1559    @staticmethod
1560    def get_firmware_types():
1561        """
1562        Provides supported architecture specific firmware types
1563
1564        :return: firmware types per architecture
1565
1566        :rtype: dict
1567        """
1568        return {
1569            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1570            'i586': ['bios'],
1571            'i686': ['bios'],
1572            'ix86': ['bios'],
1573            'aarch64': ['efi', 'uefi'],
1574            'arm64': ['efi', 'uefi'],
1575            'armv5el': ['efi', 'uefi'],
1576            'armv5tel': ['efi', 'uefi'],
1577            'armv6hl': ['efi', 'uefi'],
1578            'armv6l': ['efi', 'uefi'],
1579            'armv7hl': ['efi', 'uefi'],
1580            'armv7l': ['efi', 'uefi'],
1581            'armv8l': ['efi', 'uefi'],
1582            'loongarch64': ['efi', 'uefi'],
1583            'ppc': ['ofw'],
1584            'ppc64': ['ofw', 'opal'],
1585            'ppc64le': ['ofw', 'opal'],
1586            'riscv64': ['efi', 'uefi'],
1587            's390': [],
1588            's390x': []
1589        }
1590
1591    @staticmethod
1592    def get_default_firmware(arch):
1593        """
1594        Provides default firmware for specified architecture
1595
1596        :param string arch: machine architecture name
1597
1598        :return: firmware name
1599
1600        :rtype: str
1601        """
1602        default_firmware = {
1603            'x86_64': 'bios',
1604            'i586': 'bios',
1605            'i686': 'bios',
1606            'ix86': 'bios',
1607            'loongarch64': 'efi',
1608            'ppc': 'ofw',
1609            'ppc64': 'ofw',
1610            'ppc64le': 'ofw',
1611            'arm64': 'efi',
1612            'aarch64': 'efi',
1613            'armv5el': 'efi',
1614            'armv5tel': 'efi',
1615            'armv6hl': 'efi',
1616            'armv6l': 'efi',
1617            'armv7hl': 'efi',
1618            'armv7l': 'efi',
1619            'armv8l': 'efi',
1620            'riscv64': 'efi'
1621        }
1622        if arch in default_firmware:
1623            return default_firmware[arch]
1624
1625    @staticmethod
1626    def get_efi_capable_firmware_names():
1627        """
1628        Provides list of EFI capable firmware names. These are
1629        those for which kiwi supports the creation of an EFI
1630        bootable disk image
1631
1632        :return: firmware names
1633
1634        :rtype: list
1635        """
1636        return ['efi', 'uefi']
1637
1638    @staticmethod
1639    def get_ec2_capable_firmware_names():
1640        """
1641        Provides list of EC2 capable firmware names. These are
1642        those for which kiwi supports the creation of disk images
1643        bootable within the Amazon EC2 public cloud
1644
1645        :return: firmware names
1646
1647        :rtype: list
1648        """
1649        return ['ec2']
1650
1651    @staticmethod
1652    def get_efi_module_directory_name(arch):
1653        """
1654        Provides architecture specific EFI directory name which
1655        stores the EFI binaries for the desired architecture.
1656
1657        :param string arch: machine architecture name
1658
1659        :return: directory name
1660
1661        :rtype: str
1662        """
1663        default_module_directory_names = {
1664            'x86_64': 'x86_64-efi',
1665            'i386': 'i386-efi',
1666
1667            # There is no dedicated xen architecture but there are
1668            # modules provided for xen. Thus we treat it as an
1669            # architecture
1670            'x86_64_xen': 'x86_64-xen',
1671
1672            'aarch64': 'arm64-efi',
1673            'arm64': 'arm64-efi',
1674            'armv5el': 'arm-efi',
1675            'armv5tel': 'arm-efi',
1676            'armv6l': 'arm-efi',
1677            'armv7l': 'arm-efi',
1678            'armv8l': 'arm-efi',
1679            'loongarch64': 'loongarch64-efi',
1680            'riscv64': 'riscv64-efi'
1681        }
1682        if arch in default_module_directory_names:
1683            return default_module_directory_names[arch]
1684
1685    @staticmethod
1686    def get_grub_platform_module_directory_name():
1687        """
1688        Provides grub platform specific directory name which
1689        stores the grub module binaries
1690
1691        :return: directory name
1692
1693        :rtype: str
1694        """
1695        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1696            Defaults.get_platform_name()
1697        ) else 'i386-pc'
1698
1699    @staticmethod
1700    def get_efi_image_name(arch):
1701        """
1702        Provides architecture specific EFI boot binary name
1703
1704        :param string arch: machine architecture name
1705
1706        :return: name
1707
1708        :rtype: str
1709        """
1710        default_efi_image_names = {
1711            'x86_64': 'bootx64.efi',
1712            'i386': 'bootia32.efi',
1713            'aarch64': 'bootaa64.efi',
1714            'arm64': 'bootaa64.efi',
1715            'armv5el': 'bootarm.efi',
1716            'armv5tel': 'bootarm.efi',
1717            'armv6l': 'bootarm.efi',
1718            'armv7l': 'bootarm.efi',
1719            'armv8l': 'bootarm.efi',
1720            'loongarch64': 'bootloongarch64.efi',
1721            'riscv64': 'bootriscv64.efi'
1722        }
1723        if arch in default_efi_image_names:
1724            return default_efi_image_names[arch]
1725
1726    @staticmethod
1727    def get_grub_platform_image_name():
1728        """
1729        Provides platform specific core boot binary name
1730
1731        :return: name
1732
1733        :rtype: str
1734        """
1735        return 'grub.elf' if Defaults.is_ppc64_arch(
1736            Defaults.get_platform_name()
1737        ) else 'core.img'
1738
1739    @staticmethod
1740    def get_default_boot_timeout_seconds():
1741        """
1742        Provides default boot timeout in seconds
1743
1744        :return: seconds
1745
1746        :rtype: int
1747        """
1748        return 10
1749
1750    @staticmethod
1751    def get_default_disk_start_sector():
1752        """
1753        Provides the default initial disk sector for the first disk
1754        partition.
1755
1756        :return: sector value
1757
1758        :rtype: int
1759        """
1760        return Defaults().defaults['kiwi_startsector']
1761
1762    @staticmethod
1763    def get_default_efi_partition_table_type():
1764        """
1765        Provides the default partition table type for efi firmwares.
1766
1767        :return: partition table type name
1768
1769        :rtype: str
1770        """
1771        return 'gpt'
1772
1773    @staticmethod
1774    def get_default_inode_size():
1775        """
1776        Provides default size of inodes in bytes. This is only
1777        relevant for inode based filesystems
1778
1779        :return: bytesize value
1780
1781        :rtype: int
1782        """
1783        return Defaults().defaults['kiwi_inode_size']
1784
1785    @staticmethod
1786    def get_archive_image_types():
1787        """
1788        Provides list of supported archive image types
1789
1790        :return: archive names
1791
1792        :rtype: list
1793        """
1794        return ['tbz', 'cpio']
1795
1796    @staticmethod
1797    def get_container_image_types():
1798        """
1799        Provides list of supported container image types
1800
1801        :return: container names
1802
1803        :rtype: list
1804        """
1805        return ['docker', 'oci', 'appx', 'wsl']
1806
1807    @staticmethod
1808    def get_filesystem_image_types():
1809        """
1810        Provides list of supported filesystem image types
1811
1812        :return: filesystem names
1813
1814        :rtype: list
1815        """
1816        return [
1817            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1818            'xfs', 'fat16', 'fat32', 'erofs'
1819        ]
1820
1821    @staticmethod
1822    def get_default_live_iso_type():
1823        """
1824        Provides default live iso union type
1825
1826        :return: live iso type
1827
1828        :rtype: str
1829        """
1830        return 'overlay'
1831
1832    @staticmethod
1833    def get_default_uri_type():
1834        """
1835        Provides default URI type
1836
1837        Absolute path specifications used in the context of an URI
1838        will apply the specified default mime type
1839
1840        :return: URI mime type
1841
1842        :rtype: str
1843        """
1844        return 'dir:/'
1845
1846    @staticmethod
1847    def get_dracut_conf_name():
1848        """
1849        Provides file path of dracut config file to be used with KIWI
1850
1851        :return: file path name
1852
1853        :rtype: str
1854        """
1855        return '/etc/dracut.conf.d/02-kiwi.conf'
1856
1857    @staticmethod
1858    def get_live_dracut_modules_from_flag(flag_name):
1859        """
1860        Provides flag_name to dracut modules name map
1861
1862        Depending on the value of the flag attribute in the KIWI image
1863        description specific dracut modules need to be selected
1864
1865        :return: dracut module names as list
1866
1867        :rtype: list
1868        """
1869        live_modules = {
1870            'overlay': ['kiwi-live'],
1871            'dmsquash': ['dmsquash-live', 'livenet']
1872        }
1873        if flag_name in live_modules:
1874            return live_modules[flag_name]
1875        else:
1876            return ['kiwi-live']
1877
1878    @staticmethod
1879    def get_default_live_iso_root_filesystem():
1880        """
1881        Provides default live iso root filesystem type
1882
1883        :return: filesystem name
1884
1885        :rtype: str
1886        """
1887        return 'ext4'
1888
1889    @staticmethod
1890    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1891        """
1892        Provides list of boot options passed to the dracut
1893        kiwi-live module to setup persistent writing
1894
1895        :return: list of boot options
1896
1897        :rtype: list
1898        """
1899        live_iso_persistent_boot_options = [
1900            'rd.live.overlay.persistent'
1901        ]
1902        if persistent_filesystem:
1903            live_iso_persistent_boot_options.append(
1904                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1905            )
1906        return live_iso_persistent_boot_options
1907
1908    @staticmethod
1909    def get_disk_image_types():
1910        """
1911        Provides supported disk image types
1912
1913        :return: disk image type names
1914
1915        :rtype: list
1916        """
1917        return ['oem']
1918
1919    @staticmethod
1920    def get_live_image_types():
1921        """
1922        Provides supported live image types
1923
1924        :return: live image type names
1925
1926        :rtype: list
1927        """
1928        return ['iso']
1929
1930    @staticmethod
1931    def get_kis_image_types():
1932        """
1933        Provides supported kis image types
1934
1935        :return: kis image type names
1936
1937        :rtype: list
1938        """
1939        return ['kis', 'pxe']
1940
1941    @staticmethod
1942    def get_enclaves_image_types():
1943        """
1944        Provides supported enclave(initrd-only) image types
1945
1946        :return: enclave image type names
1947
1948        :rtype: list
1949        """
1950        return ['enclave']
1951
1952    @staticmethod
1953    def get_boot_image_description_path():
1954        """
1955        Provides the path to find custom kiwi boot descriptions
1956
1957        :return: directory path
1958
1959        :rtype: str
1960        """
1961        return '/usr/share/kiwi/custom_boot'
1962
1963    @staticmethod
1964    def get_boot_image_strip_file():
1965        """
1966        Provides the file path to bootloader strip metadata.
1967        This file contains information about the files and directories
1968        automatically striped out from the kiwi initrd
1969
1970        :return: file path
1971
1972        :rtype: str
1973        """
1974        return Defaults.project_file('config/strip.xml')
1975
1976    @staticmethod
1977    def get_schema_file():
1978        """
1979        Provides file path to kiwi RelaxNG schema
1980
1981        :return: file path
1982
1983        :rtype: str
1984        """
1985        return Defaults.project_file('schema/kiwi.rng')
1986
1987    @staticmethod
1988    def get_common_functions_file():
1989        """
1990        Provides the file path to config functions metadata.
1991
1992        This file contains bash functions used for system
1993        configuration or in the boot code from the kiwi initrd
1994
1995        :return: file path
1996
1997        :rtype: str
1998        """
1999        return Defaults.project_file('config/functions.sh')
2000
2001    @staticmethod
2002    def get_xsl_stylesheet_file():
2003        """
2004        Provides the file path to the KIWI XSLT style sheets
2005
2006        :return: file path
2007
2008        :rtype: str
2009        """
2010        return Defaults.project_file('xsl/master.xsl')
2011
2012    @staticmethod
2013    def get_schematron_module_name():
2014        """
2015        Provides module name for XML SchemaTron validations
2016
2017        :return: python module name
2018
2019        :rtype: str
2020        """
2021        return 'lxml.isoschematron'
2022
2023    @staticmethod
2024    def project_file(filename):
2025        """
2026        Provides the python module base directory search path
2027
2028        The method uses the importlib.resources.path method to identify
2029        files and directories from the application
2030
2031        :param string filename: relative project file
2032
2033        :return: absolute file path name
2034
2035        :rtype: str
2036        """
2037        with as_file(importlib.resources.files('kiwi')) as path:
2038            return f'{path}/{filename}'
2039
2040    @staticmethod
2041    def get_imported_root_image(root_dir):
2042        """
2043        Provides the path to an imported root system image
2044
2045        If the image description specified a derived_from attribute
2046        the file from this attribute is copied into the root_dir
2047        using the name as provided by this method
2048
2049        :param string root_dir: image root directory
2050
2051        :return: file path name
2052
2053        :rtype: str
2054        """
2055        return os.sep.join([root_dir, 'image', 'imported_root'])
2056
2057    @staticmethod
2058    def get_iso_boot_path():
2059        """
2060        Provides arch specific relative path to boot files
2061        on kiwi iso filesystems
2062
2063        :return: relative path name
2064
2065        :rtype: str
2066        """
2067        return os.sep.join(
2068            ['boot', Defaults.get_platform_name()]
2069        )
2070
2071    @staticmethod
2072    def get_iso_tool_category():
2073        """
2074        Provides default iso tool category
2075
2076        :return: name
2077
2078        :rtype: str
2079        """
2080        return 'xorriso'
2081
2082    @staticmethod
2083    def get_iso_media_tag_tool():
2084        """
2085        Provides default iso media tag tool
2086
2087        :return: name
2088
2089        :rtype: str
2090        """
2091        return 'checkmedia'
2092
2093    @staticmethod
2094    def get_container_compression():
2095        """
2096        Provides default container compression
2097
2098        :return: True
2099
2100        :rtype: bool
2101        """
2102        return True
2103
2104    @staticmethod
2105    def get_default_container_name():
2106        """
2107        Provides the default container name.
2108
2109        :return: name
2110
2111        :rtype: str
2112        """
2113        return 'kiwi-container'
2114
2115    @staticmethod
2116    def get_container_base_image_tag():
2117        """
2118        Provides the tag used to identify base layers during the build
2119        of derived images.
2120
2121        :return: tag
2122
2123        :rtype: str
2124        """
2125        return 'base_layer'
2126
2127    @staticmethod
2128    def get_oci_archive_tool():
2129        """
2130        Provides the default OCI archive tool name.
2131
2132        :return: name
2133
2134        :rtype: str
2135        """
2136        return 'umoci'
2137
2138    @staticmethod
2139    def get_part_mapper_tool():
2140        """
2141        Provides the default partition mapper tool name.
2142
2143        :return: name
2144
2145        :rtype: str
2146        """
2147        host_architecture = Defaults.get_platform_name()
2148        if 's390' in host_architecture:
2149            return 'kpartx'
2150        return 'partx'
2151
2152    @staticmethod
2153    def get_default_container_tag():
2154        """
2155        Provides the default container tag.
2156
2157        :return: tag
2158
2159        :rtype: str
2160        """
2161        return 'latest'
2162
2163    @staticmethod
2164    def get_default_container_subcommand():
2165        """
2166        Provides the default container subcommand.
2167
2168        :return: command as a list of arguments
2169
2170        :rtype: list
2171        """
2172        return ['/bin/bash']
2173
2174    @staticmethod
2175    def get_default_container_created_by():
2176        """
2177        Provides the default 'created by' history entry for containers.
2178
2179        :return: the specific kiwi version used for the build
2180
2181        :rtype: str
2182        """
2183        return 'KIWI {0}'.format(__version__)
2184
2185    @staticmethod
2186    def get_custom_rpm_macros_path():
2187        """
2188        Returns the custom macros directory for the rpm database.
2189
2190        :return: path name
2191
2192        :rtype: str
2193        """
2194        return 'usr/lib/rpm/macros.d'
2195
2196    @staticmethod
2197    def get_custom_rpm_bootstrap_macro_name():
2198        """
2199        Returns the rpm bootstrap macro file name created
2200        in the custom rpm macros path
2201
2202        :return: filename
2203
2204        :rtype: str
2205        """
2206        return 'macros.kiwi-bootstrap-config'
2207
2208    @staticmethod
2209    def get_custom_rpm_image_macro_name():
2210        """
2211        Returns the rpm image macro file name created
2212        in the custom rpm macros path
2213
2214        :return: filename
2215
2216        :rtype: str
2217        """
2218        return 'macros.kiwi-image-config'
2219
2220    @staticmethod
2221    def get_default_package_manager() -> str:
2222        """
2223        Returns the default package manager name if none
2224        is configured in the image description
2225
2226        :return: package manager name
2227
2228        :rtype: str
2229        """
2230        return 'dnf4'
2231
2232    @staticmethod
2233    def get_default_packager_tool(package_manager):
2234        """
2235        Provides the packager tool according to the package manager
2236
2237        :param string package_manager: package manger name
2238
2239        :return: packager tool binary name
2240
2241        :rtype: str
2242        """
2243        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2244        deb_based = ['apt']
2245        if package_manager in rpm_based:
2246            return 'rpm'
2247        elif package_manager in deb_based:
2248            return 'dpkg'
2249        elif package_manager == 'pacman':
2250            return 'pacman'
2251
2252    @staticmethod
2253    def get_discoverable_partition_ids() -> Dict[str, str]:
2254        """
2255        Provides arch specific partition UUIDs as defined
2256        by the UAPI group
2257
2258        :return: partition UUIDs
2259
2260        :rtype: dict
2261        """
2262        arch = Defaults.get_platform_name()
2263        part_uuids_archs = {
2264            'x86_64': {
2265                'root':
2266                    '4f68bce3e8cd4db196e7fbcaf984b709',
2267                'usr':
2268                    '8484680c952148c69c11b0720656f69e',
2269                'usr-verity':
2270                    '77ff5f63e7b64633acf41565b864c0e6'
2271            },
2272            'ix86': {
2273                'root':
2274                    '44479540f29741b29af7d131d5f0458a',
2275                'usr':
2276                    '75250d768cc6458ebd66bd47cc81a812',
2277                'usr-verity':
2278                    '8f461b0d14ee4e819aa9049b6fb97abd'
2279            },
2280            'aarch64': {
2281                'root':
2282                    'b921b0451df041c3af444c6f280d3fae',
2283                'usr':
2284                    'b0e01050ee5f4390949a9101b17104e9',
2285                'usr-verity':
2286                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2287            },
2288            'riscv64': {
2289                'root':
2290                    '72ec70a6cf7440e6bd494bda08e8f224',
2291                'usr':
2292                    'beaec34b8442439ba40b984381ed097d',
2293                'usr-verity':
2294                    '8f1056be9b0547c481d6be53128e5b54'
2295            }
2296        }
2297        part_uuids_arch = part_uuids_archs.get(arch) or {}
2298        return {
2299            'root':
2300                part_uuids_arch.get('root') or '',
2301            'usr':
2302                part_uuids_arch.get('usr') or '',
2303            'usr-verity':
2304                part_uuids_arch.get('usr-verity') or '',
2305            'usr-secondary':
2306                '75250d768cc6458ebd66bd47cc81a812',
2307            'usr-secondary-verity':
2308                '8f461b0d14ee4e819aa9049b6fb97abd',
2309            'esp':
2310                'c12a7328f81f11d2ba4b00a0c93ec93b',
2311            'xbootldr':
2312                'bc13c2ff59e64262a352b275fd6f7172',
2313            'swap':
2314                '0657fd6da4ab43c484e50933c84b4f4f',
2315            'home':
2316                '933ac7e12eb44f13b8440e14e2aef915',
2317            'srv':
2318                '3b8f842520e04f3b907f1a25a76f98e8',
2319            'var':
2320                '4d21b016b53445c2a9fb5c16e091fd2d',
2321            'tmp':
2322                '7ec6f5573bc54acab29316ef5df639d1',
2323            'user-home':
2324                '773f91ef66d449b5bd83d683bf40ad16',
2325            'linux-generic':
2326                '0fc63daf848347728e793d69d8477de4'
2327        }
2328
2329    @staticmethod
2330    def get_bls_loader_entries_dir() -> str:
2331        """
2332        Provide default loader entries directory for BLS loaders
2333
2334        :return: directory name
2335
2336        :rtype: str
2337        """
2338        return '/boot/loader/entries'
2339
2340    @staticmethod
2341    def get_apk_repo_config() -> str:
2342        """
2343        Repository file for apk
2344
2345        :return: file path name
2346
2347        :rtype: str
2348        """
2349        return '/etc/apk/repositories'
2350
2351    @staticmethod
2352    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2353        return CA_UPDATE_MAP.get(target_distribution)
2354
2355    @staticmethod
2356    def get_ca_target_distributions() -> List[str]:
2357        return sorted(CA_UPDATE_MAP.keys())
2358
2359    def get(self, key):
2360        """
2361        Implements get method for profile elements
2362
2363        :param string key: profile keyname
2364
2365        :return: key value
2366
2367        :rtype: str
2368        """
2369        if key in self.defaults:
2370            return self.defaults[key]
2371
2372    @staticmethod
2373    def get_profile_file(root_dir):
2374        """
2375        Return name of profile file for given root directory
2376        """
2377        return root_dir + '/.profile'
2378
2379    def to_profile(self, profile):
2380        """
2381        Implements method to add list of profile keys and their values
2382        to the specified instance of a Profile class
2383
2384        :param object profile: Profile instance
2385        """
2386        for key in sorted(self.profile_key_list):
2387            # Do not apply default values to any variable that was
2388            # already defined in the profile instance.
2389            cur_profile = profile.dot_profile
2390            if key not in cur_profile or cur_profile[key] is None:
2391                profile.add(key, self.get(key))

Implements default values

Provides static methods for default values and state information

defaults
profile_key_list
@staticmethod
def get_luks_key_length():
162    @staticmethod
163    def get_luks_key_length():
164        """
165        Provides key length to use for random luks keys
166        """
167        return 256

Provides key length to use for random luks keys

@staticmethod
def get_swapsize_mbytes():
169    @staticmethod
170    def get_swapsize_mbytes():
171        """
172        Provides swapsize in MB
173        """
174        return 128

Provides swapsize in MB

@staticmethod
def get_xz_compression_options():
176    @staticmethod
177    def get_xz_compression_options():
178        """
179        Provides compression options for the xz compressor
180
181        :return:
182            Contains list of options
183
184            .. code:: python
185
186                ['--option=value']
187
188        :rtype: list
189        """
190        return [
191            '--threads=0'
192        ]

Provides compression options for the xz compressor

Returns
Contains list of options

.. code:: python

    ['--option=value']
@staticmethod
def get_platform_name():
194    @staticmethod
195    def get_platform_name():
196        """
197        Provides the machine architecture name as used by KIWI
198
199        This is the architecture name as it is returned by 'uname -m'
200        with one exception for the 32bit x86 architecture which is
201        handled as 'ix86' in general
202
203        :return: architecture name
204
205        :rtype: str
206        """
207        arch = PLATFORM_MACHINE
208        if arch == 'i686' or arch == 'i586':
209            arch = 'ix86'
210        return arch

Provides the machine architecture name as used by KIWI

This is the architecture name as it is returned by 'uname -m' with one exception for the 32bit x86 architecture which is handled as 'ix86' in general

Returns

architecture name

@staticmethod
def set_platform_name(name: str):
212    @staticmethod
213    def set_platform_name(name: str):
214        """
215        Sets the platform architecture once
216
217        :param str name: an architecture name
218        """
219        global PLATFORM_MACHINE
220        PLATFORM_MACHINE = name

Sets the platform architecture once

Parameters
  • str name: an architecture name
@staticmethod
def is_x86_arch(arch):
222    @staticmethod
223    def is_x86_arch(arch):
224        """
225        Checks if machine architecture is x86 based
226
227        Any arch that matches 32bit and 64bit x86 architecture
228        causes the method to return True. Anything else will
229        cause the method to return False
230
231        :rtype: bool
232        """
233        x86_arch_names = [
234            'x86_64', 'i686', 'i586', 'ix86'
235        ]
236        if arch in x86_arch_names:
237            return True
238        return False

Checks if machine architecture is x86 based

Any arch that matches 32bit and 64bit x86 architecture causes the method to return True. Anything else will cause the method to return False

@staticmethod
def is_ppc64_arch(arch):
240    @staticmethod
241    def is_ppc64_arch(arch):
242        """
243        Checks if machine architecture is ppc64 based
244
245        Any arch that matches little endian or big endian ppc64 architecture
246        causes the method to return True. Anything else will
247        cause the method to return False
248
249        :rtype: bool
250        """
251        ppc64_arch_names = [
252            'ppc64', 'ppc64le'
253        ]
254        if arch in ppc64_arch_names:
255            return True
256        return False

Checks if machine architecture is ppc64 based

Any arch that matches little endian or big endian ppc64 architecture causes the method to return True. Anything else will cause the method to return False

@staticmethod
def is_buildservice_worker():
258    @staticmethod
259    def is_buildservice_worker():
260        """
261        Checks if build host is an open buildservice machine
262
263        The presence of /.buildenv on the build host indicates
264        we are building inside of the open buildservice
265
266        :return: True if obs worker, else False
267
268        :rtype: bool
269        """
270        return os.path.exists(
271            os.sep + Defaults.get_buildservice_env_name()
272        )

Checks if build host is an open buildservice machine

The presence of /.buildenv on the build host indicates we are building inside of the open buildservice

Returns

True if obs worker, else False

@staticmethod
def get_buildservice_env_name():
274    @staticmethod
275    def get_buildservice_env_name():
276        """
277        Provides the base name of the environment file in a
278        buildservice worker
279
280        :return: file basename
281
282        :rtype: str
283        """
284        return '.buildenv'

Provides the base name of the environment file in a buildservice worker

Returns

file basename

@staticmethod
def get_obs_download_server_url():
286    @staticmethod
287    def get_obs_download_server_url():
288        """
289        Provides the default download server url hosting the public open
290        buildservice repositories
291
292        :return: url path
293
294        :rtype: str
295        """
296        return 'http://download.opensuse.org/repositories'

Provides the default download server url hosting the public open buildservice repositories

Returns

url path

@staticmethod
def get_obs_api_server_url():
298    @staticmethod
299    def get_obs_api_server_url():
300        """
301        Provides the default API server url to access the
302        public open buildservice API
303
304        :return: url path
305
306        :rtype: str
307        """
308        return 'https://api.opensuse.org'

Provides the default API server url to access the public open buildservice API

Returns

url path

@staticmethod
def get_solvable_location():
310    @staticmethod
311    def get_solvable_location():
312        """
313        Provides the directory to store SAT solvables for repositories.
314        The solvable files are used to perform package
315        dependency and metadata resolution
316
317        :return: directory path
318
319        :rtype: str
320        """
321        return '/var/tmp/kiwi/satsolver'

Provides the directory to store SAT solvables for repositories. The solvable files are used to perform package dependency and metadata resolution

Returns

directory path

@staticmethod
def set_runtime_checker_metadata(filename):
323    @staticmethod
324    def set_runtime_checker_metadata(filename):
325        """
326        Sets the runtime checker metadata filename
327
328        :param str filename: a file path name
329        """
330        global RUNTIME_CHECKER_METADATA
331        RUNTIME_CHECKER_METADATA = filename

Sets the runtime checker metadata filename

Parameters
  • str filename: a file path name
@staticmethod
def set_shared_cache_location(location):
333    @staticmethod
334    def set_shared_cache_location(location):
335        """
336        Sets the shared cache location once
337
338        :param str location: a location path
339        """
340        global SHARED_CACHE_DIR
341        SHARED_CACHE_DIR = location

Sets the shared cache location once

Parameters
  • str location: a location path
@staticmethod
def set_custom_runtime_config_file(filename):
343    @staticmethod
344    def set_custom_runtime_config_file(filename):
345        """
346        Sets the runtime config file once
347
348        :param str filename: a file path name
349        """
350        global CUSTOM_RUNTIME_CONFIG_FILE
351        CUSTOM_RUNTIME_CONFIG_FILE = filename

Sets the runtime config file once

Parameters
  • str filename: a file path name
@staticmethod
def set_temp_location(location):
353    @staticmethod
354    def set_temp_location(location):
355        """
356        Sets the temp directory location once
357
358        :param str location: a location path
359        """
360        global TEMP_DIR
361        TEMP_DIR = location

Sets the temp directory location once

Parameters
  • str location: a location path
@staticmethod
def get_shared_cache_location():
363    @staticmethod
364    def get_shared_cache_location():
365        """
366        Provides the shared cache location
367
368        This is a directory which shares data from the image buildsystem
369        host with the image root system. The location is returned as an
370        absolute path stripped off by the leading '/'. This is because
371        the path is transparently used on the host /<cache-dir> and
372        inside of the image imageroot/<cache-dir>
373
374        :return: directory path
375
376        :rtype: str
377        """
378        return os.path.abspath(os.path.normpath(
379            SHARED_CACHE_DIR
380        )).lstrip(os.sep)

Provides the shared cache location

This is a directory which shares data from the image buildsystem host with the image root system. The location is returned as an absolute path stripped off by the leading '/'. This is because the path is transparently used on the host / and inside of the image imageroot/

Returns

directory path

@staticmethod
def get_temp_location():
382    @staticmethod
383    def get_temp_location():
384        """
385        Provides the base temp directory location
386
387        This is the directory used to store any temporary files
388        and directories created by kiwi during runtime
389
390        :return: directory path
391
392        :rtype: str
393        """
394        return os.path.abspath(
395            os.path.normpath(TEMP_DIR)
396        )

Provides the base temp directory location

This is the directory used to store any temporary files and directories created by kiwi during runtime

Returns

directory path

@staticmethod
def get_sync_options():
398    @staticmethod
399    def get_sync_options():
400        """
401        Provides list of default data sync options
402
403        :return: list of rsync options
404
405        :rtype: list
406        """
407        return [
408            '--archive', '--hard-links', '--xattrs', '--acls',
409            '--one-file-system', '--inplace'
410        ]

Provides list of default data sync options

Returns

list of rsync options

@staticmethod
def get_removed_files_name():
412    @staticmethod
413    def get_removed_files_name():
414        """
415        Provides base file name to store removed files
416        in a delta root build
417        """
418        return 'removed'

Provides base file name to store removed files in a delta root build

@staticmethod
def get_system_files_name():
420    @staticmethod
421    def get_system_files_name():
422        """
423        Provides base file name to store system files
424        in a container build
425        """
426        return 'systemfiles'

Provides base file name to store system files in a container build

@staticmethod
def get_exclude_list_for_removed_files_detection() -> List[str]:
428    @staticmethod
429    def get_exclude_list_for_removed_files_detection() -> List[str]:
430        """
431        Provides list of files/dirs to exclude from the removed
432        files detection in a delta root build
433        """
434        return [
435            'etc/hosts.kiwi',
436            'etc/hosts.sha',
437            'etc/resolv.conf.kiwi',
438            'etc/resolv.conf.sha',
439            'etc/sysconfig/proxy.kiwi',
440            'etc/sysconfig/proxy.sha',
441            'usr/lib/sysimage/rpm'
442        ]

Provides list of files/dirs to exclude from the removed files detection in a delta root build

@staticmethod
def get_exclude_list_for_root_data_sync(no_tmpdirs: bool = True):
444    @staticmethod
445    def get_exclude_list_for_root_data_sync(no_tmpdirs: bool = True):
446        """
447        Provides the list of files or folders that are created
448        by KIWI for its own purposes. Those files should be not
449        be included in the resulting image.
450
451        :return: list of file and directory names
452
453        :rtype: list
454        """
455        exclude_list = [
456            'image', '.kconfig'
457        ]
458        if no_tmpdirs:
459            exclude_list += ['run/*', 'tmp/*']
460        exclude_list += [
461            Defaults.get_buildservice_env_name(),
462            Defaults.get_shared_cache_location()
463        ]
464        return exclude_list

Provides the list of files or folders that are created by KIWI for its own purposes. Those files should be not be included in the resulting image.

Returns

list of file and directory names

@staticmethod
def get_runtime_checker_metadata() -> Dict:
466    @staticmethod
467    def get_runtime_checker_metadata() -> Dict:
468        with open(RUNTIME_CHECKER_METADATA) as meta:
469            return yaml.safe_load(meta)
@staticmethod
def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
513    @staticmethod
514    def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
515        """
516        Gets the list of excluded items for the root filesystem from
517        the optional metadata file image/exclude_files.yaml
518
519        :return: list of paths and glob patterns
520
521        :param string root_dir: image root directory
522
523        :rtype: list
524        """
525        return Defaults._parse_exclude_file(root_dir, 'exclude_files.yaml')

Gets the list of excluded items for the root filesystem from the optional metadata file image/exclude_files.yaml

Returns

list of paths and glob patterns

Parameters
  • string root_dir: image root directory
@staticmethod
def get_exclude_list_from_custom_exclude_files_for_efifatimage(root_dir: str) -> List:
527    @staticmethod
528    def get_exclude_list_from_custom_exclude_files_for_efifatimage(root_dir: str) -> List:
529        """
530        Gets the list of excluded items for the ESP's EFI folder from
531        the optional metadata file image/exclude_files_efifatimage.yaml
532
533        Excluded items must be relative to the ESP's /EFI directory.
534
535        :return: list of paths and glob patterns
536
537        :param string root_dir: EFI root directory
538
539        :rtype: list
540        """
541        return Defaults._parse_exclude_file(root_dir, 'exclude_files_efifatimage.yaml')

Gets the list of excluded items for the ESP's EFI folder from the optional metadata file image/exclude_files_efifatimage.yaml

Excluded items must be relative to the ESP's /EFI directory.

Returns

list of paths and glob patterns

Parameters
  • string root_dir: EFI root directory
@staticmethod
def get_exclude_list_for_non_physical_devices():
543    @staticmethod
544    def get_exclude_list_for_non_physical_devices():
545        """
546        Provides the list of folders that are not associated
547        with a physical device. KIWI returns the basename of
548        the folders typically used as mountpoint for those
549        devices.
550
551        :return: list of file and directory names
552
553        :rtype: list
554        """
555        exclude_list = [
556            'proc', 'sys', 'dev'
557        ]
558        return exclude_list

Provides the list of folders that are not associated with a physical device. KIWI returns the basename of the folders typically used as mountpoint for those devices.

Returns

list of file and directory names

@staticmethod
def get_failsafe_kernel_options():
560    @staticmethod
561    def get_failsafe_kernel_options():
562        """
563        Provides failsafe boot kernel options
564
565        :return:
566            list of kernel options
567
568            .. code:: python
569
570                ['option=value', 'option']
571
572        :rtype: list
573        """
574        return ' '.join(
575            [
576                'ide=nodma',
577                'apm=off',
578                'noresume',
579                'edd=off',
580                'nomodeset',
581                '3'
582            ]
583        )

Provides failsafe boot kernel options

Returns
list of kernel options

.. code:: python

    ['option=value', 'option']
@staticmethod
def get_video_mode_map():
585    @staticmethod
586    def get_video_mode_map():
587        """
588        Provides video mode map
589
590        Assign a tuple to each kernel vesa hex id for each of the
591        supported bootloaders
592
593        :return:
594            video type map
595
596            .. code:: python
597
598                {'kernel_hex_mode': video_type(grub2='mode')}
599
600        :rtype: dict
601        """
602        video_type = namedtuple(
603            'video_type', ['grub2']
604        )
605        return {
606            '0x301': video_type(grub2='640x480'),
607            '0x310': video_type(grub2='640x480'),
608            '0x311': video_type(grub2='640x480'),
609            '0x312': video_type(grub2='640x480'),
610            '0x303': video_type(grub2='800x600'),
611            '0x313': video_type(grub2='800x600'),
612            '0x314': video_type(grub2='800x600'),
613            '0x315': video_type(grub2='800x600'),
614            '0x305': video_type(grub2='1024x768'),
615            '0x316': video_type(grub2='1024x768'),
616            '0x317': video_type(grub2='1024x768'),
617            '0x318': video_type(grub2='1024x768'),
618            '0x307': video_type(grub2='1280x1024'),
619            '0x319': video_type(grub2='1280x1024'),
620            '0x31a': video_type(grub2='1280x1024'),
621            '0x31b': video_type(grub2='1280x1024'),
622            'auto': video_type(grub2='auto')
623        }

Provides video mode map

Assign a tuple to each kernel vesa hex id for each of the supported bootloaders

Returns
video type map

.. code:: python

    {'kernel_hex_mode': video_type(grub2='mode')}
@staticmethod
def get_volume_id():
625    @staticmethod
626    def get_volume_id():
627        """
628        Provides default value for ISO volume ID
629
630        :return: name
631
632        :rtype: str
633        """
634        return 'CDROM'

Provides default value for ISO volume ID

Returns

name

@staticmethod
def get_install_volume_id():
636    @staticmethod
637    def get_install_volume_id():
638        """
639        Provides default value for ISO volume ID for install media
640
641        :return: name
642
643        :rtype: str
644        """
645        return 'INSTALL'

Provides default value for ISO volume ID for install media

Returns

name

@staticmethod
def get_snapper_config_template_file(root: str) -> str:
647    @staticmethod
648    def get_snapper_config_template_file(root: str) -> str:
649        """
650        Provides the default configuration template file for snapper.
651        The location in etc/ are preferred over files in usr/
652
653        :return: file path
654
655        :rtype: str
656        """
657        snapper_templates = [
658            'etc/snapper/config-templates/default',
659            'usr/share/snapper/config-templates/default'
660        ]
661        snapper_default_conf = ''
662        for snapper_template in snapper_templates:
663            template_config = os.path.join(root, snapper_template)
664            if os.path.exists(template_config):
665                snapper_default_conf = template_config
666                break
667        return snapper_default_conf

Provides the default configuration template file for snapper. The location in etc/ are preferred over files in usr/

Returns

file path

@staticmethod
def get_default_video_mode():
669    @staticmethod
670    def get_default_video_mode():
671        """
672        Uses auto mode for default video. See get_video_mode_map
673        for details on the value depending which bootloader is
674        used
675
676        :return: auto
677
678        :rtype: str
679        """
680        return 'auto'

Uses auto mode for default video. See get_video_mode_map for details on the value depending which bootloader is used

Returns

auto

@staticmethod
def get_default_bootloader():
682    @staticmethod
683    def get_default_bootloader():
684        """
685        Return default bootloader name which is grub2
686
687        :return: bootloader name
688
689        :rtype: str
690        """
691        return 'grub2'

Return default bootloader name which is grub2

Returns

bootloader name

@staticmethod
def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
693    @staticmethod
694    def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
695        return {
696            'grub_directory_name':
697                Defaults.get_grub_boot_directory_name(root_dir),
698            'grub_load_command':
699                'configfile'
700        }
@staticmethod
def get_grub_boot_directory_name(lookup_path):
702    @staticmethod
703    def get_grub_boot_directory_name(lookup_path):
704        """
705        Provides grub2 data directory name in boot/ directory
706
707        Depending on the distribution the grub2 boot path could be
708        either boot/grub2 or boot/grub. The method will decide for
709        the correct base directory name according to the name pattern
710        of the installed grub2 tools
711
712        :return: directory basename
713
714        :rtype: str
715        """
716        if Path.which(filename='grub2-install', root_dir=lookup_path):
717            # the presence of grub2-install is an indicator to put all
718            # grub2 data below boot/grub2
719            return 'grub2'
720        else:
721            # in any other case the assumption is made that all grub
722            # boot data should live below boot/grub
723            return 'grub'

Provides grub2 data directory name in boot/ directory

Depending on the distribution the grub2 boot path could be either boot/grub2 or boot/grub. The method will decide for the correct base directory name according to the name pattern of the installed grub2 tools

Returns

directory basename

@staticmethod
def get_grub_basic_modules(multiboot):
725    @staticmethod
726    def get_grub_basic_modules(multiboot):
727        """
728        Provides list of basic grub modules
729
730        :param bool multiboot: grub multiboot mode
731
732        :return: list of module names
733
734        :rtype: list
735        """
736        modules = [
737            'ext2',
738            'iso9660',
739            'linux',
740            'echo',
741            'configfile',
742            'search_label',
743            'search_fs_file',
744            'search',
745            'search_fs_uuid',
746            'ls',
747            'normal',
748            'gzio',
749            'png',
750            'fat',
751            'gettext',
752            'font',
753            'minicmd',
754            'gfxterm',
755            'gfxmenu',
756            'all_video',
757            'xfs',
758            'btrfs',
759            'squash4',
760            'lvm',
761            'luks',
762            'gcry_rijndael',
763            'gcry_sha256',
764            'gcry_sha512',
765            'crypto',
766            'cryptodisk',
767            'test',
768            'true',
769            'loadenv'
770        ]
771        if multiboot:
772            modules.append('multiboot')
773        return modules

Provides list of basic grub modules

Parameters
  • bool multiboot: grub multiboot mode
Returns

list of module names

@staticmethod
def get_grub_efi_modules(multiboot=False):
775    @staticmethod
776    def get_grub_efi_modules(multiboot=False):
777        """
778        Provides list of grub efi modules
779
780        :param bool multiboot: grub multiboot mode
781
782        :return: list of module names
783
784        :rtype: list
785        """
786        modules = Defaults.get_grub_basic_modules(multiboot) + [
787            'part_gpt',
788            'part_msdos',
789            'efi_gop'
790        ]
791        return modules

Provides list of grub efi modules

Parameters
  • bool multiboot: grub multiboot mode
Returns

list of module names

@staticmethod
def get_grub_platform_modules(multiboot=False):
793    @staticmethod
794    def get_grub_platform_modules(multiboot=False):
795        """
796        Provides list of platform specific grub modules
797
798        :param bool multiboot: grub multiboot mode
799
800        :return: list of module names
801
802        :rtype: list
803        """
804        modules = Defaults.get_grub_basic_modules(multiboot)
805        if Defaults.is_ppc64_arch(Defaults.get_platform_name()):
806            return Defaults.get_grub_ofw_modules()
807        else:
808            modules += [
809                'part_gpt',
810                'part_msdos',
811                'biosdisk',
812                'vga',
813                'vbe',
814                'chain',
815                'boot'
816            ]
817        return modules

Provides list of platform specific grub modules

Parameters
  • bool multiboot: grub multiboot mode
Returns

list of module names

@staticmethod
def get_grub_ofw_modules():
819    @staticmethod
820    def get_grub_ofw_modules():
821        """
822        Provides list of grub ofw modules (ppc)
823
824        :return: list of module names
825
826        :rtype: list
827        """
828        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
829            'part_gpt',
830            'part_msdos',
831            'boot'
832        ]
833        return modules

Provides list of grub ofw modules (ppc)

Returns

list of module names

@staticmethod
def get_grub_s390_modules():
835    @staticmethod
836    def get_grub_s390_modules():
837        """
838        Provides list of grub ofw modules (s390)
839
840        :return: list of module names
841
842        :rtype: list
843        """
844        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
845            'part_gpt',
846            'part_msdos',
847            'boot'
848        ]
849        return modules

Provides list of grub ofw modules (s390)

Returns

list of module names

@staticmethod
def get_grub_path(root_path: str, filename: str, raise_on_error: bool = True) -> str:
851    @staticmethod
852    def get_grub_path(
853        root_path: str, filename: str, raise_on_error: bool = True
854    ) -> str:
855        """
856        Provides grub path to given search file
857
858        Depending on the distribution grub could be installed below
859        a grub2 or grub directory. grub could also reside in /usr/lib
860        as well as in /usr/share. Therefore this information needs
861        to be dynamically looked up
862
863        :param string root_path: root path to start the lookup from
864        :param string filename: filename to search
865        :param bool raise_on_error: raise on not found, defaults to True
866
867        The method returns the path to the given grub search file.
868        By default it raises a KiwiBootLoaderGrubDataError exception
869        if the file could not be found in any of the search locations.
870        If raise_on_error is set to False and no file could be found
871        the function returns None
872
873        :return: filepath
874
875        :rtype: str
876        """
877        log.debug(f'Searching grub file: {filename}')
878        install_dirs = [
879            'usr/share', 'usr/lib'
880        ]
881        lookup_list = []
882        for grub_name in ['grub2', 'grub']:
883            for install_dir in install_dirs:
884                grub_path = os.path.join(
885                    root_path, install_dir, grub_name, filename
886                )
887                log.debug(f'--> {grub_path}')
888                if os.path.exists(grub_path):
889                    log.debug(f'--> Found in: {grub_path}')
890                    return grub_path
891                lookup_list.append(grub_path)
892        if raise_on_error:
893            raise KiwiBootLoaderGrubDataError(
894                'grub path {0} not found in {1}'.format(filename, lookup_list)
895            )
896        return ''

Provides grub path to given search file

Depending on the distribution grub could be installed below a grub2 or grub directory. grub could also reside in /usr/lib as well as in /usr/share. Therefore this information needs to be dynamically looked up

Parameters
  • string root_path: root path to start the lookup from
  • string filename: filename to search
  • bool raise_on_error: raise on not found, defaults to True

The method returns the path to the given grub search file. By default it raises a KiwiBootLoaderGrubDataError exception if the file could not be found in any of the search locations. If raise_on_error is set to False and no file could be found the function returns None

Returns

filepath

@staticmethod
def get_preparer():
898    @staticmethod
899    def get_preparer():
900        """
901        Provides ISO preparer name
902
903        :return: name
904
905        :rtype: str
906        """
907        return 'KIWI - https://github.com/OSInside/kiwi'

Provides ISO preparer name

Returns

name

@staticmethod
def get_publisher():
909    @staticmethod
910    def get_publisher():
911        """
912        Provides ISO publisher name
913
914        :return: name
915
916        :rtype: str
917        """
918        return 'SUSE LINUX GmbH'

Provides ISO publisher name

Returns

name

@staticmethod
def get_shim_loader(root_path: str) -> List[shim_loader_type]:
920    @staticmethod
921    def get_shim_loader(root_path: str) -> List[shim_loader_type]:
922        """
923        Provides shim loader file path
924
925        Searches distribution specific locations to find shim.efi
926        below the given root path
927
928        :param string root_path: image root path
929
930        :return: list of shim_loader_type
931
932        :rtype: list
933        """
934        result = []
935        shim_pattern_type = namedtuple(
936            'shim_pattern_type', ['pattern', 'binaryname']
937        )
938        shim_file_patterns = [
939            shim_pattern_type(
940                '/usr/lib/shim/shim*.efi.signed.latest',
941                'bootx64.efi'
942            ),
943            shim_pattern_type(
944                '/usr/lib/shim/shim*.efi.signed',
945                'bootx64.efi'
946            ),
947            shim_pattern_type(
948                '/usr/lib/grub/*-efi-signed',
949                'bootx64.efi'
950            ),
951            shim_pattern_type(
952                '/usr/share/efi/x86_64/shim.efi',
953                'bootx64.efi'
954            ),
955            shim_pattern_type(
956                '/usr/share/efi/aarch64/shim.efi',
957                'bootaa64.efi'
958            ),
959            shim_pattern_type(
960                '/usr/lib64/efi/shim.efi',
961                'bootx64.efi'
962            ),
963            shim_pattern_type(
964                '/boot/efi/EFI/*/shimx64.efi',
965                'bootx64.efi'
966            ),
967            shim_pattern_type(
968                '/boot/efi/EFI/*/shimia32.efi',
969                'bootia32.efi'
970            ),
971            shim_pattern_type(
972                '/boot/efi/EFI/*/shimaa64.efi',
973                'bootaa64.efi'
974            ),
975            shim_pattern_type(
976                '/boot/efi/EFI/*/shimriscv64.efi',
977                'bootriscv64.efi'
978            ),
979            shim_pattern_type(
980                '/boot/efi/EFI/*/shim.efi',
981                'bootx64.efi'
982            ),
983            shim_pattern_type(
984                '/usr/lib/shim/shim*.efi',
985                'bootx64.efi'
986            )
987        ]
988        for shim_file_pattern in shim_file_patterns:
989            for shim_file in sorted(
990                glob.iglob(root_path + shim_file_pattern.pattern), key=len
991            ):
992                result.append(
993                    shim_loader_type(shim_file, shim_file_pattern.binaryname)
994                )
995                # one match only expected, per pattern
996                break
997        return result

Provides shim loader file path

Searches distribution specific locations to find shim.efi below the given root path

Parameters
  • string root_path: image root path
Returns

list of shim_loader_type

@staticmethod
def get_mok_manager(root_path: str) -> List[str]:
 999    @staticmethod
1000    def get_mok_manager(root_path: str) -> List[str]:
1001        """
1002        Provides Mok Manager file path
1003
1004        Searches distribution specific locations to find
1005        the Mok Manager EFI binary
1006
1007        :param str root_path: image root path
1008
1009        :return: file path or None
1010
1011        :rtype: str
1012        """
1013        result = []
1014        mok_manager_file_patterns = [
1015            '/usr/share/efi/*/MokManager.efi',
1016            '/usr/lib64/efi/MokManager.efi',
1017            '/boot/efi/EFI/*/mm*.efi',
1018            '/usr/lib/shim/mm*.efi'
1019        ]
1020        for mok_manager_file_pattern in mok_manager_file_patterns:
1021            for mm_file in glob.iglob(root_path + mok_manager_file_pattern):
1022                result.append(mm_file)
1023        return result

Provides Mok Manager file path

Searches distribution specific locations to find the Mok Manager EFI binary

Parameters
  • str root_path: image root path
Returns

file path or None

@staticmethod
def get_grub_efi_font_directory(root_path):
1025    @staticmethod
1026    def get_grub_efi_font_directory(root_path):
1027        """
1028        Provides distribution specific EFI font directory used with grub.
1029
1030        :param string root_path: image root path
1031
1032        :return: file path or None
1033
1034        :rtype: str
1035        """
1036        font_dir_patterns = [
1037            '/boot/efi/EFI/*/fonts'
1038        ]
1039        for font_dir_pattern in font_dir_patterns:
1040            for font_dir in glob.iglob(root_path + font_dir_pattern):
1041                return font_dir

Provides distribution specific EFI font directory used with grub.

Parameters
  • string root_path: image root path
Returns

file path or None

@staticmethod
def get_unsigned_grub_loader( root_path: str, target_type: str = 'disk') -> List[grub_loader_type]:
1043    @staticmethod
1044    def get_unsigned_grub_loader(
1045        root_path: str, target_type: str = 'disk'
1046    ) -> List[grub_loader_type]:
1047        """
1048        Provides unsigned grub efi loader file path
1049
1050        Searches distribution specific locations to find a distro
1051        grub EFI binary within the given root path
1052
1053        :param string root_path: image root path
1054
1055        :return: list of grub_loader_type
1056
1057        :rtype: list
1058        """
1059        result = []
1060        grub_pattern_type = namedtuple(
1061            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1062        )
1063        unsigned_grub_file_patterns = {
1064            'disk': [
1065                grub_pattern_type(
1066                    '/usr/share/grub*/x86_64-efi/grub.efi',
1067                    'grub.efi',
1068                    'bootx64.efi'
1069                ),
1070                grub_pattern_type(
1071                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1072                    'grub.efi',
1073                    'bootx64.efi'
1074                ),
1075                grub_pattern_type(
1076                    '/boot/efi/EFI/*/grubx64.efi',
1077                    'grubx64.efi',
1078                    'bootx64.efi'
1079                ),
1080                grub_pattern_type(
1081                    '/boot/efi/EFI/*/grubia32.efi',
1082                    'grubia32.efi',
1083                    'bootia32.efi'
1084                ),
1085                grub_pattern_type(
1086                    '/boot/efi/EFI/*/grubaa64.efi',
1087                    'grubaa64.efi',
1088                    'bootaa64.efi'
1089                ),
1090                grub_pattern_type(
1091                    '/boot/efi/EFI/*/grubriscv64.efi',
1092                    'grubriscv64.efi',
1093                    'bootriscv64.efi'
1094                )
1095            ],
1096            'iso': [
1097                grub_pattern_type(
1098                    '/boot/efi/EFI/*/gcdx64.efi',
1099                    'grubx64.efi',
1100                    'bootx64.efi'
1101                ),
1102                grub_pattern_type(
1103                    '/usr/share/grub*/x86_64-efi/grub.efi',
1104                    'grub.efi',
1105                    'bootx64.efi'
1106                ),
1107                grub_pattern_type(
1108                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1109                    'grub.efi',
1110                    'bootx64.efi'
1111                ),
1112                grub_pattern_type(
1113                    '/boot/efi/EFI/*/grubx64.efi',
1114                    'grubx64.efi',
1115                    'bootx64.efi'
1116                ),
1117                grub_pattern_type(
1118                    '/boot/efi/EFI/*/grubia32.efi',
1119                    'grubia32.efi',
1120                    'bootia32.efi'
1121                ),
1122                grub_pattern_type(
1123                    '/boot/efi/EFI/*/grubaa64.efi',
1124                    'grubaa64.efi',
1125                    'bootaa64.efi'
1126                ),
1127                grub_pattern_type(
1128                    '/boot/efi/EFI/*/grubriscv64.efi',
1129                    'grubriscv64.efi',
1130                    'bootriscv64.efi'
1131                )
1132            ]
1133        }
1134        for unsigned_grub_file_pattern in unsigned_grub_file_patterns[target_type]:
1135            for unsigned_grub_file in glob.iglob(
1136                root_path + unsigned_grub_file_pattern.pattern
1137            ):
1138                result.append(
1139                    grub_loader_type(
1140                        unsigned_grub_file,
1141                        unsigned_grub_file_pattern.binaryname,
1142                        unsigned_grub_file_pattern.targetname
1143                    )
1144                )
1145                # one match only expected, per pattern
1146                break
1147        return result

Provides unsigned grub efi loader file path

Searches distribution specific locations to find a distro grub EFI binary within the given root path

Parameters
  • string root_path: image root path
Returns

list of grub_loader_type

@staticmethod
def get_grub_chrp_loader(boot_path: str) -> str:
1149    @staticmethod
1150    def get_grub_chrp_loader(boot_path: str) -> str:
1151        """
1152        Lookup CHRP boot loader (ppc)
1153
1154        :param string boot_path: boot path
1155
1156        :return: file base name
1157
1158        :rtype: str
1159        """
1160        for chrp_loader in ['grub.elf', 'core.elf']:
1161            for grub_chrp in glob.iglob(
1162                os.sep.join(
1163                    [boot_path, 'boot/grub*/powerpc-ieee1275', chrp_loader]
1164                )
1165            ):
1166                log.info(f'Found CHRP loader at: {grub_chrp}')
1167                return os.path.basename(grub_chrp)
1168        raise KiwiBootLoaderGrubDataError(
1169            f'CHRP loader not found in {boot_path}'
1170        )

Lookup CHRP boot loader (ppc)

Parameters
  • string boot_path: boot path
Returns

file base name

@staticmethod
def get_grub_platform_core_loader(root_path):
1172    @staticmethod
1173    def get_grub_platform_core_loader(root_path):
1174        """
1175        Provides grub bios image
1176
1177        Searches distribution specific locations to find the
1178        core bios image below the given root path
1179
1180        :param string root_path: image root path
1181
1182        :return: file path or None
1183
1184        :rtype: str
1185        """
1186        bios_grub_core_patterns = [
1187            '/usr/share/grub*/{0}/{1}'.format(
1188                Defaults.get_grub_platform_module_directory_name(),
1189                Defaults.get_grub_platform_image_name()
1190            ),
1191            '/usr/lib/grub*/{0}/{1}'.format(
1192                Defaults.get_grub_platform_module_directory_name(),
1193                Defaults.get_grub_platform_image_name()
1194            )
1195        ]
1196        for bios_grub_core_pattern in bios_grub_core_patterns:
1197            for bios_grub_core in glob.iglob(
1198                root_path + bios_grub_core_pattern
1199            ):
1200                return bios_grub_core

Provides grub bios image

Searches distribution specific locations to find the core bios image below the given root path

Parameters
  • string root_path: image root path
Returns

file path or None

@staticmethod
def get_iso_grub_loader():
1202    @staticmethod
1203    def get_iso_grub_loader():
1204        """
1205        Return name of eltorito grub image used as ISO loader
1206
1207        :return: file base name
1208
1209        :rtype: str
1210        """
1211        return 'eltorito.img'

Return name of eltorito grub image used as ISO loader

Returns

file base name

@staticmethod
def get_iso_grub_mbr():
1213    @staticmethod
1214    def get_iso_grub_mbr():
1215        """
1216        Return name of hybrid MBR image used as ISO boot record
1217
1218        :return: file base name
1219
1220        :rtype: str
1221        """
1222        return 'boot_hybrid.img'

Return name of hybrid MBR image used as ISO boot record

Returns

file base name

@staticmethod
def get_signed_grub_loader( root_path: str, target_type: str = 'disk') -> List[grub_loader_type]:
1224    @staticmethod
1225    def get_signed_grub_loader(
1226        root_path: str, target_type: str = 'disk'
1227    ) -> List[grub_loader_type]:
1228        """
1229        Provides shim signed grub loader file path
1230
1231        Searches distribution specific locations to find a grub
1232        EFI binary within the given root path
1233
1234        :param str root_path: image root path
1235
1236        :return: list of grub_loader_type
1237
1238        :rtype: list
1239        """
1240        result = []
1241        grub_pattern_type = namedtuple(
1242            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1243        )
1244        signed_grub_file_patterns = {
1245            'disk': [
1246                grub_pattern_type(
1247                    '/usr/share/efi/*/grub.efi',
1248                    'grub.efi',
1249                    'bootx64.efi'
1250                ),
1251                grub_pattern_type(
1252                    '/usr/lib64/efi/grub.efi',
1253                    'grub.efi',
1254                    'bootx64.efi'
1255                ),
1256                grub_pattern_type(
1257                    '/boot/efi/EFI/*/grubx64.efi',
1258                    'grubx64.efi',
1259                    'bootx64.efi'
1260                ),
1261                grub_pattern_type(
1262                    '/boot/efi/EFI/*/grubia32.efi',
1263                    'grubia32.efi',
1264                    'bootia32.efi'
1265                ),
1266                grub_pattern_type(
1267                    '/boot/efi/EFI/*/grubaa64.efi',
1268                    'grubaa64.efi',
1269                    'bootaa64.efi'
1270                ),
1271                grub_pattern_type(
1272                    '/boot/efi/EFI/*/grubriscv64.efi',
1273                    'grubriscv64.efi',
1274                    'bootriscv64.efi'
1275                ),
1276                grub_pattern_type(
1277                    '/usr/share/grub*/*-efi/grub.efi',
1278                    'grub.efi',
1279                    'bootx64.efi'
1280                ),
1281                grub_pattern_type(
1282                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1283                    'grubx64.efi',
1284                    'bootx64.efi'
1285                )
1286            ],
1287            'iso': [
1288                grub_pattern_type(
1289                    '/boot/efi/EFI/*/gcdx64.efi',
1290                    'grubx64.efi',
1291                    'bootx64.efi'
1292                ),
1293                grub_pattern_type(
1294                    '/boot/efi/EFI/*/gcdaa64.efi',
1295                    'grubaa64.efi',
1296                    'bootaa64.efi'
1297                ),
1298                grub_pattern_type(
1299                    '/usr/share/efi/x86_64/grub.efi',
1300                    'grub.efi',
1301                    'grubx64.efi'
1302                ),
1303                grub_pattern_type(
1304                    '/usr/share/efi/aarch64/grub.efi',
1305                    'grub.efi',
1306                    'grubaa64.efi'
1307                ),
1308                grub_pattern_type(
1309                    '/usr/lib64/efi/grub.efi',
1310                    'grub.efi',
1311                    'bootx64.efi'
1312                ),
1313                grub_pattern_type(
1314                    '/boot/efi/EFI/*/grubx64.efi',
1315                    'grubx64.efi',
1316                    'bootx64.efi'
1317                ),
1318                grub_pattern_type(
1319                    '/boot/efi/EFI/*/grubia32.efi',
1320                    'grubia32.efi',
1321                    'bootia32.efi'
1322                ),
1323                grub_pattern_type(
1324                    '/boot/efi/EFI/*/grubaa64.efi',
1325                    'grubaa64.efi',
1326                    'bootaa64.efi'
1327                ),
1328                grub_pattern_type(
1329                    '/boot/efi/EFI/*/grubriscv64.efi',
1330                    'grubriscv64.efi',
1331                    'bootriscv64.efi'
1332                ),
1333                grub_pattern_type(
1334                    '/usr/share/grub*/x86_64-efi/grub.efi',
1335                    'grub.efi',
1336                    'bootx64.efi'
1337                ),
1338                grub_pattern_type(
1339                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1340                    'grubx64.efi',
1341                    'bootx64.efi'
1342                )
1343            ]
1344        }
1345        for signed_grub in signed_grub_file_patterns[target_type]:
1346            for signed_grub_file in glob.iglob(root_path + signed_grub.pattern):
1347                result.append(
1348                    grub_loader_type(
1349                        signed_grub_file,
1350                        signed_grub.binaryname,
1351                        signed_grub.targetname
1352                    )
1353                )
1354                # one match only expected, per pattern
1355                break
1356        return result

Provides shim signed grub loader file path

Searches distribution specific locations to find a grub EFI binary within the given root path

Parameters
  • str root_path: image root path
Returns

list of grub_loader_type

@staticmethod
def get_efi_vendor_directory(efi_path):
1358    @staticmethod
1359    def get_efi_vendor_directory(efi_path):
1360        """
1361        Provides EFI vendor directory if present
1362
1363        Looks up distribution specific EFI vendor directory
1364
1365        :param string root_path: path to efi mountpoint
1366
1367        :return: directory path or None
1368
1369        :rtype: str
1370        """
1371        efi_vendor_directories = [
1372            'EFI/fedora',
1373            'EFI/redhat',
1374            'EFI/centos',
1375            'EFI/almalinux',
1376            'EFI/opensuse',
1377            'EFI/ubuntu',
1378            'EFI/debian'
1379        ]
1380        for efi_vendor_directory in efi_vendor_directories:
1381            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1382            if os.path.exists(efi_vendor_directory):
1383                return efi_vendor_directory

Provides EFI vendor directory if present

Looks up distribution specific EFI vendor directory

Parameters
  • string root_path: path to efi mountpoint
Returns

directory path or None

@staticmethod
def get_vendor_grubenv(efi_path):
1385    @staticmethod
1386    def get_vendor_grubenv(efi_path):
1387        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1388        if efi_vendor_directory:
1389            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1390            if os.path.exists(grubenv):
1391                return grubenv
@staticmethod
def get_shim_vendor_directory(root_path):
1393    @staticmethod
1394    def get_shim_vendor_directory(root_path):
1395        """
1396        Provides shim vendor directory
1397
1398        Searches distribution specific locations to find shim.efi
1399        below the given root path and return the directory name
1400        to the file found
1401
1402        :param string root_path: image root path
1403
1404        :return: directory path or None
1405
1406        :rtype: str
1407        """
1408        shim_vendor_patterns = [
1409            '/boot/efi/EFI/*/shim*.efi',
1410            '/EFI/*/shim*.efi'
1411        ]
1412        for shim_vendor_pattern in shim_vendor_patterns:
1413            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1414                return os.path.dirname(shim_file)

Provides shim vendor directory

Searches distribution specific locations to find shim.efi below the given root path and return the directory name to the file found

Parameters
  • string root_path: image root path
Returns

directory path or None

@staticmethod
def get_default_volume_group_name():
1416    @staticmethod
1417    def get_default_volume_group_name():
1418        """
1419        Provides default LVM volume group name
1420
1421        :return: name
1422
1423        :rtype: str
1424        """
1425        return 'systemVG'

Provides default LVM volume group name

Returns

name

@staticmethod
def get_min_partition_mbytes():
1427    @staticmethod
1428    def get_min_partition_mbytes():
1429        """
1430        Provides default minimum partition size in mbytes
1431
1432        :return: mbsize value
1433
1434        :rtype: int
1435        """
1436        return 10

Provides default minimum partition size in mbytes

Returns

mbsize value

@staticmethod
def get_min_volume_mbytes(filesystem: str):
1438    @staticmethod
1439    def get_min_volume_mbytes(filesystem: str):
1440        """
1441        Provides default minimum LVM volume size in mbytes
1442        per filesystem
1443
1444        :return: mbsize value
1445
1446        :rtype: int
1447        """
1448        if filesystem == 'btrfs':
1449            return 120
1450        elif filesystem == 'xfs':
1451            return 300
1452        else:
1453            return 30

Provides default minimum LVM volume size in mbytes per filesystem

Returns

mbsize value

@staticmethod
def get_lvm_overhead_mbytes():
1455    @staticmethod
1456    def get_lvm_overhead_mbytes():
1457        """
1458        Provides empiric LVM overhead size in mbytes
1459
1460        :return: mbsize value
1461
1462        :rtype: int
1463        """
1464        return 80

Provides empiric LVM overhead size in mbytes

Returns

mbsize value

@staticmethod
def get_default_boot_mbytes():
1466    @staticmethod
1467    def get_default_boot_mbytes():
1468        """
1469        Provides default boot partition size in mbytes
1470
1471        :return: mbsize value
1472
1473        :rtype: int
1474        """
1475        return 300

Provides default boot partition size in mbytes

Returns

mbsize value

@staticmethod
def get_default_efi_boot_mbytes():
1477    @staticmethod
1478    def get_default_efi_boot_mbytes():
1479        """
1480        Provides default EFI partition size in mbytes
1481
1482        :return: mbsize value
1483
1484        :rtype: int
1485        """
1486        return 20

Provides default EFI partition size in mbytes

Returns

mbsize value

@staticmethod
def get_recovery_spare_mbytes():
1488    @staticmethod
1489    def get_recovery_spare_mbytes():
1490        """
1491        Provides spare size of recovery partition in mbytes
1492
1493        :return: mbsize value
1494
1495        :rtype: int
1496        """
1497        return 300

Provides spare size of recovery partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_legacy_bios_mbytes():
1499    @staticmethod
1500    def get_default_legacy_bios_mbytes():
1501        """
1502        Provides default size of bios_grub partition in mbytes
1503
1504        :return: mbsize value
1505
1506        :rtype: int
1507        """
1508        return 2

Provides default size of bios_grub partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_prep_mbytes():
1510    @staticmethod
1511    def get_default_prep_mbytes():
1512        """
1513        Provides default size of prep partition in mbytes
1514
1515        :return: mbsize value
1516
1517        :rtype: int
1518        """
1519        return 8

Provides default size of prep partition in mbytes

Returns

mbsize value

@staticmethod
def get_disk_format_types():
1521    @staticmethod
1522    def get_disk_format_types():
1523        """
1524        Provides supported disk format types
1525
1526        :return: disk types
1527
1528        :rtype: list
1529        """
1530        return [
1531            'gce',
1532            'qcow2',
1533            'vmdk',
1534            'ova',
1535            'meta',
1536            'vmx',
1537            'vhd',
1538            'vhdx',
1539            'vhdfixed',
1540            'vdi',
1541            'vagrant.libvirt.box',
1542            'vagrant.virtualbox.box',
1543            'oci'
1544        ]

Provides supported disk format types

Returns

disk types

@staticmethod
def get_vagrant_config_virtualbox_guest_additions():
1546    @staticmethod
1547    def get_vagrant_config_virtualbox_guest_additions():
1548        """
1549        Provides the default value for
1550        ``vagrantconfig.virtualbox_guest_additions_present``
1551
1552        :return: whether guest additions are expected to be present in the
1553            vagrant box
1554
1555        :rtype: bool
1556        """
1557        return False

Provides the default value for vagrantconfig.virtualbox_guest_additions_present

Returns

whether guest additions are expected to be present in the vagrant box

@staticmethod
def get_firmware_types():
1559    @staticmethod
1560    def get_firmware_types():
1561        """
1562        Provides supported architecture specific firmware types
1563
1564        :return: firmware types per architecture
1565
1566        :rtype: dict
1567        """
1568        return {
1569            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1570            'i586': ['bios'],
1571            'i686': ['bios'],
1572            'ix86': ['bios'],
1573            'aarch64': ['efi', 'uefi'],
1574            'arm64': ['efi', 'uefi'],
1575            'armv5el': ['efi', 'uefi'],
1576            'armv5tel': ['efi', 'uefi'],
1577            'armv6hl': ['efi', 'uefi'],
1578            'armv6l': ['efi', 'uefi'],
1579            'armv7hl': ['efi', 'uefi'],
1580            'armv7l': ['efi', 'uefi'],
1581            'armv8l': ['efi', 'uefi'],
1582            'loongarch64': ['efi', 'uefi'],
1583            'ppc': ['ofw'],
1584            'ppc64': ['ofw', 'opal'],
1585            'ppc64le': ['ofw', 'opal'],
1586            'riscv64': ['efi', 'uefi'],
1587            's390': [],
1588            's390x': []
1589        }

Provides supported architecture specific firmware types

Returns

firmware types per architecture

@staticmethod
def get_default_firmware(arch):
1591    @staticmethod
1592    def get_default_firmware(arch):
1593        """
1594        Provides default firmware for specified architecture
1595
1596        :param string arch: machine architecture name
1597
1598        :return: firmware name
1599
1600        :rtype: str
1601        """
1602        default_firmware = {
1603            'x86_64': 'bios',
1604            'i586': 'bios',
1605            'i686': 'bios',
1606            'ix86': 'bios',
1607            'loongarch64': 'efi',
1608            'ppc': 'ofw',
1609            'ppc64': 'ofw',
1610            'ppc64le': 'ofw',
1611            'arm64': 'efi',
1612            'aarch64': 'efi',
1613            'armv5el': 'efi',
1614            'armv5tel': 'efi',
1615            'armv6hl': 'efi',
1616            'armv6l': 'efi',
1617            'armv7hl': 'efi',
1618            'armv7l': 'efi',
1619            'armv8l': 'efi',
1620            'riscv64': 'efi'
1621        }
1622        if arch in default_firmware:
1623            return default_firmware[arch]

Provides default firmware for specified architecture

Parameters
  • string arch: machine architecture name
Returns

firmware name

@staticmethod
def get_efi_capable_firmware_names():
1625    @staticmethod
1626    def get_efi_capable_firmware_names():
1627        """
1628        Provides list of EFI capable firmware names. These are
1629        those for which kiwi supports the creation of an EFI
1630        bootable disk image
1631
1632        :return: firmware names
1633
1634        :rtype: list
1635        """
1636        return ['efi', 'uefi']

Provides list of EFI capable firmware names. These are those for which kiwi supports the creation of an EFI bootable disk image

Returns

firmware names

@staticmethod
def get_ec2_capable_firmware_names():
1638    @staticmethod
1639    def get_ec2_capable_firmware_names():
1640        """
1641        Provides list of EC2 capable firmware names. These are
1642        those for which kiwi supports the creation of disk images
1643        bootable within the Amazon EC2 public cloud
1644
1645        :return: firmware names
1646
1647        :rtype: list
1648        """
1649        return ['ec2']

Provides list of EC2 capable firmware names. These are those for which kiwi supports the creation of disk images bootable within the Amazon EC2 public cloud

Returns

firmware names

@staticmethod
def get_efi_module_directory_name(arch):
1651    @staticmethod
1652    def get_efi_module_directory_name(arch):
1653        """
1654        Provides architecture specific EFI directory name which
1655        stores the EFI binaries for the desired architecture.
1656
1657        :param string arch: machine architecture name
1658
1659        :return: directory name
1660
1661        :rtype: str
1662        """
1663        default_module_directory_names = {
1664            'x86_64': 'x86_64-efi',
1665            'i386': 'i386-efi',
1666
1667            # There is no dedicated xen architecture but there are
1668            # modules provided for xen. Thus we treat it as an
1669            # architecture
1670            'x86_64_xen': 'x86_64-xen',
1671
1672            'aarch64': 'arm64-efi',
1673            'arm64': 'arm64-efi',
1674            'armv5el': 'arm-efi',
1675            'armv5tel': 'arm-efi',
1676            'armv6l': 'arm-efi',
1677            'armv7l': 'arm-efi',
1678            'armv8l': 'arm-efi',
1679            'loongarch64': 'loongarch64-efi',
1680            'riscv64': 'riscv64-efi'
1681        }
1682        if arch in default_module_directory_names:
1683            return default_module_directory_names[arch]

Provides architecture specific EFI directory name which stores the EFI binaries for the desired architecture.

Parameters
  • string arch: machine architecture name
Returns

directory name

@staticmethod
def get_grub_platform_module_directory_name():
1685    @staticmethod
1686    def get_grub_platform_module_directory_name():
1687        """
1688        Provides grub platform specific directory name which
1689        stores the grub module binaries
1690
1691        :return: directory name
1692
1693        :rtype: str
1694        """
1695        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1696            Defaults.get_platform_name()
1697        ) else 'i386-pc'

Provides grub platform specific directory name which stores the grub module binaries

Returns

directory name

@staticmethod
def get_efi_image_name(arch):
1699    @staticmethod
1700    def get_efi_image_name(arch):
1701        """
1702        Provides architecture specific EFI boot binary name
1703
1704        :param string arch: machine architecture name
1705
1706        :return: name
1707
1708        :rtype: str
1709        """
1710        default_efi_image_names = {
1711            'x86_64': 'bootx64.efi',
1712            'i386': 'bootia32.efi',
1713            'aarch64': 'bootaa64.efi',
1714            'arm64': 'bootaa64.efi',
1715            'armv5el': 'bootarm.efi',
1716            'armv5tel': 'bootarm.efi',
1717            'armv6l': 'bootarm.efi',
1718            'armv7l': 'bootarm.efi',
1719            'armv8l': 'bootarm.efi',
1720            'loongarch64': 'bootloongarch64.efi',
1721            'riscv64': 'bootriscv64.efi'
1722        }
1723        if arch in default_efi_image_names:
1724            return default_efi_image_names[arch]

Provides architecture specific EFI boot binary name

Parameters
  • string arch: machine architecture name
Returns

name

@staticmethod
def get_grub_platform_image_name():
1726    @staticmethod
1727    def get_grub_platform_image_name():
1728        """
1729        Provides platform specific core boot binary name
1730
1731        :return: name
1732
1733        :rtype: str
1734        """
1735        return 'grub.elf' if Defaults.is_ppc64_arch(
1736            Defaults.get_platform_name()
1737        ) else 'core.img'

Provides platform specific core boot binary name

Returns

name

@staticmethod
def get_default_boot_timeout_seconds():
1739    @staticmethod
1740    def get_default_boot_timeout_seconds():
1741        """
1742        Provides default boot timeout in seconds
1743
1744        :return: seconds
1745
1746        :rtype: int
1747        """
1748        return 10

Provides default boot timeout in seconds

Returns

seconds

@staticmethod
def get_default_disk_start_sector():
1750    @staticmethod
1751    def get_default_disk_start_sector():
1752        """
1753        Provides the default initial disk sector for the first disk
1754        partition.
1755
1756        :return: sector value
1757
1758        :rtype: int
1759        """
1760        return Defaults().defaults['kiwi_startsector']

Provides the default initial disk sector for the first disk partition.

Returns

sector value

@staticmethod
def get_default_efi_partition_table_type():
1762    @staticmethod
1763    def get_default_efi_partition_table_type():
1764        """
1765        Provides the default partition table type for efi firmwares.
1766
1767        :return: partition table type name
1768
1769        :rtype: str
1770        """
1771        return 'gpt'

Provides the default partition table type for efi firmwares.

Returns

partition table type name

@staticmethod
def get_default_inode_size():
1773    @staticmethod
1774    def get_default_inode_size():
1775        """
1776        Provides default size of inodes in bytes. This is only
1777        relevant for inode based filesystems
1778
1779        :return: bytesize value
1780
1781        :rtype: int
1782        """
1783        return Defaults().defaults['kiwi_inode_size']

Provides default size of inodes in bytes. This is only relevant for inode based filesystems

Returns

bytesize value

@staticmethod
def get_archive_image_types():
1785    @staticmethod
1786    def get_archive_image_types():
1787        """
1788        Provides list of supported archive image types
1789
1790        :return: archive names
1791
1792        :rtype: list
1793        """
1794        return ['tbz', 'cpio']

Provides list of supported archive image types

Returns

archive names

@staticmethod
def get_container_image_types():
1796    @staticmethod
1797    def get_container_image_types():
1798        """
1799        Provides list of supported container image types
1800
1801        :return: container names
1802
1803        :rtype: list
1804        """
1805        return ['docker', 'oci', 'appx', 'wsl']

Provides list of supported container image types

Returns

container names

@staticmethod
def get_filesystem_image_types():
1807    @staticmethod
1808    def get_filesystem_image_types():
1809        """
1810        Provides list of supported filesystem image types
1811
1812        :return: filesystem names
1813
1814        :rtype: list
1815        """
1816        return [
1817            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1818            'xfs', 'fat16', 'fat32', 'erofs'
1819        ]

Provides list of supported filesystem image types

Returns

filesystem names

@staticmethod
def get_default_live_iso_type():
1821    @staticmethod
1822    def get_default_live_iso_type():
1823        """
1824        Provides default live iso union type
1825
1826        :return: live iso type
1827
1828        :rtype: str
1829        """
1830        return 'overlay'

Provides default live iso union type

Returns

live iso type

@staticmethod
def get_default_uri_type():
1832    @staticmethod
1833    def get_default_uri_type():
1834        """
1835        Provides default URI type
1836
1837        Absolute path specifications used in the context of an URI
1838        will apply the specified default mime type
1839
1840        :return: URI mime type
1841
1842        :rtype: str
1843        """
1844        return 'dir:/'

Provides default URI type

Absolute path specifications used in the context of an URI will apply the specified default mime type

Returns

URI mime type

@staticmethod
def get_dracut_conf_name():
1846    @staticmethod
1847    def get_dracut_conf_name():
1848        """
1849        Provides file path of dracut config file to be used with KIWI
1850
1851        :return: file path name
1852
1853        :rtype: str
1854        """
1855        return '/etc/dracut.conf.d/02-kiwi.conf'

Provides file path of dracut config file to be used with KIWI

Returns

file path name

@staticmethod
def get_live_dracut_modules_from_flag(flag_name):
1857    @staticmethod
1858    def get_live_dracut_modules_from_flag(flag_name):
1859        """
1860        Provides flag_name to dracut modules name map
1861
1862        Depending on the value of the flag attribute in the KIWI image
1863        description specific dracut modules need to be selected
1864
1865        :return: dracut module names as list
1866
1867        :rtype: list
1868        """
1869        live_modules = {
1870            'overlay': ['kiwi-live'],
1871            'dmsquash': ['dmsquash-live', 'livenet']
1872        }
1873        if flag_name in live_modules:
1874            return live_modules[flag_name]
1875        else:
1876            return ['kiwi-live']

Provides flag_name to dracut modules name map

Depending on the value of the flag attribute in the KIWI image description specific dracut modules need to be selected

Returns

dracut module names as list

@staticmethod
def get_default_live_iso_root_filesystem():
1878    @staticmethod
1879    def get_default_live_iso_root_filesystem():
1880        """
1881        Provides default live iso root filesystem type
1882
1883        :return: filesystem name
1884
1885        :rtype: str
1886        """
1887        return 'ext4'

Provides default live iso root filesystem type

Returns

filesystem name

@staticmethod
def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1889    @staticmethod
1890    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1891        """
1892        Provides list of boot options passed to the dracut
1893        kiwi-live module to setup persistent writing
1894
1895        :return: list of boot options
1896
1897        :rtype: list
1898        """
1899        live_iso_persistent_boot_options = [
1900            'rd.live.overlay.persistent'
1901        ]
1902        if persistent_filesystem:
1903            live_iso_persistent_boot_options.append(
1904                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1905            )
1906        return live_iso_persistent_boot_options

Provides list of boot options passed to the dracut kiwi-live module to setup persistent writing

Returns

list of boot options

@staticmethod
def get_disk_image_types():
1908    @staticmethod
1909    def get_disk_image_types():
1910        """
1911        Provides supported disk image types
1912
1913        :return: disk image type names
1914
1915        :rtype: list
1916        """
1917        return ['oem']

Provides supported disk image types

Returns

disk image type names

@staticmethod
def get_live_image_types():
1919    @staticmethod
1920    def get_live_image_types():
1921        """
1922        Provides supported live image types
1923
1924        :return: live image type names
1925
1926        :rtype: list
1927        """
1928        return ['iso']

Provides supported live image types

Returns

live image type names

@staticmethod
def get_kis_image_types():
1930    @staticmethod
1931    def get_kis_image_types():
1932        """
1933        Provides supported kis image types
1934
1935        :return: kis image type names
1936
1937        :rtype: list
1938        """
1939        return ['kis', 'pxe']

Provides supported kis image types

Returns

kis image type names

@staticmethod
def get_enclaves_image_types():
1941    @staticmethod
1942    def get_enclaves_image_types():
1943        """
1944        Provides supported enclave(initrd-only) image types
1945
1946        :return: enclave image type names
1947
1948        :rtype: list
1949        """
1950        return ['enclave']

Provides supported enclave(initrd-only) image types

Returns

enclave image type names

@staticmethod
def get_boot_image_description_path():
1952    @staticmethod
1953    def get_boot_image_description_path():
1954        """
1955        Provides the path to find custom kiwi boot descriptions
1956
1957        :return: directory path
1958
1959        :rtype: str
1960        """
1961        return '/usr/share/kiwi/custom_boot'

Provides the path to find custom kiwi boot descriptions

Returns

directory path

@staticmethod
def get_boot_image_strip_file():
1963    @staticmethod
1964    def get_boot_image_strip_file():
1965        """
1966        Provides the file path to bootloader strip metadata.
1967        This file contains information about the files and directories
1968        automatically striped out from the kiwi initrd
1969
1970        :return: file path
1971
1972        :rtype: str
1973        """
1974        return Defaults.project_file('config/strip.xml')

Provides the file path to bootloader strip metadata. This file contains information about the files and directories automatically striped out from the kiwi initrd

Returns

file path

@staticmethod
def get_schema_file():
1976    @staticmethod
1977    def get_schema_file():
1978        """
1979        Provides file path to kiwi RelaxNG schema
1980
1981        :return: file path
1982
1983        :rtype: str
1984        """
1985        return Defaults.project_file('schema/kiwi.rng')

Provides file path to kiwi RelaxNG schema

Returns

file path

@staticmethod
def get_common_functions_file():
1987    @staticmethod
1988    def get_common_functions_file():
1989        """
1990        Provides the file path to config functions metadata.
1991
1992        This file contains bash functions used for system
1993        configuration or in the boot code from the kiwi initrd
1994
1995        :return: file path
1996
1997        :rtype: str
1998        """
1999        return Defaults.project_file('config/functions.sh')

Provides the file path to config functions metadata.

This file contains bash functions used for system configuration or in the boot code from the kiwi initrd

Returns

file path

@staticmethod
def get_xsl_stylesheet_file():
2001    @staticmethod
2002    def get_xsl_stylesheet_file():
2003        """
2004        Provides the file path to the KIWI XSLT style sheets
2005
2006        :return: file path
2007
2008        :rtype: str
2009        """
2010        return Defaults.project_file('xsl/master.xsl')

Provides the file path to the KIWI XSLT style sheets

Returns

file path

@staticmethod
def get_schematron_module_name():
2012    @staticmethod
2013    def get_schematron_module_name():
2014        """
2015        Provides module name for XML SchemaTron validations
2016
2017        :return: python module name
2018
2019        :rtype: str
2020        """
2021        return 'lxml.isoschematron'

Provides module name for XML SchemaTron validations

Returns

python module name

@staticmethod
def project_file(filename):
2023    @staticmethod
2024    def project_file(filename):
2025        """
2026        Provides the python module base directory search path
2027
2028        The method uses the importlib.resources.path method to identify
2029        files and directories from the application
2030
2031        :param string filename: relative project file
2032
2033        :return: absolute file path name
2034
2035        :rtype: str
2036        """
2037        with as_file(importlib.resources.files('kiwi')) as path:
2038            return f'{path}/{filename}'

Provides the python module base directory search path

The method uses the importlib.resources.path method to identify files and directories from the application

Parameters
  • string filename: relative project file
Returns

absolute file path name

@staticmethod
def get_imported_root_image(root_dir):
2040    @staticmethod
2041    def get_imported_root_image(root_dir):
2042        """
2043        Provides the path to an imported root system image
2044
2045        If the image description specified a derived_from attribute
2046        the file from this attribute is copied into the root_dir
2047        using the name as provided by this method
2048
2049        :param string root_dir: image root directory
2050
2051        :return: file path name
2052
2053        :rtype: str
2054        """
2055        return os.sep.join([root_dir, 'image', 'imported_root'])

Provides the path to an imported root system image

If the image description specified a derived_from attribute the file from this attribute is copied into the root_dir using the name as provided by this method

Parameters
  • string root_dir: image root directory
Returns

file path name

@staticmethod
def get_iso_boot_path():
2057    @staticmethod
2058    def get_iso_boot_path():
2059        """
2060        Provides arch specific relative path to boot files
2061        on kiwi iso filesystems
2062
2063        :return: relative path name
2064
2065        :rtype: str
2066        """
2067        return os.sep.join(
2068            ['boot', Defaults.get_platform_name()]
2069        )

Provides arch specific relative path to boot files on kiwi iso filesystems

Returns

relative path name

@staticmethod
def get_iso_tool_category():
2071    @staticmethod
2072    def get_iso_tool_category():
2073        """
2074        Provides default iso tool category
2075
2076        :return: name
2077
2078        :rtype: str
2079        """
2080        return 'xorriso'

Provides default iso tool category

Returns

name

@staticmethod
def get_iso_media_tag_tool():
2082    @staticmethod
2083    def get_iso_media_tag_tool():
2084        """
2085        Provides default iso media tag tool
2086
2087        :return: name
2088
2089        :rtype: str
2090        """
2091        return 'checkmedia'

Provides default iso media tag tool

Returns

name

@staticmethod
def get_container_compression():
2093    @staticmethod
2094    def get_container_compression():
2095        """
2096        Provides default container compression
2097
2098        :return: True
2099
2100        :rtype: bool
2101        """
2102        return True

Provides default container compression

Returns

True

@staticmethod
def get_default_container_name():
2104    @staticmethod
2105    def get_default_container_name():
2106        """
2107        Provides the default container name.
2108
2109        :return: name
2110
2111        :rtype: str
2112        """
2113        return 'kiwi-container'

Provides the default container name.

Returns

name

@staticmethod
def get_container_base_image_tag():
2115    @staticmethod
2116    def get_container_base_image_tag():
2117        """
2118        Provides the tag used to identify base layers during the build
2119        of derived images.
2120
2121        :return: tag
2122
2123        :rtype: str
2124        """
2125        return 'base_layer'

Provides the tag used to identify base layers during the build of derived images.

Returns

tag

@staticmethod
def get_oci_archive_tool():
2127    @staticmethod
2128    def get_oci_archive_tool():
2129        """
2130        Provides the default OCI archive tool name.
2131
2132        :return: name
2133
2134        :rtype: str
2135        """
2136        return 'umoci'

Provides the default OCI archive tool name.

Returns

name

@staticmethod
def get_part_mapper_tool():
2138    @staticmethod
2139    def get_part_mapper_tool():
2140        """
2141        Provides the default partition mapper tool name.
2142
2143        :return: name
2144
2145        :rtype: str
2146        """
2147        host_architecture = Defaults.get_platform_name()
2148        if 's390' in host_architecture:
2149            return 'kpartx'
2150        return 'partx'

Provides the default partition mapper tool name.

Returns

name

@staticmethod
def get_default_container_tag():
2152    @staticmethod
2153    def get_default_container_tag():
2154        """
2155        Provides the default container tag.
2156
2157        :return: tag
2158
2159        :rtype: str
2160        """
2161        return 'latest'

Provides the default container tag.

Returns

tag

@staticmethod
def get_default_container_subcommand():
2163    @staticmethod
2164    def get_default_container_subcommand():
2165        """
2166        Provides the default container subcommand.
2167
2168        :return: command as a list of arguments
2169
2170        :rtype: list
2171        """
2172        return ['/bin/bash']

Provides the default container subcommand.

Returns

command as a list of arguments

@staticmethod
def get_default_container_created_by():
2174    @staticmethod
2175    def get_default_container_created_by():
2176        """
2177        Provides the default 'created by' history entry for containers.
2178
2179        :return: the specific kiwi version used for the build
2180
2181        :rtype: str
2182        """
2183        return 'KIWI {0}'.format(__version__)

Provides the default 'created by' history entry for containers.

Returns

the specific kiwi version used for the build

@staticmethod
def get_custom_rpm_macros_path():
2185    @staticmethod
2186    def get_custom_rpm_macros_path():
2187        """
2188        Returns the custom macros directory for the rpm database.
2189
2190        :return: path name
2191
2192        :rtype: str
2193        """
2194        return 'usr/lib/rpm/macros.d'

Returns the custom macros directory for the rpm database.

Returns

path name

@staticmethod
def get_custom_rpm_bootstrap_macro_name():
2196    @staticmethod
2197    def get_custom_rpm_bootstrap_macro_name():
2198        """
2199        Returns the rpm bootstrap macro file name created
2200        in the custom rpm macros path
2201
2202        :return: filename
2203
2204        :rtype: str
2205        """
2206        return 'macros.kiwi-bootstrap-config'

Returns the rpm bootstrap macro file name created in the custom rpm macros path

Returns

filename

@staticmethod
def get_custom_rpm_image_macro_name():
2208    @staticmethod
2209    def get_custom_rpm_image_macro_name():
2210        """
2211        Returns the rpm image macro file name created
2212        in the custom rpm macros path
2213
2214        :return: filename
2215
2216        :rtype: str
2217        """
2218        return 'macros.kiwi-image-config'

Returns the rpm image macro file name created in the custom rpm macros path

Returns

filename

@staticmethod
def get_default_package_manager() -> str:
2220    @staticmethod
2221    def get_default_package_manager() -> str:
2222        """
2223        Returns the default package manager name if none
2224        is configured in the image description
2225
2226        :return: package manager name
2227
2228        :rtype: str
2229        """
2230        return 'dnf4'

Returns the default package manager name if none is configured in the image description

Returns

package manager name

@staticmethod
def get_default_packager_tool(package_manager):
2232    @staticmethod
2233    def get_default_packager_tool(package_manager):
2234        """
2235        Provides the packager tool according to the package manager
2236
2237        :param string package_manager: package manger name
2238
2239        :return: packager tool binary name
2240
2241        :rtype: str
2242        """
2243        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2244        deb_based = ['apt']
2245        if package_manager in rpm_based:
2246            return 'rpm'
2247        elif package_manager in deb_based:
2248            return 'dpkg'
2249        elif package_manager == 'pacman':
2250            return 'pacman'

Provides the packager tool according to the package manager

Parameters
  • string package_manager: package manger name
Returns

packager tool binary name

@staticmethod
def get_discoverable_partition_ids() -> Dict[str, str]:
2252    @staticmethod
2253    def get_discoverable_partition_ids() -> Dict[str, str]:
2254        """
2255        Provides arch specific partition UUIDs as defined
2256        by the UAPI group
2257
2258        :return: partition UUIDs
2259
2260        :rtype: dict
2261        """
2262        arch = Defaults.get_platform_name()
2263        part_uuids_archs = {
2264            'x86_64': {
2265                'root':
2266                    '4f68bce3e8cd4db196e7fbcaf984b709',
2267                'usr':
2268                    '8484680c952148c69c11b0720656f69e',
2269                'usr-verity':
2270                    '77ff5f63e7b64633acf41565b864c0e6'
2271            },
2272            'ix86': {
2273                'root':
2274                    '44479540f29741b29af7d131d5f0458a',
2275                'usr':
2276                    '75250d768cc6458ebd66bd47cc81a812',
2277                'usr-verity':
2278                    '8f461b0d14ee4e819aa9049b6fb97abd'
2279            },
2280            'aarch64': {
2281                'root':
2282                    'b921b0451df041c3af444c6f280d3fae',
2283                'usr':
2284                    'b0e01050ee5f4390949a9101b17104e9',
2285                'usr-verity':
2286                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2287            },
2288            'riscv64': {
2289                'root':
2290                    '72ec70a6cf7440e6bd494bda08e8f224',
2291                'usr':
2292                    'beaec34b8442439ba40b984381ed097d',
2293                'usr-verity':
2294                    '8f1056be9b0547c481d6be53128e5b54'
2295            }
2296        }
2297        part_uuids_arch = part_uuids_archs.get(arch) or {}
2298        return {
2299            'root':
2300                part_uuids_arch.get('root') or '',
2301            'usr':
2302                part_uuids_arch.get('usr') or '',
2303            'usr-verity':
2304                part_uuids_arch.get('usr-verity') or '',
2305            'usr-secondary':
2306                '75250d768cc6458ebd66bd47cc81a812',
2307            'usr-secondary-verity':
2308                '8f461b0d14ee4e819aa9049b6fb97abd',
2309            'esp':
2310                'c12a7328f81f11d2ba4b00a0c93ec93b',
2311            'xbootldr':
2312                'bc13c2ff59e64262a352b275fd6f7172',
2313            'swap':
2314                '0657fd6da4ab43c484e50933c84b4f4f',
2315            'home':
2316                '933ac7e12eb44f13b8440e14e2aef915',
2317            'srv':
2318                '3b8f842520e04f3b907f1a25a76f98e8',
2319            'var':
2320                '4d21b016b53445c2a9fb5c16e091fd2d',
2321            'tmp':
2322                '7ec6f5573bc54acab29316ef5df639d1',
2323            'user-home':
2324                '773f91ef66d449b5bd83d683bf40ad16',
2325            'linux-generic':
2326                '0fc63daf848347728e793d69d8477de4'
2327        }

Provides arch specific partition UUIDs as defined by the UAPI group

Returns

partition UUIDs

@staticmethod
def get_bls_loader_entries_dir() -> str:
2329    @staticmethod
2330    def get_bls_loader_entries_dir() -> str:
2331        """
2332        Provide default loader entries directory for BLS loaders
2333
2334        :return: directory name
2335
2336        :rtype: str
2337        """
2338        return '/boot/loader/entries'

Provide default loader entries directory for BLS loaders

Returns

directory name

@staticmethod
def get_apk_repo_config() -> str:
2340    @staticmethod
2341    def get_apk_repo_config() -> str:
2342        """
2343        Repository file for apk
2344
2345        :return: file path name
2346
2347        :rtype: str
2348        """
2349        return '/etc/apk/repositories'

Repository file for apk

Returns

file path name

@staticmethod
def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2351    @staticmethod
2352    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2353        return CA_UPDATE_MAP.get(target_distribution)
@staticmethod
def get_ca_target_distributions() -> List[str]:
2355    @staticmethod
2356    def get_ca_target_distributions() -> List[str]:
2357        return sorted(CA_UPDATE_MAP.keys())
def get(self, key):
2359    def get(self, key):
2360        """
2361        Implements get method for profile elements
2362
2363        :param string key: profile keyname
2364
2365        :return: key value
2366
2367        :rtype: str
2368        """
2369        if key in self.defaults:
2370            return self.defaults[key]

Implements get method for profile elements

Parameters
  • string key: profile keyname
Returns

key value

@staticmethod
def get_profile_file(root_dir):
2372    @staticmethod
2373    def get_profile_file(root_dir):
2374        """
2375        Return name of profile file for given root directory
2376        """
2377        return root_dir + '/.profile'

Return name of profile file for given root directory

def to_profile(self, profile):
2379    def to_profile(self, profile):
2380        """
2381        Implements method to add list of profile keys and their values
2382        to the specified instance of a Profile class
2383
2384        :param object profile: Profile instance
2385        """
2386        for key in sorted(self.profile_key_list):
2387            # Do not apply default values to any variable that was
2388            # already defined in the profile instance.
2389            cur_profile = profile.dot_profile
2390            if key not in cur_profile or cur_profile[key] is None:
2391                profile.add(key, self.get(key))

Implements method to add list of profile keys and their values to the specified instance of a Profile class

Parameters
  • object profile: Profile instance