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

Provides key length to use for random luks keys

@staticmethod
def get_swapsize_mbytes():
165    @staticmethod
166    def get_swapsize_mbytes():
167        """
168        Provides swapsize in MB
169        """
170        return 128

Provides swapsize in MB

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

Provides compression options for the xz compressor

Returns
Contains list of options

.. code:: python

    ['--option=value']
@staticmethod
def get_platform_name():
190    @staticmethod
191    def get_platform_name():
192        """
193        Provides the machine architecture name as used by KIWI
194
195        This is the architecture name as it is returned by 'uname -m'
196        with one exception for the 32bit x86 architecture which is
197        handled as 'ix86' in general
198
199        :return: architecture name
200
201        :rtype: str
202        """
203        arch = PLATFORM_MACHINE
204        if arch == 'i686' or arch == 'i586':
205            arch = 'ix86'
206        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):
208    @staticmethod
209    def set_platform_name(name: str):
210        """
211        Sets the platform architecture once
212
213        :param str name: an architecture name
214        """
215        global PLATFORM_MACHINE
216        PLATFORM_MACHINE = name

Sets the platform architecture once

Parameters
  • str name: an architecture name
@staticmethod
def is_x86_arch(arch):
218    @staticmethod
219    def is_x86_arch(arch):
220        """
221        Checks if machine architecture is x86 based
222
223        Any arch that matches 32bit and 64bit x86 architecture
224        causes the method to return True. Anything else will
225        cause the method to return False
226
227        :rtype: bool
228        """
229        x86_arch_names = [
230            'x86_64', 'i686', 'i586', 'ix86'
231        ]
232        if arch in x86_arch_names:
233            return True
234        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):
236    @staticmethod
237    def is_ppc64_arch(arch):
238        """
239        Checks if machine architecture is ppc64 based
240
241        Any arch that matches little endian or big endian ppc64 architecture
242        causes the method to return True. Anything else will
243        cause the method to return False
244
245        :rtype: bool
246        """
247        ppc64_arch_names = [
248            'ppc64', 'ppc64le'
249        ]
250        if arch in ppc64_arch_names:
251            return True
252        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():
254    @staticmethod
255    def is_buildservice_worker():
256        """
257        Checks if build host is an open buildservice machine
258
259        The presence of /.buildenv on the build host indicates
260        we are building inside of the open buildservice
261
262        :return: True if obs worker, else False
263
264        :rtype: bool
265        """
266        return os.path.exists(
267            os.sep + Defaults.get_buildservice_env_name()
268        )

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():
270    @staticmethod
271    def get_buildservice_env_name():
272        """
273        Provides the base name of the environment file in a
274        buildservice worker
275
276        :return: file basename
277
278        :rtype: str
279        """
280        return '.buildenv'

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

Returns

file basename

@staticmethod
def get_obs_download_server_url():
282    @staticmethod
283    def get_obs_download_server_url():
284        """
285        Provides the default download server url hosting the public open
286        buildservice repositories
287
288        :return: url path
289
290        :rtype: str
291        """
292        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():
294    @staticmethod
295    def get_obs_api_server_url():
296        """
297        Provides the default API server url to access the
298        public open buildservice API
299
300        :return: url path
301
302        :rtype: str
303        """
304        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():
306    @staticmethod
307    def get_solvable_location():
308        """
309        Provides the directory to store SAT solvables for repositories.
310        The solvable files are used to perform package
311        dependency and metadata resolution
312
313        :return: directory path
314
315        :rtype: str
316        """
317        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):
319    @staticmethod
320    def set_runtime_checker_metadata(filename):
321        """
322        Sets the runtime checker metadata filename
323
324        :param str filename: a file path name
325        """
326        global RUNTIME_CHECKER_METADATA
327        RUNTIME_CHECKER_METADATA = filename

Sets the runtime checker metadata filename

Parameters
  • str filename: a file path name
@staticmethod
def set_shared_cache_location(location):
329    @staticmethod
330    def set_shared_cache_location(location):
331        """
332        Sets the shared cache location once
333
334        :param str location: a location path
335        """
336        global SHARED_CACHE_DIR
337        SHARED_CACHE_DIR = location

Sets the shared cache location once

Parameters
  • str location: a location path
@staticmethod
def set_custom_runtime_config_file(filename):
339    @staticmethod
340    def set_custom_runtime_config_file(filename):
341        """
342        Sets the runtime config file once
343
344        :param str filename: a file path name
345        """
346        global CUSTOM_RUNTIME_CONFIG_FILE
347        CUSTOM_RUNTIME_CONFIG_FILE = filename

Sets the runtime config file once

Parameters
  • str filename: a file path name
@staticmethod
def set_temp_location(location):
349    @staticmethod
350    def set_temp_location(location):
351        """
352        Sets the temp directory location once
353
354        :param str location: a location path
355        """
356        global TEMP_DIR
357        TEMP_DIR = location

Sets the temp directory location once

Parameters
  • str location: a location path
@staticmethod
def get_shared_cache_location():
359    @staticmethod
360    def get_shared_cache_location():
361        """
362        Provides the shared cache location
363
364        This is a directory which shares data from the image buildsystem
365        host with the image root system. The location is returned as an
366        absolute path stripped off by the leading '/'. This is because
367        the path is transparently used on the host /<cache-dir> and
368        inside of the image imageroot/<cache-dir>
369
370        :return: directory path
371
372        :rtype: str
373        """
374        return os.path.abspath(os.path.normpath(
375            SHARED_CACHE_DIR
376        )).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():
378    @staticmethod
379    def get_temp_location():
380        """
381        Provides the base temp directory location
382
383        This is the directory used to store any temporary files
384        and directories created by kiwi during runtime
385
386        :return: directory path
387
388        :rtype: str
389        """
390        return os.path.abspath(
391            os.path.normpath(TEMP_DIR)
392        )

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():
394    @staticmethod
395    def get_sync_options():
396        """
397        Provides list of default data sync options
398
399        :return: list of rsync options
400
401        :rtype: list
402        """
403        return [
404            '--archive', '--hard-links', '--xattrs', '--acls',
405            '--one-file-system', '--inplace'
406        ]

Provides list of default data sync options

Returns

list of rsync options

@staticmethod
def get_removed_files_name():
408    @staticmethod
409    def get_removed_files_name():
410        """
411        Provides base file name to store removed files
412        in a delta root build
413        """
414        return 'removed'

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

@staticmethod
def get_system_files_name():
416    @staticmethod
417    def get_system_files_name():
418        """
419        Provides base file name to store system files
420        in a container build
421        """
422        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]:
424    @staticmethod
425    def get_exclude_list_for_removed_files_detection() -> List[str]:
426        """
427        Provides list of files/dirs to exclude from the removed
428        files detection in a delta root build
429        """
430        return [
431            'etc/hosts.kiwi',
432            'etc/hosts.sha',
433            'etc/resolv.conf.kiwi',
434            'etc/resolv.conf.sha',
435            'etc/sysconfig/proxy.kiwi',
436            'etc/sysconfig/proxy.sha',
437            'usr/lib/sysimage/rpm'
438        ]

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):
440    @staticmethod
441    def get_exclude_list_for_root_data_sync(no_tmpdirs: bool = True):
442        """
443        Provides the list of files or folders that are created
444        by KIWI for its own purposes. Those files should be not
445        be included in the resulting image.
446
447        :return: list of file and directory names
448
449        :rtype: list
450        """
451        exclude_list = [
452            'image', '.kconfig'
453        ]
454        if no_tmpdirs:
455            exclude_list += ['run/*', 'tmp/*']
456        exclude_list += [
457            Defaults.get_buildservice_env_name(),
458            Defaults.get_shared_cache_location()
459        ]
460        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:
462    @staticmethod
463    def get_runtime_checker_metadata() -> Dict:
464        with open(RUNTIME_CHECKER_METADATA) as meta:
465            return yaml.safe_load(meta)
@staticmethod
def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
509    @staticmethod
510    def get_exclude_list_from_custom_exclude_files(root_dir: str) -> List:
511        """
512        Gets the list of excluded items for the root filesystem from
513        the optional metadata file image/exclude_files.yaml
514
515        :return: list of paths and glob patterns
516
517        :param string root_dir: image root directory
518
519        :rtype: list
520        """
521        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:
523    @staticmethod
524    def get_exclude_list_from_custom_exclude_files_for_efifatimage(root_dir: str) -> List:
525        """
526        Gets the list of excluded items for the ESP's EFI folder from
527        the optional metadata file image/exclude_files_efifatimage.yaml
528
529        Excluded items must be relative to the ESP's /EFI directory.
530
531        :return: list of paths and glob patterns
532
533        :param string root_dir: EFI root directory
534
535        :rtype: list
536        """
537        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():
539    @staticmethod
540    def get_exclude_list_for_non_physical_devices():
541        """
542        Provides the list of folders that are not associated
543        with a physical device. KIWI returns the basename of
544        the folders typically used as mountpoint for those
545        devices.
546
547        :return: list of file and directory names
548
549        :rtype: list
550        """
551        exclude_list = [
552            'proc', 'sys', 'dev'
553        ]
554        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():
556    @staticmethod
557    def get_failsafe_kernel_options():
558        """
559        Provides failsafe boot kernel options
560
561        :return:
562            list of kernel options
563
564            .. code:: python
565
566                ['option=value', 'option']
567
568        :rtype: list
569        """
570        return ' '.join(
571            [
572                'ide=nodma',
573                'apm=off',
574                'noresume',
575                'edd=off',
576                'nomodeset',
577                '3'
578            ]
579        )

Provides failsafe boot kernel options

Returns
list of kernel options

.. code:: python

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

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():
621    @staticmethod
622    def get_volume_id():
623        """
624        Provides default value for ISO volume ID
625
626        :return: name
627
628        :rtype: str
629        """
630        return 'CDROM'

Provides default value for ISO volume ID

Returns

name

@staticmethod
def get_install_volume_id():
632    @staticmethod
633    def get_install_volume_id():
634        """
635        Provides default value for ISO volume ID for install media
636
637        :return: name
638
639        :rtype: str
640        """
641        return 'INSTALL'

Provides default value for ISO volume ID for install media

Returns

name

@staticmethod
def get_snapper_config_template_file(root: str) -> str:
643    @staticmethod
644    def get_snapper_config_template_file(root: str) -> str:
645        """
646        Provides the default configuration template file for snapper.
647        The location in etc/ are preferred over files in usr/
648
649        :return: file path
650
651        :rtype: str
652        """
653        snapper_templates = [
654            'etc/snapper/config-templates/default',
655            'usr/share/snapper/config-templates/default'
656        ]
657        snapper_default_conf = ''
658        for snapper_template in snapper_templates:
659            template_config = os.path.join(root, snapper_template)
660            if os.path.exists(template_config):
661                snapper_default_conf = template_config
662                break
663        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():
665    @staticmethod
666    def get_default_video_mode():
667        """
668        Uses auto mode for default video. See get_video_mode_map
669        for details on the value depending which bootloader is
670        used
671
672        :return: auto
673
674        :rtype: str
675        """
676        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():
678    @staticmethod
679    def get_default_bootloader():
680        """
681        Return default bootloader name which is grub2
682
683        :return: bootloader name
684
685        :rtype: str
686        """
687        return 'grub2'

Return default bootloader name which is grub2

Returns

bootloader name

@staticmethod
def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
689    @staticmethod
690    def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
691        return {
692            'grub_directory_name':
693                Defaults.get_grub_boot_directory_name(root_dir),
694            'grub_load_command':
695                'configfile'
696        }
@staticmethod
def get_grub_boot_directory_name(lookup_path):
698    @staticmethod
699    def get_grub_boot_directory_name(lookup_path):
700        """
701        Provides grub2 data directory name in boot/ directory
702
703        Depending on the distribution the grub2 boot path could be
704        either boot/grub2 or boot/grub. The method will decide for
705        the correct base directory name according to the name pattern
706        of the installed grub2 tools
707
708        :return: directory basename
709
710        :rtype: str
711        """
712        if Path.which(filename='grub2-install', root_dir=lookup_path):
713            # the presence of grub2-install is an indicator to put all
714            # grub2 data below boot/grub2
715            return 'grub2'
716        else:
717            # in any other case the assumption is made that all grub
718            # boot data should live below boot/grub
719            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):
721    @staticmethod
722    def get_grub_basic_modules(multiboot):
723        """
724        Provides list of basic grub modules
725
726        :param bool multiboot: grub multiboot mode
727
728        :return: list of module names
729
730        :rtype: list
731        """
732        modules = [
733            'ext2',
734            'iso9660',
735            'linux',
736            'echo',
737            'configfile',
738            'search_label',
739            'search_fs_file',
740            'search',
741            'search_fs_uuid',
742            'ls',
743            'normal',
744            'gzio',
745            'png',
746            'fat',
747            'gettext',
748            'font',
749            'minicmd',
750            'gfxterm',
751            'gfxmenu',
752            'all_video',
753            'xfs',
754            'btrfs',
755            'squash4',
756            'lvm',
757            'luks',
758            'gcry_rijndael',
759            'gcry_sha256',
760            'gcry_sha512',
761            'crypto',
762            'cryptodisk',
763            'test',
764            'true',
765            'loadenv'
766        ]
767        if multiboot:
768            modules.append('multiboot')
769        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):
771    @staticmethod
772    def get_grub_efi_modules(multiboot=False):
773        """
774        Provides list of grub efi modules
775
776        :param bool multiboot: grub multiboot mode
777
778        :return: list of module names
779
780        :rtype: list
781        """
782        host_architecture = Defaults.get_platform_name()
783        modules = Defaults.get_grub_basic_modules(multiboot) + [
784            'part_gpt',
785            'part_msdos',
786            'efi_gop'
787        ]
788        if host_architecture == 'x86_64':
789            modules += [
790                'efi_uga'
791            ]
792        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):
794    @staticmethod
795    def get_grub_platform_modules(multiboot=False):
796        """
797        Provides list of platform specific grub modules
798
799        :param bool multiboot: grub multiboot mode
800
801        :return: list of module names
802
803        :rtype: list
804        """
805        modules = Defaults.get_grub_basic_modules(multiboot)
806        if Defaults.is_ppc64_arch(Defaults.get_platform_name()):
807            return Defaults.get_grub_ofw_modules()
808        else:
809            modules += [
810                'part_gpt',
811                'part_msdos',
812                'biosdisk',
813                'vga',
814                'vbe',
815                'chain',
816                'boot'
817            ]
818        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():
820    @staticmethod
821    def get_grub_ofw_modules():
822        """
823        Provides list of grub ofw modules (ppc)
824
825        :return: list of module names
826
827        :rtype: list
828        """
829        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
830            'part_gpt',
831            'part_msdos',
832            'boot'
833        ]
834        return modules

Provides list of grub ofw modules (ppc)

Returns

list of module names

@staticmethod
def get_grub_s390_modules():
836    @staticmethod
837    def get_grub_s390_modules():
838        """
839        Provides list of grub ofw modules (s390)
840
841        :return: list of module names
842
843        :rtype: list
844        """
845        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
846            'part_gpt',
847            'part_msdos',
848            'boot'
849        ]
850        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:
852    @staticmethod
853    def get_grub_path(
854        root_path: str, filename: str, raise_on_error: bool = True
855    ) -> str:
856        """
857        Provides grub path to given search file
858
859        Depending on the distribution grub could be installed below
860        a grub2 or grub directory. grub could also reside in /usr/lib
861        as well as in /usr/share. Therefore this information needs
862        to be dynamically looked up
863
864        :param string root_path: root path to start the lookup from
865        :param string filename: filename to search
866        :param bool raise_on_error: raise on not found, defaults to True
867
868        The method returns the path to the given grub search file.
869        By default it raises a KiwiBootLoaderGrubDataError exception
870        if the file could not be found in any of the search locations.
871        If raise_on_error is set to False and no file could be found
872        the function returns None
873
874        :return: filepath
875
876        :rtype: str
877        """
878        log.debug(f'Searching grub file: {filename}')
879        install_dirs = [
880            'usr/share', 'usr/lib'
881        ]
882        lookup_list = []
883        for grub_name in ['grub2', 'grub']:
884            for install_dir in install_dirs:
885                grub_path = os.path.join(
886                    root_path, install_dir, grub_name, filename
887                )
888                log.debug(f'--> {grub_path}')
889                if os.path.exists(grub_path):
890                    log.debug(f'--> Found in: {grub_path}')
891                    return grub_path
892                lookup_list.append(grub_path)
893        if raise_on_error:
894            raise KiwiBootLoaderGrubDataError(
895                'grub path {0} not found in {1}'.format(filename, lookup_list)
896            )
897        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():
899    @staticmethod
900    def get_preparer():
901        """
902        Provides ISO preparer name
903
904        :return: name
905
906        :rtype: str
907        """
908        return 'KIWI - https://github.com/OSInside/kiwi'

Provides ISO preparer name

Returns

name

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

Provides ISO publisher name

Returns

name

@staticmethod
def get_shim_loader(root_path: str) -> List[shim_loader_type]:
921    @staticmethod
922    def get_shim_loader(root_path: str) -> List[shim_loader_type]:
923        """
924        Provides shim loader file path
925
926        Searches distribution specific locations to find shim.efi
927        below the given root path
928
929        :param string root_path: image root path
930
931        :return: list of shim_loader_type
932
933        :rtype: list
934        """
935        result = []
936        shim_pattern_type = namedtuple(
937            'shim_pattern_type', ['pattern', 'binaryname']
938        )
939        shim_file_patterns = [
940            shim_pattern_type(
941                '/usr/lib/shim/shim*.efi.signed.latest',
942                'bootx64.efi'
943            ),
944            shim_pattern_type(
945                '/usr/lib/shim/shim*.efi.signed',
946                'bootx64.efi'
947            ),
948            shim_pattern_type(
949                '/usr/lib/grub/*-efi-signed',
950                'bootx64.efi'
951            ),
952            shim_pattern_type(
953                '/usr/share/efi/x86_64/shim.efi',
954                'bootx64.efi'
955            ),
956            shim_pattern_type(
957                '/usr/share/efi/aarch64/shim.efi',
958                'bootaa64.efi'
959            ),
960            shim_pattern_type(
961                '/usr/lib64/efi/shim.efi',
962                'bootx64.efi'
963            ),
964            shim_pattern_type(
965                '/boot/efi/EFI/*/shimx64.efi',
966                'bootx64.efi'
967            ),
968            shim_pattern_type(
969                '/boot/efi/EFI/*/shimia32.efi',
970                'bootia32.efi'
971            ),
972            shim_pattern_type(
973                '/boot/efi/EFI/*/shimaa64.efi',
974                'bootaa64.efi'
975            ),
976            shim_pattern_type(
977                '/boot/efi/EFI/*/shimriscv64.efi',
978                'bootriscv64.efi'
979            ),
980            shim_pattern_type(
981                '/boot/efi/EFI/*/shim.efi',
982                'bootx64.efi'
983            ),
984            shim_pattern_type(
985                '/usr/lib/shim/shim*.efi',
986                'bootx64.efi'
987            )
988        ]
989        for shim_file_pattern in shim_file_patterns:
990            for shim_file in sorted(
991                glob.iglob(root_path + shim_file_pattern.pattern), key=len
992            ):
993                result.append(
994                    shim_loader_type(shim_file, shim_file_pattern.binaryname)
995                )
996                # one match only expected, per pattern
997                break
998        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]:
1000    @staticmethod
1001    def get_mok_manager(root_path: str) -> List[str]:
1002        """
1003        Provides Mok Manager file path
1004
1005        Searches distribution specific locations to find
1006        the Mok Manager EFI binary
1007
1008        :param str root_path: image root path
1009
1010        :return: file path or None
1011
1012        :rtype: str
1013        """
1014        result = []
1015        mok_manager_file_patterns = [
1016            '/usr/share/efi/*/MokManager.efi',
1017            '/usr/lib64/efi/MokManager.efi',
1018            '/boot/efi/EFI/*/mm*.efi',
1019            '/usr/lib/shim/mm*.efi'
1020        ]
1021        for mok_manager_file_pattern in mok_manager_file_patterns:
1022            for mm_file in glob.iglob(root_path + mok_manager_file_pattern):
1023                result.append(mm_file)
1024        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):
1026    @staticmethod
1027    def get_grub_efi_font_directory(root_path):
1028        """
1029        Provides distribution specific EFI font directory used with grub.
1030
1031        :param string root_path: image root path
1032
1033        :return: file path or None
1034
1035        :rtype: str
1036        """
1037        font_dir_patterns = [
1038            '/boot/efi/EFI/*/fonts'
1039        ]
1040        for font_dir_pattern in font_dir_patterns:
1041            for font_dir in glob.iglob(root_path + font_dir_pattern):
1042                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]:
1044    @staticmethod
1045    def get_unsigned_grub_loader(
1046        root_path: str, target_type: str = 'disk'
1047    ) -> List[grub_loader_type]:
1048        """
1049        Provides unsigned grub efi loader file path
1050
1051        Searches distribution specific locations to find a distro
1052        grub EFI binary within the given root path
1053
1054        :param string root_path: image root path
1055
1056        :return: list of grub_loader_type
1057
1058        :rtype: list
1059        """
1060        result = []
1061        grub_pattern_type = namedtuple(
1062            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1063        )
1064        unsigned_grub_file_patterns = {
1065            'disk': [
1066                grub_pattern_type(
1067                    '/usr/share/grub*/x86_64-efi/grub.efi',
1068                    'grub.efi',
1069                    'bootx64.efi'
1070                ),
1071                grub_pattern_type(
1072                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1073                    'grub.efi',
1074                    'bootx64.efi'
1075                ),
1076                grub_pattern_type(
1077                    '/boot/efi/EFI/*/grubx64.efi',
1078                    'grubx64.efi',
1079                    'bootx64.efi'
1080                ),
1081                grub_pattern_type(
1082                    '/boot/efi/EFI/*/grubia32.efi',
1083                    'grubia32.efi',
1084                    'bootia32.efi'
1085                ),
1086                grub_pattern_type(
1087                    '/boot/efi/EFI/*/grubaa64.efi',
1088                    'grubaa64.efi',
1089                    'bootaa64.efi'
1090                ),
1091                grub_pattern_type(
1092                    '/boot/efi/EFI/*/grubriscv64.efi',
1093                    'grubriscv64.efi',
1094                    'bootriscv64.efi'
1095                )
1096            ],
1097            'iso': [
1098                grub_pattern_type(
1099                    '/boot/efi/EFI/*/gcdx64.efi',
1100                    'grubx64.efi',
1101                    'bootx64.efi'
1102                ),
1103                grub_pattern_type(
1104                    '/usr/share/grub*/x86_64-efi/grub.efi',
1105                    'grub.efi',
1106                    'bootx64.efi'
1107                ),
1108                grub_pattern_type(
1109                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1110                    'grub.efi',
1111                    'bootx64.efi'
1112                ),
1113                grub_pattern_type(
1114                    '/boot/efi/EFI/*/grubx64.efi',
1115                    'grubx64.efi',
1116                    'bootx64.efi'
1117                ),
1118                grub_pattern_type(
1119                    '/boot/efi/EFI/*/grubia32.efi',
1120                    'grubia32.efi',
1121                    'bootia32.efi'
1122                ),
1123                grub_pattern_type(
1124                    '/boot/efi/EFI/*/grubaa64.efi',
1125                    'grubaa64.efi',
1126                    'bootaa64.efi'
1127                ),
1128                grub_pattern_type(
1129                    '/boot/efi/EFI/*/grubriscv64.efi',
1130                    'grubriscv64.efi',
1131                    'bootriscv64.efi'
1132                )
1133            ]
1134        }
1135        for unsigned_grub_file_pattern in unsigned_grub_file_patterns[target_type]:
1136            for unsigned_grub_file in glob.iglob(
1137                root_path + unsigned_grub_file_pattern.pattern
1138            ):
1139                result.append(
1140                    grub_loader_type(
1141                        unsigned_grub_file,
1142                        unsigned_grub_file_pattern.binaryname,
1143                        unsigned_grub_file_pattern.targetname
1144                    )
1145                )
1146                # one match only expected, per pattern
1147                break
1148        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:
1150    @staticmethod
1151    def get_grub_chrp_loader(boot_path: str) -> str:
1152        """
1153        Lookup CHRP boot loader (ppc)
1154
1155        :param string boot_path: boot path
1156
1157        :return: file base name
1158
1159        :rtype: str
1160        """
1161        for chrp_loader in ['grub.elf', 'core.elf']:
1162            for grub_chrp in glob.iglob(
1163                os.sep.join(
1164                    [boot_path, 'boot/grub*/powerpc-ieee1275', chrp_loader]
1165                )
1166            ):
1167                log.info(f'Found CHRP loader at: {grub_chrp}')
1168                return os.path.basename(grub_chrp)
1169        raise KiwiBootLoaderGrubDataError(
1170            f'CHRP loader not found in {boot_path}'
1171        )

Lookup CHRP boot loader (ppc)

Parameters
  • string boot_path: boot path
Returns

file base name

@staticmethod
def get_grub_platform_core_loader(root_path):
1173    @staticmethod
1174    def get_grub_platform_core_loader(root_path):
1175        """
1176        Provides grub bios image
1177
1178        Searches distribution specific locations to find the
1179        core bios image below the given root path
1180
1181        :param string root_path: image root path
1182
1183        :return: file path or None
1184
1185        :rtype: str
1186        """
1187        bios_grub_core_patterns = [
1188            '/usr/share/grub*/{0}/{1}'.format(
1189                Defaults.get_grub_platform_module_directory_name(),
1190                Defaults.get_grub_platform_image_name()
1191            ),
1192            '/usr/lib/grub*/{0}/{1}'.format(
1193                Defaults.get_grub_platform_module_directory_name(),
1194                Defaults.get_grub_platform_image_name()
1195            )
1196        ]
1197        for bios_grub_core_pattern in bios_grub_core_patterns:
1198            for bios_grub_core in glob.iglob(
1199                root_path + bios_grub_core_pattern
1200            ):
1201                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():
1203    @staticmethod
1204    def get_iso_grub_loader():
1205        """
1206        Return name of eltorito grub image used as ISO loader
1207
1208        :return: file base name
1209
1210        :rtype: str
1211        """
1212        return 'eltorito.img'

Return name of eltorito grub image used as ISO loader

Returns

file base name

@staticmethod
def get_iso_grub_mbr():
1214    @staticmethod
1215    def get_iso_grub_mbr():
1216        """
1217        Return name of hybrid MBR image used as ISO boot record
1218
1219        :return: file base name
1220
1221        :rtype: str
1222        """
1223        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]:
1225    @staticmethod
1226    def get_signed_grub_loader(
1227        root_path: str, target_type: str = 'disk'
1228    ) -> List[grub_loader_type]:
1229        """
1230        Provides shim signed grub loader file path
1231
1232        Searches distribution specific locations to find a grub
1233        EFI binary within the given root path
1234
1235        :param str root_path: image root path
1236
1237        :return: list of grub_loader_type
1238
1239        :rtype: list
1240        """
1241        result = []
1242        grub_pattern_type = namedtuple(
1243            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1244        )
1245        signed_grub_file_patterns = {
1246            'disk': [
1247                grub_pattern_type(
1248                    '/usr/share/efi/*/grub.efi',
1249                    'grub.efi',
1250                    'bootx64.efi'
1251                ),
1252                grub_pattern_type(
1253                    '/usr/lib64/efi/grub.efi',
1254                    'grub.efi',
1255                    'bootx64.efi'
1256                ),
1257                grub_pattern_type(
1258                    '/boot/efi/EFI/*/grubx64.efi',
1259                    'grubx64.efi',
1260                    'bootx64.efi'
1261                ),
1262                grub_pattern_type(
1263                    '/boot/efi/EFI/*/grubia32.efi',
1264                    'grubia32.efi',
1265                    'bootia32.efi'
1266                ),
1267                grub_pattern_type(
1268                    '/boot/efi/EFI/*/grubaa64.efi',
1269                    'grubaa64.efi',
1270                    'bootaa64.efi'
1271                ),
1272                grub_pattern_type(
1273                    '/boot/efi/EFI/*/grubriscv64.efi',
1274                    'grubriscv64.efi',
1275                    'bootriscv64.efi'
1276                ),
1277                grub_pattern_type(
1278                    '/usr/share/grub*/*-efi/grub.efi',
1279                    'grub.efi',
1280                    'bootx64.efi'
1281                ),
1282                grub_pattern_type(
1283                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1284                    'grubx64.efi',
1285                    'bootx64.efi'
1286                )
1287            ],
1288            'iso': [
1289                grub_pattern_type(
1290                    '/boot/efi/EFI/*/gcdx64.efi',
1291                    'grubx64.efi',
1292                    'bootx64.efi'
1293                ),
1294                grub_pattern_type(
1295                    '/boot/efi/EFI/*/gcdaa64.efi',
1296                    'grubaa64.efi',
1297                    'bootaa64.efi'
1298                ),
1299                grub_pattern_type(
1300                    '/usr/share/efi/x86_64/grub.efi',
1301                    'grub.efi',
1302                    'grubx64.efi'
1303                ),
1304                grub_pattern_type(
1305                    '/usr/share/efi/aarch64/grub.efi',
1306                    'grub.efi',
1307                    'grubaa64.efi'
1308                ),
1309                grub_pattern_type(
1310                    '/usr/lib64/efi/grub.efi',
1311                    'grub.efi',
1312                    'bootx64.efi'
1313                ),
1314                grub_pattern_type(
1315                    '/boot/efi/EFI/*/grubx64.efi',
1316                    'grubx64.efi',
1317                    'bootx64.efi'
1318                ),
1319                grub_pattern_type(
1320                    '/boot/efi/EFI/*/grubia32.efi',
1321                    'grubia32.efi',
1322                    'bootia32.efi'
1323                ),
1324                grub_pattern_type(
1325                    '/boot/efi/EFI/*/grubaa64.efi',
1326                    'grubaa64.efi',
1327                    'bootaa64.efi'
1328                ),
1329                grub_pattern_type(
1330                    '/boot/efi/EFI/*/grubriscv64.efi',
1331                    'grubriscv64.efi',
1332                    'bootriscv64.efi'
1333                ),
1334                grub_pattern_type(
1335                    '/usr/share/grub*/x86_64-efi/grub.efi',
1336                    'grub.efi',
1337                    'bootx64.efi'
1338                ),
1339                grub_pattern_type(
1340                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1341                    'grubx64.efi',
1342                    'bootx64.efi'
1343                )
1344            ]
1345        }
1346        for signed_grub in signed_grub_file_patterns[target_type]:
1347            for signed_grub_file in glob.iglob(root_path + signed_grub.pattern):
1348                result.append(
1349                    grub_loader_type(
1350                        signed_grub_file,
1351                        signed_grub.binaryname,
1352                        signed_grub.targetname
1353                    )
1354                )
1355                # one match only expected, per pattern
1356                break
1357        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):
1359    @staticmethod
1360    def get_efi_vendor_directory(efi_path):
1361        """
1362        Provides EFI vendor directory if present
1363
1364        Looks up distribution specific EFI vendor directory
1365
1366        :param string root_path: path to efi mountpoint
1367
1368        :return: directory path or None
1369
1370        :rtype: str
1371        """
1372        efi_vendor_directories = [
1373            'EFI/fedora',
1374            'EFI/redhat',
1375            'EFI/centos',
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', 'qcow2', 'vmdk', 'ova', 'meta', 'vmx', 'vhd', 'vhdx',
1532            'vhdfixed', 'vdi', 'vagrant.libvirt.box', 'vagrant.virtualbox.box'
1533        ]

Provides supported disk format types

Returns

disk types

@staticmethod
def get_vagrant_config_virtualbox_guest_additions():
1535    @staticmethod
1536    def get_vagrant_config_virtualbox_guest_additions():
1537        """
1538        Provides the default value for
1539        ``vagrantconfig.virtualbox_guest_additions_present``
1540
1541        :return: whether guest additions are expected to be present in the
1542            vagrant box
1543
1544        :rtype: bool
1545        """
1546        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():
1548    @staticmethod
1549    def get_firmware_types():
1550        """
1551        Provides supported architecture specific firmware types
1552
1553        :return: firmware types per architecture
1554
1555        :rtype: dict
1556        """
1557        return {
1558            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1559            'i586': ['bios'],
1560            'i686': ['bios'],
1561            'ix86': ['bios'],
1562            'aarch64': ['efi', 'uefi'],
1563            'arm64': ['efi', 'uefi'],
1564            'armv5el': ['efi', 'uefi'],
1565            'armv5tel': ['efi', 'uefi'],
1566            'armv6hl': ['efi', 'uefi'],
1567            'armv6l': ['efi', 'uefi'],
1568            'armv7hl': ['efi', 'uefi'],
1569            'armv7l': ['efi', 'uefi'],
1570            'armv8l': ['efi', 'uefi'],
1571            'loongarch64': ['efi', 'uefi'],
1572            'ppc': ['ofw'],
1573            'ppc64': ['ofw', 'opal'],
1574            'ppc64le': ['ofw', 'opal'],
1575            'riscv64': ['efi', 'uefi'],
1576            's390': [],
1577            's390x': []
1578        }

Provides supported architecture specific firmware types

Returns

firmware types per architecture

@staticmethod
def get_default_firmware(arch):
1580    @staticmethod
1581    def get_default_firmware(arch):
1582        """
1583        Provides default firmware for specified architecture
1584
1585        :param string arch: machine architecture name
1586
1587        :return: firmware name
1588
1589        :rtype: str
1590        """
1591        default_firmware = {
1592            'x86_64': 'bios',
1593            'i586': 'bios',
1594            'i686': 'bios',
1595            'ix86': 'bios',
1596            'loongarch64': 'efi',
1597            'ppc': 'ofw',
1598            'ppc64': 'ofw',
1599            'ppc64le': 'ofw',
1600            'arm64': 'efi',
1601            'aarch64': 'efi',
1602            'armv5el': 'efi',
1603            'armv5tel': 'efi',
1604            'armv6hl': 'efi',
1605            'armv6l': 'efi',
1606            'armv7hl': 'efi',
1607            'armv7l': 'efi',
1608            'armv8l': 'efi',
1609            'riscv64': 'efi'
1610        }
1611        if arch in default_firmware:
1612            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():
1614    @staticmethod
1615    def get_efi_capable_firmware_names():
1616        """
1617        Provides list of EFI capable firmware names. These are
1618        those for which kiwi supports the creation of an EFI
1619        bootable disk image
1620
1621        :return: firmware names
1622
1623        :rtype: list
1624        """
1625        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():
1627    @staticmethod
1628    def get_ec2_capable_firmware_names():
1629        """
1630        Provides list of EC2 capable firmware names. These are
1631        those for which kiwi supports the creation of disk images
1632        bootable within the Amazon EC2 public cloud
1633
1634        :return: firmware names
1635
1636        :rtype: list
1637        """
1638        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):
1640    @staticmethod
1641    def get_efi_module_directory_name(arch):
1642        """
1643        Provides architecture specific EFI directory name which
1644        stores the EFI binaries for the desired architecture.
1645
1646        :param string arch: machine architecture name
1647
1648        :return: directory name
1649
1650        :rtype: str
1651        """
1652        default_module_directory_names = {
1653            'x86_64': 'x86_64-efi',
1654            'i386': 'i386-efi',
1655
1656            # There is no dedicated xen architecture but there are
1657            # modules provided for xen. Thus we treat it as an
1658            # architecture
1659            'x86_64_xen': 'x86_64-xen',
1660
1661            'aarch64': 'arm64-efi',
1662            'arm64': 'arm64-efi',
1663            'armv5el': 'arm-efi',
1664            'armv5tel': 'arm-efi',
1665            'armv6l': 'arm-efi',
1666            'armv7l': 'arm-efi',
1667            'armv8l': 'arm-efi',
1668            'loongarch64': 'loongarch64-efi',
1669            'riscv64': 'riscv64-efi'
1670        }
1671        if arch in default_module_directory_names:
1672            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():
1674    @staticmethod
1675    def get_grub_platform_module_directory_name():
1676        """
1677        Provides grub platform specific directory name which
1678        stores the grub module binaries
1679
1680        :return: directory name
1681
1682        :rtype: str
1683        """
1684        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1685            Defaults.get_platform_name()
1686        ) 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):
1688    @staticmethod
1689    def get_efi_image_name(arch):
1690        """
1691        Provides architecture specific EFI boot binary name
1692
1693        :param string arch: machine architecture name
1694
1695        :return: name
1696
1697        :rtype: str
1698        """
1699        default_efi_image_names = {
1700            'x86_64': 'bootx64.efi',
1701            'i386': 'bootia32.efi',
1702            'aarch64': 'bootaa64.efi',
1703            'arm64': 'bootaa64.efi',
1704            'armv5el': 'bootarm.efi',
1705            'armv5tel': 'bootarm.efi',
1706            'armv6l': 'bootarm.efi',
1707            'armv7l': 'bootarm.efi',
1708            'armv8l': 'bootarm.efi',
1709            'loongarch64': 'bootloongarch64.efi',
1710            'riscv64': 'bootriscv64.efi'
1711        }
1712        if arch in default_efi_image_names:
1713            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():
1715    @staticmethod
1716    def get_grub_platform_image_name():
1717        """
1718        Provides platform specific core boot binary name
1719
1720        :return: name
1721
1722        :rtype: str
1723        """
1724        return 'grub.elf' if Defaults.is_ppc64_arch(
1725            Defaults.get_platform_name()
1726        ) else 'core.img'

Provides platform specific core boot binary name

Returns

name

@staticmethod
def get_default_boot_timeout_seconds():
1728    @staticmethod
1729    def get_default_boot_timeout_seconds():
1730        """
1731        Provides default boot timeout in seconds
1732
1733        :return: seconds
1734
1735        :rtype: int
1736        """
1737        return 10

Provides default boot timeout in seconds

Returns

seconds

@staticmethod
def get_default_disk_start_sector():
1739    @staticmethod
1740    def get_default_disk_start_sector():
1741        """
1742        Provides the default initial disk sector for the first disk
1743        partition.
1744
1745        :return: sector value
1746
1747        :rtype: int
1748        """
1749        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():
1751    @staticmethod
1752    def get_default_efi_partition_table_type():
1753        """
1754        Provides the default partition table type for efi firmwares.
1755
1756        :return: partition table type name
1757
1758        :rtype: str
1759        """
1760        return 'gpt'

Provides the default partition table type for efi firmwares.

Returns

partition table type name

@staticmethod
def get_default_inode_size():
1762    @staticmethod
1763    def get_default_inode_size():
1764        """
1765        Provides default size of inodes in bytes. This is only
1766        relevant for inode based filesystems
1767
1768        :return: bytesize value
1769
1770        :rtype: int
1771        """
1772        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():
1774    @staticmethod
1775    def get_archive_image_types():
1776        """
1777        Provides list of supported archive image types
1778
1779        :return: archive names
1780
1781        :rtype: list
1782        """
1783        return ['tbz', 'cpio']

Provides list of supported archive image types

Returns

archive names

@staticmethod
def get_container_image_types():
1785    @staticmethod
1786    def get_container_image_types():
1787        """
1788        Provides list of supported container image types
1789
1790        :return: container names
1791
1792        :rtype: list
1793        """
1794        return ['docker', 'oci', 'appx', 'wsl']

Provides list of supported container image types

Returns

container names

@staticmethod
def get_filesystem_image_types():
1796    @staticmethod
1797    def get_filesystem_image_types():
1798        """
1799        Provides list of supported filesystem image types
1800
1801        :return: filesystem names
1802
1803        :rtype: list
1804        """
1805        return [
1806            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1807            'xfs', 'fat16', 'fat32', 'erofs'
1808        ]

Provides list of supported filesystem image types

Returns

filesystem names

@staticmethod
def get_default_live_iso_type():
1810    @staticmethod
1811    def get_default_live_iso_type():
1812        """
1813        Provides default live iso union type
1814
1815        :return: live iso type
1816
1817        :rtype: str
1818        """
1819        return 'overlay'

Provides default live iso union type

Returns

live iso type

@staticmethod
def get_default_uri_type():
1821    @staticmethod
1822    def get_default_uri_type():
1823        """
1824        Provides default URI type
1825
1826        Absolute path specifications used in the context of an URI
1827        will apply the specified default mime type
1828
1829        :return: URI mime type
1830
1831        :rtype: str
1832        """
1833        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():
1835    @staticmethod
1836    def get_dracut_conf_name():
1837        """
1838        Provides file path of dracut config file to be used with KIWI
1839
1840        :return: file path name
1841
1842        :rtype: str
1843        """
1844        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):
1846    @staticmethod
1847    def get_live_dracut_modules_from_flag(flag_name):
1848        """
1849        Provides flag_name to dracut modules name map
1850
1851        Depending on the value of the flag attribute in the KIWI image
1852        description specific dracut modules need to be selected
1853
1854        :return: dracut module names as list
1855
1856        :rtype: list
1857        """
1858        live_modules = {
1859            'overlay': ['kiwi-live'],
1860            'dmsquash': ['dmsquash-live', 'livenet']
1861        }
1862        if flag_name in live_modules:
1863            return live_modules[flag_name]
1864        else:
1865            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():
1867    @staticmethod
1868    def get_default_live_iso_root_filesystem():
1869        """
1870        Provides default live iso root filesystem type
1871
1872        :return: filesystem name
1873
1874        :rtype: str
1875        """
1876        return 'ext4'

Provides default live iso root filesystem type

Returns

filesystem name

@staticmethod
def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1878    @staticmethod
1879    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1880        """
1881        Provides list of boot options passed to the dracut
1882        kiwi-live module to setup persistent writing
1883
1884        :return: list of boot options
1885
1886        :rtype: list
1887        """
1888        live_iso_persistent_boot_options = [
1889            'rd.live.overlay.persistent'
1890        ]
1891        if persistent_filesystem:
1892            live_iso_persistent_boot_options.append(
1893                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1894            )
1895        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():
1897    @staticmethod
1898    def get_disk_image_types():
1899        """
1900        Provides supported disk image types
1901
1902        :return: disk image type names
1903
1904        :rtype: list
1905        """
1906        return ['oem']

Provides supported disk image types

Returns

disk image type names

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

Provides supported live image types

Returns

live image type names

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

Provides supported kis image types

Returns

kis image type names

@staticmethod
def get_enclaves_image_types():
1930    @staticmethod
1931    def get_enclaves_image_types():
1932        """
1933        Provides supported enclave(initrd-only) image types
1934
1935        :return: enclave image type names
1936
1937        :rtype: list
1938        """
1939        return ['enclave']

Provides supported enclave(initrd-only) image types

Returns

enclave image type names

@staticmethod
def get_boot_image_description_path():
1941    @staticmethod
1942    def get_boot_image_description_path():
1943        """
1944        Provides the path to find custom kiwi boot descriptions
1945
1946        :return: directory path
1947
1948        :rtype: str
1949        """
1950        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():
1952    @staticmethod
1953    def get_boot_image_strip_file():
1954        """
1955        Provides the file path to bootloader strip metadata.
1956        This file contains information about the files and directories
1957        automatically striped out from the kiwi initrd
1958
1959        :return: file path
1960
1961        :rtype: str
1962        """
1963        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():
1965    @staticmethod
1966    def get_schema_file():
1967        """
1968        Provides file path to kiwi RelaxNG schema
1969
1970        :return: file path
1971
1972        :rtype: str
1973        """
1974        return Defaults.project_file('schema/kiwi.rng')

Provides file path to kiwi RelaxNG schema

Returns

file path

@staticmethod
def get_common_functions_file():
1976    @staticmethod
1977    def get_common_functions_file():
1978        """
1979        Provides the file path to config functions metadata.
1980
1981        This file contains bash functions used for system
1982        configuration or in the boot code from the kiwi initrd
1983
1984        :return: file path
1985
1986        :rtype: str
1987        """
1988        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():
1990    @staticmethod
1991    def get_xsl_stylesheet_file():
1992        """
1993        Provides the file path to the KIWI XSLT style sheets
1994
1995        :return: file path
1996
1997        :rtype: str
1998        """
1999        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():
2001    @staticmethod
2002    def get_schematron_module_name():
2003        """
2004        Provides module name for XML SchemaTron validations
2005
2006        :return: python module name
2007
2008        :rtype: str
2009        """
2010        return 'lxml.isoschematron'

Provides module name for XML SchemaTron validations

Returns

python module name

@staticmethod
def project_file(filename):
2012    @staticmethod
2013    def project_file(filename):
2014        """
2015        Provides the python module base directory search path
2016
2017        The method uses the importlib.resources.path method to identify
2018        files and directories from the application
2019
2020        :param string filename: relative project file
2021
2022        :return: absolute file path name
2023
2024        :rtype: str
2025        """
2026        with as_file(importlib.resources.files('kiwi')) as path:
2027            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):
2029    @staticmethod
2030    def get_imported_root_image(root_dir):
2031        """
2032        Provides the path to an imported root system image
2033
2034        If the image description specified a derived_from attribute
2035        the file from this attribute is copied into the root_dir
2036        using the name as provided by this method
2037
2038        :param string root_dir: image root directory
2039
2040        :return: file path name
2041
2042        :rtype: str
2043        """
2044        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():
2046    @staticmethod
2047    def get_iso_boot_path():
2048        """
2049        Provides arch specific relative path to boot files
2050        on kiwi iso filesystems
2051
2052        :return: relative path name
2053
2054        :rtype: str
2055        """
2056        return os.sep.join(
2057            ['boot', Defaults.get_platform_name()]
2058        )

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

Returns

relative path name

@staticmethod
def get_iso_tool_category():
2060    @staticmethod
2061    def get_iso_tool_category():
2062        """
2063        Provides default iso tool category
2064
2065        :return: name
2066
2067        :rtype: str
2068        """
2069        return 'xorriso'

Provides default iso tool category

Returns

name

@staticmethod
def get_iso_media_tag_tool():
2071    @staticmethod
2072    def get_iso_media_tag_tool():
2073        """
2074        Provides default iso media tag tool
2075
2076        :return: name
2077
2078        :rtype: str
2079        """
2080        return 'checkmedia'

Provides default iso media tag tool

Returns

name

@staticmethod
def get_container_compression():
2082    @staticmethod
2083    def get_container_compression():
2084        """
2085        Provides default container compression
2086
2087        :return: True
2088
2089        :rtype: bool
2090        """
2091        return True

Provides default container compression

Returns

True

@staticmethod
def get_default_container_name():
2093    @staticmethod
2094    def get_default_container_name():
2095        """
2096        Provides the default container name.
2097
2098        :return: name
2099
2100        :rtype: str
2101        """
2102        return 'kiwi-container'

Provides the default container name.

Returns

name

@staticmethod
def get_container_base_image_tag():
2104    @staticmethod
2105    def get_container_base_image_tag():
2106        """
2107        Provides the tag used to identify base layers during the build
2108        of derived images.
2109
2110        :return: tag
2111
2112        :rtype: str
2113        """
2114        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():
2116    @staticmethod
2117    def get_oci_archive_tool():
2118        """
2119        Provides the default OCI archive tool name.
2120
2121        :return: name
2122
2123        :rtype: str
2124        """
2125        return 'umoci'

Provides the default OCI archive tool name.

Returns

name

@staticmethod
def get_part_mapper_tool():
2127    @staticmethod
2128    def get_part_mapper_tool():
2129        """
2130        Provides the default partition mapper tool name.
2131
2132        :return: name
2133
2134        :rtype: str
2135        """
2136        host_architecture = Defaults.get_platform_name()
2137        if 's390' in host_architecture:
2138            return 'kpartx'
2139        return 'partx'

Provides the default partition mapper tool name.

Returns

name

@staticmethod
def get_default_container_tag():
2141    @staticmethod
2142    def get_default_container_tag():
2143        """
2144        Provides the default container tag.
2145
2146        :return: tag
2147
2148        :rtype: str
2149        """
2150        return 'latest'

Provides the default container tag.

Returns

tag

@staticmethod
def get_default_container_subcommand():
2152    @staticmethod
2153    def get_default_container_subcommand():
2154        """
2155        Provides the default container subcommand.
2156
2157        :return: command as a list of arguments
2158
2159        :rtype: list
2160        """
2161        return ['/bin/bash']

Provides the default container subcommand.

Returns

command as a list of arguments

@staticmethod
def get_default_container_created_by():
2163    @staticmethod
2164    def get_default_container_created_by():
2165        """
2166        Provides the default 'created by' history entry for containers.
2167
2168        :return: the specific kiwi version used for the build
2169
2170        :rtype: str
2171        """
2172        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():
2174    @staticmethod
2175    def get_custom_rpm_macros_path():
2176        """
2177        Returns the custom macros directory for the rpm database.
2178
2179        :return: path name
2180
2181        :rtype: str
2182        """
2183        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():
2185    @staticmethod
2186    def get_custom_rpm_bootstrap_macro_name():
2187        """
2188        Returns the rpm bootstrap macro file name created
2189        in the custom rpm macros path
2190
2191        :return: filename
2192
2193        :rtype: str
2194        """
2195        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():
2197    @staticmethod
2198    def get_custom_rpm_image_macro_name():
2199        """
2200        Returns the rpm image macro file name created
2201        in the custom rpm macros path
2202
2203        :return: filename
2204
2205        :rtype: str
2206        """
2207        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:
2209    @staticmethod
2210    def get_default_package_manager() -> str:
2211        """
2212        Returns the default package manager name if none
2213        is configured in the image description
2214
2215        :return: package manager name
2216
2217        :rtype: str
2218        """
2219        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):
2221    @staticmethod
2222    def get_default_packager_tool(package_manager):
2223        """
2224        Provides the packager tool according to the package manager
2225
2226        :param string package_manager: package manger name
2227
2228        :return: packager tool binary name
2229
2230        :rtype: str
2231        """
2232        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2233        deb_based = ['apt']
2234        if package_manager in rpm_based:
2235            return 'rpm'
2236        elif package_manager in deb_based:
2237            return 'dpkg'
2238        elif package_manager == 'pacman':
2239            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]:
2241    @staticmethod
2242    def get_discoverable_partition_ids() -> Dict[str, str]:
2243        """
2244        Provides arch specific partition UUIDs as defined
2245        by the UAPI group
2246
2247        :return: partition UUIDs
2248
2249        :rtype: dict
2250        """
2251        arch = Defaults.get_platform_name()
2252        part_uuids_archs = {
2253            'x86_64': {
2254                'root':
2255                    '4f68bce3e8cd4db196e7fbcaf984b709',
2256                'usr':
2257                    '8484680c952148c69c11b0720656f69e',
2258                'usr-verity':
2259                    '77ff5f63e7b64633acf41565b864c0e6'
2260            },
2261            'ix86': {
2262                'root':
2263                    '44479540f29741b29af7d131d5f0458a',
2264                'usr':
2265                    '75250d768cc6458ebd66bd47cc81a812',
2266                'usr-verity':
2267                    '8f461b0d14ee4e819aa9049b6fb97abd'
2268            },
2269            'aarch64': {
2270                'root':
2271                    'b921b0451df041c3af444c6f280d3fae',
2272                'usr':
2273                    'b0e01050ee5f4390949a9101b17104e9',
2274                'usr-verity':
2275                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2276            },
2277            'riscv64': {
2278                'root':
2279                    '72ec70a6cf7440e6bd494bda08e8f224',
2280                'usr':
2281                    'beaec34b8442439ba40b984381ed097d',
2282                'usr-verity':
2283                    '8f1056be9b0547c481d6be53128e5b54'
2284            }
2285        }
2286        part_uuids_arch = part_uuids_archs.get(arch) or {}
2287        return {
2288            'root':
2289                part_uuids_arch.get('root') or '',
2290            'usr':
2291                part_uuids_arch.get('usr') or '',
2292            'usr-verity':
2293                part_uuids_arch.get('usr-verity') or '',
2294            'usr-secondary':
2295                '75250d768cc6458ebd66bd47cc81a812',
2296            'usr-secondary-verity':
2297                '8f461b0d14ee4e819aa9049b6fb97abd',
2298            'esp':
2299                'c12a7328f81f11d2ba4b00a0c93ec93b',
2300            'xbootldr':
2301                'bc13c2ff59e64262a352b275fd6f7172',
2302            'swap':
2303                '0657fd6da4ab43c484e50933c84b4f4f',
2304            'home':
2305                '933ac7e12eb44f13b8440e14e2aef915',
2306            'srv':
2307                '3b8f842520e04f3b907f1a25a76f98e8',
2308            'var':
2309                '4d21b016b53445c2a9fb5c16e091fd2d',
2310            'tmp':
2311                '7ec6f5573bc54acab29316ef5df639d1',
2312            'user-home':
2313                '773f91ef66d449b5bd83d683bf40ad16',
2314            'linux-generic':
2315                '0fc63daf848347728e793d69d8477de4'
2316        }

Provides arch specific partition UUIDs as defined by the UAPI group

Returns

partition UUIDs

@staticmethod
def get_bls_loader_entries_dir() -> str:
2318    @staticmethod
2319    def get_bls_loader_entries_dir() -> str:
2320        """
2321        Provide default loader entries directory for BLS loaders
2322
2323        :return: directory name
2324
2325        :rtype: str
2326        """
2327        return '/boot/loader/entries'

Provide default loader entries directory for BLS loaders

Returns

directory name

@staticmethod
def get_apk_repo_config() -> str:
2329    @staticmethod
2330    def get_apk_repo_config() -> str:
2331        """
2332        Repository file for apk
2333
2334        :return: file path name
2335
2336        :rtype: str
2337        """
2338        return '/etc/apk/repositories'

Repository file for apk

Returns

file path name

@staticmethod
def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2340    @staticmethod
2341    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2342        return CA_UPDATE_MAP.get(target_distribution)
@staticmethod
def get_ca_target_distributions() -> List[str]:
2344    @staticmethod
2345    def get_ca_target_distributions() -> List[str]:
2346        return sorted(CA_UPDATE_MAP.keys())
def get(self, key):
2348    def get(self, key):
2349        """
2350        Implements get method for profile elements
2351
2352        :param string key: profile keyname
2353
2354        :return: key value
2355
2356        :rtype: str
2357        """
2358        if key in self.defaults:
2359            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):
2361    @staticmethod
2362    def get_profile_file(root_dir):
2363        """
2364        Return name of profile file for given root directory
2365        """
2366        return root_dir + '/.profile'

Return name of profile file for given root directory

def to_profile(self, profile):
2368    def to_profile(self, profile):
2369        """
2370        Implements method to add list of profile keys and their values
2371        to the specified instance of a Profile class
2372
2373        :param object profile: Profile instance
2374        """
2375        for key in sorted(self.profile_key_list):
2376            # Do not apply default values to any variable that was
2377            # already defined in the profile instance.
2378            cur_profile = profile.dot_profile
2379            if key not in cur_profile or cur_profile[key] is None:
2380                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