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/almalinux',
1376            'EFI/opensuse',
1377            'EFI/ubuntu',
1378            'EFI/debian'
1379        ]
1380        for efi_vendor_directory in efi_vendor_directories:
1381            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1382            if os.path.exists(efi_vendor_directory):
1383                return efi_vendor_directory
1384
1385    @staticmethod
1386    def get_vendor_grubenv(efi_path):
1387        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1388        if efi_vendor_directory:
1389            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1390            if os.path.exists(grubenv):
1391                return grubenv
1392
1393    @staticmethod
1394    def get_shim_vendor_directory(root_path):
1395        """
1396        Provides shim vendor directory
1397
1398        Searches distribution specific locations to find shim.efi
1399        below the given root path and return the directory name
1400        to the file found
1401
1402        :param string root_path: image root path
1403
1404        :return: directory path or None
1405
1406        :rtype: str
1407        """
1408        shim_vendor_patterns = [
1409            '/boot/efi/EFI/*/shim*.efi',
1410            '/EFI/*/shim*.efi'
1411        ]
1412        for shim_vendor_pattern in shim_vendor_patterns:
1413            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1414                return os.path.dirname(shim_file)
1415
1416    @staticmethod
1417    def get_default_volume_group_name():
1418        """
1419        Provides default LVM volume group name
1420
1421        :return: name
1422
1423        :rtype: str
1424        """
1425        return 'systemVG'
1426
1427    @staticmethod
1428    def get_min_partition_mbytes():
1429        """
1430        Provides default minimum partition size in mbytes
1431
1432        :return: mbsize value
1433
1434        :rtype: int
1435        """
1436        return 10
1437
1438    @staticmethod
1439    def get_min_volume_mbytes(filesystem: str):
1440        """
1441        Provides default minimum LVM volume size in mbytes
1442        per filesystem
1443
1444        :return: mbsize value
1445
1446        :rtype: int
1447        """
1448        if filesystem == 'btrfs':
1449            return 120
1450        elif filesystem == 'xfs':
1451            return 300
1452        else:
1453            return 30
1454
1455    @staticmethod
1456    def get_lvm_overhead_mbytes():
1457        """
1458        Provides empiric LVM overhead size in mbytes
1459
1460        :return: mbsize value
1461
1462        :rtype: int
1463        """
1464        return 80
1465
1466    @staticmethod
1467    def get_default_boot_mbytes():
1468        """
1469        Provides default boot partition size in mbytes
1470
1471        :return: mbsize value
1472
1473        :rtype: int
1474        """
1475        return 300
1476
1477    @staticmethod
1478    def get_default_efi_boot_mbytes():
1479        """
1480        Provides default EFI partition size in mbytes
1481
1482        :return: mbsize value
1483
1484        :rtype: int
1485        """
1486        return 20
1487
1488    @staticmethod
1489    def get_recovery_spare_mbytes():
1490        """
1491        Provides spare size of recovery partition in mbytes
1492
1493        :return: mbsize value
1494
1495        :rtype: int
1496        """
1497        return 300
1498
1499    @staticmethod
1500    def get_default_legacy_bios_mbytes():
1501        """
1502        Provides default size of bios_grub partition in mbytes
1503
1504        :return: mbsize value
1505
1506        :rtype: int
1507        """
1508        return 2
1509
1510    @staticmethod
1511    def get_default_prep_mbytes():
1512        """
1513        Provides default size of prep partition in mbytes
1514
1515        :return: mbsize value
1516
1517        :rtype: int
1518        """
1519        return 8
1520
1521    @staticmethod
1522    def get_disk_format_types():
1523        """
1524        Provides supported disk format types
1525
1526        :return: disk types
1527
1528        :rtype: list
1529        """
1530        return [
1531            'gce',
1532            'qcow2',
1533            'vmdk',
1534            'ova',
1535            'meta',
1536            'vmx',
1537            'vhd',
1538            'vhdx',
1539            'vhdfixed',
1540            'vdi',
1541            'vagrant.libvirt.box',
1542            'vagrant.virtualbox.box',
1543            'oci'
1544        ]
1545
1546    @staticmethod
1547    def get_vagrant_config_virtualbox_guest_additions():
1548        """
1549        Provides the default value for
1550        ``vagrantconfig.virtualbox_guest_additions_present``
1551
1552        :return: whether guest additions are expected to be present in the
1553            vagrant box
1554
1555        :rtype: bool
1556        """
1557        return False
1558
1559    @staticmethod
1560    def get_firmware_types():
1561        """
1562        Provides supported architecture specific firmware types
1563
1564        :return: firmware types per architecture
1565
1566        :rtype: dict
1567        """
1568        return {
1569            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1570            'i586': ['bios'],
1571            'i686': ['bios'],
1572            'ix86': ['bios'],
1573            'aarch64': ['efi', 'uefi'],
1574            'arm64': ['efi', 'uefi'],
1575            'armv5el': ['efi', 'uefi'],
1576            'armv5tel': ['efi', 'uefi'],
1577            'armv6hl': ['efi', 'uefi'],
1578            'armv6l': ['efi', 'uefi'],
1579            'armv7hl': ['efi', 'uefi'],
1580            'armv7l': ['efi', 'uefi'],
1581            'armv8l': ['efi', 'uefi'],
1582            'loongarch64': ['efi', 'uefi'],
1583            'ppc': ['ofw'],
1584            'ppc64': ['ofw', 'opal'],
1585            'ppc64le': ['ofw', 'opal'],
1586            'riscv64': ['efi', 'uefi'],
1587            's390': [],
1588            's390x': []
1589        }
1590
1591    @staticmethod
1592    def get_default_firmware(arch):
1593        """
1594        Provides default firmware for specified architecture
1595
1596        :param string arch: machine architecture name
1597
1598        :return: firmware name
1599
1600        :rtype: str
1601        """
1602        default_firmware = {
1603            'x86_64': 'bios',
1604            'i586': 'bios',
1605            'i686': 'bios',
1606            'ix86': 'bios',
1607            'loongarch64': 'efi',
1608            'ppc': 'ofw',
1609            'ppc64': 'ofw',
1610            'ppc64le': 'ofw',
1611            'arm64': 'efi',
1612            'aarch64': 'efi',
1613            'armv5el': 'efi',
1614            'armv5tel': 'efi',
1615            'armv6hl': 'efi',
1616            'armv6l': 'efi',
1617            'armv7hl': 'efi',
1618            'armv7l': 'efi',
1619            'armv8l': 'efi',
1620            'riscv64': 'efi'
1621        }
1622        if arch in default_firmware:
1623            return default_firmware[arch]
1624
1625    @staticmethod
1626    def get_efi_capable_firmware_names():
1627        """
1628        Provides list of EFI capable firmware names. These are
1629        those for which kiwi supports the creation of an EFI
1630        bootable disk image
1631
1632        :return: firmware names
1633
1634        :rtype: list
1635        """
1636        return ['efi', 'uefi']
1637
1638    @staticmethod
1639    def get_ec2_capable_firmware_names():
1640        """
1641        Provides list of EC2 capable firmware names. These are
1642        those for which kiwi supports the creation of disk images
1643        bootable within the Amazon EC2 public cloud
1644
1645        :return: firmware names
1646
1647        :rtype: list
1648        """
1649        return ['ec2']
1650
1651    @staticmethod
1652    def get_efi_module_directory_name(arch):
1653        """
1654        Provides architecture specific EFI directory name which
1655        stores the EFI binaries for the desired architecture.
1656
1657        :param string arch: machine architecture name
1658
1659        :return: directory name
1660
1661        :rtype: str
1662        """
1663        default_module_directory_names = {
1664            'x86_64': 'x86_64-efi',
1665            'i386': 'i386-efi',
1666
1667            # There is no dedicated xen architecture but there are
1668            # modules provided for xen. Thus we treat it as an
1669            # architecture
1670            'x86_64_xen': 'x86_64-xen',
1671
1672            'aarch64': 'arm64-efi',
1673            'arm64': 'arm64-efi',
1674            'armv5el': 'arm-efi',
1675            'armv5tel': 'arm-efi',
1676            'armv6l': 'arm-efi',
1677            'armv7l': 'arm-efi',
1678            'armv8l': 'arm-efi',
1679            'loongarch64': 'loongarch64-efi',
1680            'riscv64': 'riscv64-efi'
1681        }
1682        if arch in default_module_directory_names:
1683            return default_module_directory_names[arch]
1684
1685    @staticmethod
1686    def get_grub_platform_module_directory_name():
1687        """
1688        Provides grub platform specific directory name which
1689        stores the grub module binaries
1690
1691        :return: directory name
1692
1693        :rtype: str
1694        """
1695        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1696            Defaults.get_platform_name()
1697        ) else 'i386-pc'
1698
1699    @staticmethod
1700    def get_efi_image_name(arch):
1701        """
1702        Provides architecture specific EFI boot binary name
1703
1704        :param string arch: machine architecture name
1705
1706        :return: name
1707
1708        :rtype: str
1709        """
1710        default_efi_image_names = {
1711            'x86_64': 'bootx64.efi',
1712            'i386': 'bootia32.efi',
1713            'aarch64': 'bootaa64.efi',
1714            'arm64': 'bootaa64.efi',
1715            'armv5el': 'bootarm.efi',
1716            'armv5tel': 'bootarm.efi',
1717            'armv6l': 'bootarm.efi',
1718            'armv7l': 'bootarm.efi',
1719            'armv8l': 'bootarm.efi',
1720            'loongarch64': 'bootloongarch64.efi',
1721            'riscv64': 'bootriscv64.efi'
1722        }
1723        if arch in default_efi_image_names:
1724            return default_efi_image_names[arch]
1725
1726    @staticmethod
1727    def get_grub_platform_image_name():
1728        """
1729        Provides platform specific core boot binary name
1730
1731        :return: name
1732
1733        :rtype: str
1734        """
1735        return 'grub.elf' if Defaults.is_ppc64_arch(
1736            Defaults.get_platform_name()
1737        ) else 'core.img'
1738
1739    @staticmethod
1740    def get_default_boot_timeout_seconds():
1741        """
1742        Provides default boot timeout in seconds
1743
1744        :return: seconds
1745
1746        :rtype: int
1747        """
1748        return 10
1749
1750    @staticmethod
1751    def get_default_disk_start_sector():
1752        """
1753        Provides the default initial disk sector for the first disk
1754        partition.
1755
1756        :return: sector value
1757
1758        :rtype: int
1759        """
1760        return Defaults().defaults['kiwi_startsector']
1761
1762    @staticmethod
1763    def get_default_efi_partition_table_type():
1764        """
1765        Provides the default partition table type for efi firmwares.
1766
1767        :return: partition table type name
1768
1769        :rtype: str
1770        """
1771        return 'gpt'
1772
1773    @staticmethod
1774    def get_default_inode_size():
1775        """
1776        Provides default size of inodes in bytes. This is only
1777        relevant for inode based filesystems
1778
1779        :return: bytesize value
1780
1781        :rtype: int
1782        """
1783        return Defaults().defaults['kiwi_inode_size']
1784
1785    @staticmethod
1786    def get_archive_image_types():
1787        """
1788        Provides list of supported archive image types
1789
1790        :return: archive names
1791
1792        :rtype: list
1793        """
1794        return ['tbz', 'cpio']
1795
1796    @staticmethod
1797    def get_container_image_types():
1798        """
1799        Provides list of supported container image types
1800
1801        :return: container names
1802
1803        :rtype: list
1804        """
1805        return ['docker', 'oci', 'appx', 'wsl']
1806
1807    @staticmethod
1808    def get_filesystem_image_types():
1809        """
1810        Provides list of supported filesystem image types
1811
1812        :return: filesystem names
1813
1814        :rtype: list
1815        """
1816        return [
1817            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1818            'xfs', 'fat16', 'fat32', 'erofs'
1819        ]
1820
1821    @staticmethod
1822    def get_default_live_iso_type():
1823        """
1824        Provides default live iso union type
1825
1826        :return: live iso type
1827
1828        :rtype: str
1829        """
1830        return 'overlay'
1831
1832    @staticmethod
1833    def get_default_uri_type():
1834        """
1835        Provides default URI type
1836
1837        Absolute path specifications used in the context of an URI
1838        will apply the specified default mime type
1839
1840        :return: URI mime type
1841
1842        :rtype: str
1843        """
1844        return 'dir:/'
1845
1846    @staticmethod
1847    def get_dracut_conf_name():
1848        """
1849        Provides file path of dracut config file to be used with KIWI
1850
1851        :return: file path name
1852
1853        :rtype: str
1854        """
1855        return '/etc/dracut.conf.d/02-kiwi.conf'
1856
1857    @staticmethod
1858    def get_live_dracut_modules_from_flag(flag_name):
1859        """
1860        Provides flag_name to dracut modules name map
1861
1862        Depending on the value of the flag attribute in the KIWI image
1863        description specific dracut modules need to be selected
1864
1865        :return: dracut module names as list
1866
1867        :rtype: list
1868        """
1869        live_modules = {
1870            'overlay': ['kiwi-live'],
1871            'dmsquash': ['dmsquash-live', 'livenet']
1872        }
1873        if flag_name in live_modules:
1874            return live_modules[flag_name]
1875        else:
1876            return ['kiwi-live']
1877
1878    @staticmethod
1879    def get_default_live_iso_root_filesystem():
1880        """
1881        Provides default live iso root filesystem type
1882
1883        :return: filesystem name
1884
1885        :rtype: str
1886        """
1887        return 'ext4'
1888
1889    @staticmethod
1890    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1891        """
1892        Provides list of boot options passed to the dracut
1893        kiwi-live module to setup persistent writing
1894
1895        :return: list of boot options
1896
1897        :rtype: list
1898        """
1899        live_iso_persistent_boot_options = [
1900            'rd.live.overlay.persistent'
1901        ]
1902        if persistent_filesystem:
1903            live_iso_persistent_boot_options.append(
1904                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1905            )
1906        return live_iso_persistent_boot_options
1907
1908    @staticmethod
1909    def get_disk_image_types():
1910        """
1911        Provides supported disk image types
1912
1913        :return: disk image type names
1914
1915        :rtype: list
1916        """
1917        return ['oem']
1918
1919    @staticmethod
1920    def get_live_image_types():
1921        """
1922        Provides supported live image types
1923
1924        :return: live image type names
1925
1926        :rtype: list
1927        """
1928        return ['iso']
1929
1930    @staticmethod
1931    def get_kis_image_types():
1932        """
1933        Provides supported kis image types
1934
1935        :return: kis image type names
1936
1937        :rtype: list
1938        """
1939        return ['kis', 'pxe']
1940
1941    @staticmethod
1942    def get_enclaves_image_types():
1943        """
1944        Provides supported enclave(initrd-only) image types
1945
1946        :return: enclave image type names
1947
1948        :rtype: list
1949        """
1950        return ['enclave']
1951
1952    @staticmethod
1953    def get_boot_image_description_path():
1954        """
1955        Provides the path to find custom kiwi boot descriptions
1956
1957        :return: directory path
1958
1959        :rtype: str
1960        """
1961        return '/usr/share/kiwi/custom_boot'
1962
1963    @staticmethod
1964    def get_boot_image_strip_file():
1965        """
1966        Provides the file path to bootloader strip metadata.
1967        This file contains information about the files and directories
1968        automatically striped out from the kiwi initrd
1969
1970        :return: file path
1971
1972        :rtype: str
1973        """
1974        return Defaults.project_file('config/strip.xml')
1975
1976    @staticmethod
1977    def get_schema_file():
1978        """
1979        Provides file path to kiwi RelaxNG schema
1980
1981        :return: file path
1982
1983        :rtype: str
1984        """
1985        return Defaults.project_file('schema/kiwi.rng')
1986
1987    @staticmethod
1988    def get_common_functions_file():
1989        """
1990        Provides the file path to config functions metadata.
1991
1992        This file contains bash functions used for system
1993        configuration or in the boot code from the kiwi initrd
1994
1995        :return: file path
1996
1997        :rtype: str
1998        """
1999        return Defaults.project_file('config/functions.sh')
2000
2001    @staticmethod
2002    def get_xsl_stylesheet_file():
2003        """
2004        Provides the file path to the KIWI XSLT style sheets
2005
2006        :return: file path
2007
2008        :rtype: str
2009        """
2010        return Defaults.project_file('xsl/master.xsl')
2011
2012    @staticmethod
2013    def get_schematron_module_name():
2014        """
2015        Provides module name for XML SchemaTron validations
2016
2017        :return: python module name
2018
2019        :rtype: str
2020        """
2021        return 'lxml.isoschematron'
2022
2023    @staticmethod
2024    def project_file(filename):
2025        """
2026        Provides the python module base directory search path
2027
2028        The method uses the importlib.resources.path method to identify
2029        files and directories from the application
2030
2031        :param string filename: relative project file
2032
2033        :return: absolute file path name
2034
2035        :rtype: str
2036        """
2037        with as_file(importlib.resources.files('kiwi')) as path:
2038            return f'{path}/{filename}'
2039
2040    @staticmethod
2041    def get_imported_root_image(root_dir):
2042        """
2043        Provides the path to an imported root system image
2044
2045        If the image description specified a derived_from attribute
2046        the file from this attribute is copied into the root_dir
2047        using the name as provided by this method
2048
2049        :param string root_dir: image root directory
2050
2051        :return: file path name
2052
2053        :rtype: str
2054        """
2055        return os.sep.join([root_dir, 'image', 'imported_root'])
2056
2057    @staticmethod
2058    def get_iso_boot_path():
2059        """
2060        Provides arch specific relative path to boot files
2061        on kiwi iso filesystems
2062
2063        :return: relative path name
2064
2065        :rtype: str
2066        """
2067        return os.sep.join(
2068            ['boot', Defaults.get_platform_name()]
2069        )
2070
2071    @staticmethod
2072    def get_iso_tool_category():
2073        """
2074        Provides default iso tool category
2075
2076        :return: name
2077
2078        :rtype: str
2079        """
2080        return 'xorriso'
2081
2082    @staticmethod
2083    def get_iso_media_tag_tool():
2084        """
2085        Provides default iso media tag tool
2086
2087        :return: name
2088
2089        :rtype: str
2090        """
2091        return 'checkmedia'
2092
2093    @staticmethod
2094    def get_container_compression():
2095        """
2096        Provides default container compression
2097
2098        :return: True
2099
2100        :rtype: bool
2101        """
2102        return True
2103
2104    @staticmethod
2105    def get_default_container_name():
2106        """
2107        Provides the default container name.
2108
2109        :return: name
2110
2111        :rtype: str
2112        """
2113        return 'kiwi-container'
2114
2115    @staticmethod
2116    def get_container_base_image_tag():
2117        """
2118        Provides the tag used to identify base layers during the build
2119        of derived images.
2120
2121        :return: tag
2122
2123        :rtype: str
2124        """
2125        return 'base_layer'
2126
2127    @staticmethod
2128    def get_oci_archive_tool():
2129        """
2130        Provides the default OCI archive tool name.
2131
2132        :return: name
2133
2134        :rtype: str
2135        """
2136        return 'umoci'
2137
2138    @staticmethod
2139    def get_part_mapper_tool():
2140        """
2141        Provides the default partition mapper tool name.
2142
2143        :return: name
2144
2145        :rtype: str
2146        """
2147        host_architecture = Defaults.get_platform_name()
2148        if 's390' in host_architecture:
2149            return 'kpartx'
2150        return 'partx'
2151
2152    @staticmethod
2153    def get_default_container_tag():
2154        """
2155        Provides the default container tag.
2156
2157        :return: tag
2158
2159        :rtype: str
2160        """
2161        return 'latest'
2162
2163    @staticmethod
2164    def get_default_container_subcommand():
2165        """
2166        Provides the default container subcommand.
2167
2168        :return: command as a list of arguments
2169
2170        :rtype: list
2171        """
2172        return ['/bin/bash']
2173
2174    @staticmethod
2175    def get_default_container_created_by():
2176        """
2177        Provides the default 'created by' history entry for containers.
2178
2179        :return: the specific kiwi version used for the build
2180
2181        :rtype: str
2182        """
2183        return 'KIWI {0}'.format(__version__)
2184
2185    @staticmethod
2186    def get_custom_rpm_macros_path():
2187        """
2188        Returns the custom macros directory for the rpm database.
2189
2190        :return: path name
2191
2192        :rtype: str
2193        """
2194        return 'usr/lib/rpm/macros.d'
2195
2196    @staticmethod
2197    def get_custom_rpm_bootstrap_macro_name():
2198        """
2199        Returns the rpm bootstrap macro file name created
2200        in the custom rpm macros path
2201
2202        :return: filename
2203
2204        :rtype: str
2205        """
2206        return 'macros.kiwi-bootstrap-config'
2207
2208    @staticmethod
2209    def get_custom_rpm_image_macro_name():
2210        """
2211        Returns the rpm image macro file name created
2212        in the custom rpm macros path
2213
2214        :return: filename
2215
2216        :rtype: str
2217        """
2218        return 'macros.kiwi-image-config'
2219
2220    @staticmethod
2221    def get_default_package_manager() -> str:
2222        """
2223        Returns the default package manager name if none
2224        is configured in the image description
2225
2226        :return: package manager name
2227
2228        :rtype: str
2229        """
2230        return 'dnf4'
2231
2232    @staticmethod
2233    def get_default_packager_tool(package_manager):
2234        """
2235        Provides the packager tool according to the package manager
2236
2237        :param string package_manager: package manger name
2238
2239        :return: packager tool binary name
2240
2241        :rtype: str
2242        """
2243        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2244        deb_based = ['apt']
2245        if package_manager in rpm_based:
2246            return 'rpm'
2247        elif package_manager in deb_based:
2248            return 'dpkg'
2249        elif package_manager == 'pacman':
2250            return 'pacman'
2251
2252    @staticmethod
2253    def get_discoverable_partition_ids() -> Dict[str, str]:
2254        """
2255        Provides arch specific partition UUIDs as defined
2256        by the UAPI group
2257
2258        :return: partition UUIDs
2259
2260        :rtype: dict
2261        """
2262        arch = Defaults.get_platform_name()
2263        part_uuids_archs = {
2264            'x86_64': {
2265                'root':
2266                    '4f68bce3e8cd4db196e7fbcaf984b709',
2267                'usr':
2268                    '8484680c952148c69c11b0720656f69e',
2269                'usr-verity':
2270                    '77ff5f63e7b64633acf41565b864c0e6'
2271            },
2272            'ix86': {
2273                'root':
2274                    '44479540f29741b29af7d131d5f0458a',
2275                'usr':
2276                    '75250d768cc6458ebd66bd47cc81a812',
2277                'usr-verity':
2278                    '8f461b0d14ee4e819aa9049b6fb97abd'
2279            },
2280            'aarch64': {
2281                'root':
2282                    'b921b0451df041c3af444c6f280d3fae',
2283                'usr':
2284                    'b0e01050ee5f4390949a9101b17104e9',
2285                'usr-verity':
2286                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2287            },
2288            'riscv64': {
2289                'root':
2290                    '72ec70a6cf7440e6bd494bda08e8f224',
2291                'usr':
2292                    'beaec34b8442439ba40b984381ed097d',
2293                'usr-verity':
2294                    '8f1056be9b0547c481d6be53128e5b54'
2295            }
2296        }
2297        part_uuids_arch = part_uuids_archs.get(arch) or {}
2298        return {
2299            'root':
2300                part_uuids_arch.get('root') or '',
2301            'usr':
2302                part_uuids_arch.get('usr') or '',
2303            'usr-verity':
2304                part_uuids_arch.get('usr-verity') or '',
2305            'usr-secondary':
2306                '75250d768cc6458ebd66bd47cc81a812',
2307            'usr-secondary-verity':
2308                '8f461b0d14ee4e819aa9049b6fb97abd',
2309            'esp':
2310                'c12a7328f81f11d2ba4b00a0c93ec93b',
2311            'xbootldr':
2312                'bc13c2ff59e64262a352b275fd6f7172',
2313            'swap':
2314                '0657fd6da4ab43c484e50933c84b4f4f',
2315            'home':
2316                '933ac7e12eb44f13b8440e14e2aef915',
2317            'srv':
2318                '3b8f842520e04f3b907f1a25a76f98e8',
2319            'var':
2320                '4d21b016b53445c2a9fb5c16e091fd2d',
2321            'tmp':
2322                '7ec6f5573bc54acab29316ef5df639d1',
2323            'user-home':
2324                '773f91ef66d449b5bd83d683bf40ad16',
2325            'linux-generic':
2326                '0fc63daf848347728e793d69d8477de4'
2327        }
2328
2329    @staticmethod
2330    def get_bls_loader_entries_dir() -> str:
2331        """
2332        Provide default loader entries directory for BLS loaders
2333
2334        :return: directory name
2335
2336        :rtype: str
2337        """
2338        return '/boot/loader/entries'
2339
2340    @staticmethod
2341    def get_apk_repo_config() -> str:
2342        """
2343        Repository file for apk
2344
2345        :return: file path name
2346
2347        :rtype: str
2348        """
2349        return '/etc/apk/repositories'
2350
2351    @staticmethod
2352    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2353        return CA_UPDATE_MAP.get(target_distribution)
2354
2355    @staticmethod
2356    def get_ca_target_distributions() -> List[str]:
2357        return sorted(CA_UPDATE_MAP.keys())
2358
2359    def get(self, key):
2360        """
2361        Implements get method for profile elements
2362
2363        :param string key: profile keyname
2364
2365        :return: key value
2366
2367        :rtype: str
2368        """
2369        if key in self.defaults:
2370            return self.defaults[key]
2371
2372    @staticmethod
2373    def get_profile_file(root_dir):
2374        """
2375        Return name of profile file for given root directory
2376        """
2377        return root_dir + '/.profile'
2378
2379    def to_profile(self, profile):
2380        """
2381        Implements method to add list of profile keys and their values
2382        to the specified instance of a Profile class
2383
2384        :param object profile: Profile instance
2385        """
2386        for key in sorted(self.profile_key_list):
2387            # Do not apply default values to any variable that was
2388            # already defined in the profile instance.
2389            cur_profile = profile.dot_profile
2390            if key not in cur_profile or cur_profile[key] is None:
2391                profile.add(key, self.get(key))
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/almalinux',
1377            'EFI/opensuse',
1378            'EFI/ubuntu',
1379            'EFI/debian'
1380        ]
1381        for efi_vendor_directory in efi_vendor_directories:
1382            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1383            if os.path.exists(efi_vendor_directory):
1384                return efi_vendor_directory
1385
1386    @staticmethod
1387    def get_vendor_grubenv(efi_path):
1388        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1389        if efi_vendor_directory:
1390            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1391            if os.path.exists(grubenv):
1392                return grubenv
1393
1394    @staticmethod
1395    def get_shim_vendor_directory(root_path):
1396        """
1397        Provides shim vendor directory
1398
1399        Searches distribution specific locations to find shim.efi
1400        below the given root path and return the directory name
1401        to the file found
1402
1403        :param string root_path: image root path
1404
1405        :return: directory path or None
1406
1407        :rtype: str
1408        """
1409        shim_vendor_patterns = [
1410            '/boot/efi/EFI/*/shim*.efi',
1411            '/EFI/*/shim*.efi'
1412        ]
1413        for shim_vendor_pattern in shim_vendor_patterns:
1414            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1415                return os.path.dirname(shim_file)
1416
1417    @staticmethod
1418    def get_default_volume_group_name():
1419        """
1420        Provides default LVM volume group name
1421
1422        :return: name
1423
1424        :rtype: str
1425        """
1426        return 'systemVG'
1427
1428    @staticmethod
1429    def get_min_partition_mbytes():
1430        """
1431        Provides default minimum partition size in mbytes
1432
1433        :return: mbsize value
1434
1435        :rtype: int
1436        """
1437        return 10
1438
1439    @staticmethod
1440    def get_min_volume_mbytes(filesystem: str):
1441        """
1442        Provides default minimum LVM volume size in mbytes
1443        per filesystem
1444
1445        :return: mbsize value
1446
1447        :rtype: int
1448        """
1449        if filesystem == 'btrfs':
1450            return 120
1451        elif filesystem == 'xfs':
1452            return 300
1453        else:
1454            return 30
1455
1456    @staticmethod
1457    def get_lvm_overhead_mbytes():
1458        """
1459        Provides empiric LVM overhead size in mbytes
1460
1461        :return: mbsize value
1462
1463        :rtype: int
1464        """
1465        return 80
1466
1467    @staticmethod
1468    def get_default_boot_mbytes():
1469        """
1470        Provides default boot partition size in mbytes
1471
1472        :return: mbsize value
1473
1474        :rtype: int
1475        """
1476        return 300
1477
1478    @staticmethod
1479    def get_default_efi_boot_mbytes():
1480        """
1481        Provides default EFI partition size in mbytes
1482
1483        :return: mbsize value
1484
1485        :rtype: int
1486        """
1487        return 20
1488
1489    @staticmethod
1490    def get_recovery_spare_mbytes():
1491        """
1492        Provides spare size of recovery partition in mbytes
1493
1494        :return: mbsize value
1495
1496        :rtype: int
1497        """
1498        return 300
1499
1500    @staticmethod
1501    def get_default_legacy_bios_mbytes():
1502        """
1503        Provides default size of bios_grub partition in mbytes
1504
1505        :return: mbsize value
1506
1507        :rtype: int
1508        """
1509        return 2
1510
1511    @staticmethod
1512    def get_default_prep_mbytes():
1513        """
1514        Provides default size of prep partition in mbytes
1515
1516        :return: mbsize value
1517
1518        :rtype: int
1519        """
1520        return 8
1521
1522    @staticmethod
1523    def get_disk_format_types():
1524        """
1525        Provides supported disk format types
1526
1527        :return: disk types
1528
1529        :rtype: list
1530        """
1531        return [
1532            'gce',
1533            'qcow2',
1534            'vmdk',
1535            'ova',
1536            'meta',
1537            'vmx',
1538            'vhd',
1539            'vhdx',
1540            'vhdfixed',
1541            'vdi',
1542            'vagrant.libvirt.box',
1543            'vagrant.virtualbox.box',
1544            'oci'
1545        ]
1546
1547    @staticmethod
1548    def get_vagrant_config_virtualbox_guest_additions():
1549        """
1550        Provides the default value for
1551        ``vagrantconfig.virtualbox_guest_additions_present``
1552
1553        :return: whether guest additions are expected to be present in the
1554            vagrant box
1555
1556        :rtype: bool
1557        """
1558        return False
1559
1560    @staticmethod
1561    def get_firmware_types():
1562        """
1563        Provides supported architecture specific firmware types
1564
1565        :return: firmware types per architecture
1566
1567        :rtype: dict
1568        """
1569        return {
1570            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1571            'i586': ['bios'],
1572            'i686': ['bios'],
1573            'ix86': ['bios'],
1574            'aarch64': ['efi', 'uefi'],
1575            'arm64': ['efi', 'uefi'],
1576            'armv5el': ['efi', 'uefi'],
1577            'armv5tel': ['efi', 'uefi'],
1578            'armv6hl': ['efi', 'uefi'],
1579            'armv6l': ['efi', 'uefi'],
1580            'armv7hl': ['efi', 'uefi'],
1581            'armv7l': ['efi', 'uefi'],
1582            'armv8l': ['efi', 'uefi'],
1583            'loongarch64': ['efi', 'uefi'],
1584            'ppc': ['ofw'],
1585            'ppc64': ['ofw', 'opal'],
1586            'ppc64le': ['ofw', 'opal'],
1587            'riscv64': ['efi', 'uefi'],
1588            's390': [],
1589            's390x': []
1590        }
1591
1592    @staticmethod
1593    def get_default_firmware(arch):
1594        """
1595        Provides default firmware for specified architecture
1596
1597        :param string arch: machine architecture name
1598
1599        :return: firmware name
1600
1601        :rtype: str
1602        """
1603        default_firmware = {
1604            'x86_64': 'bios',
1605            'i586': 'bios',
1606            'i686': 'bios',
1607            'ix86': 'bios',
1608            'loongarch64': 'efi',
1609            'ppc': 'ofw',
1610            'ppc64': 'ofw',
1611            'ppc64le': 'ofw',
1612            'arm64': 'efi',
1613            'aarch64': 'efi',
1614            'armv5el': 'efi',
1615            'armv5tel': 'efi',
1616            'armv6hl': 'efi',
1617            'armv6l': 'efi',
1618            'armv7hl': 'efi',
1619            'armv7l': 'efi',
1620            'armv8l': 'efi',
1621            'riscv64': 'efi'
1622        }
1623        if arch in default_firmware:
1624            return default_firmware[arch]
1625
1626    @staticmethod
1627    def get_efi_capable_firmware_names():
1628        """
1629        Provides list of EFI capable firmware names. These are
1630        those for which kiwi supports the creation of an EFI
1631        bootable disk image
1632
1633        :return: firmware names
1634
1635        :rtype: list
1636        """
1637        return ['efi', 'uefi']
1638
1639    @staticmethod
1640    def get_ec2_capable_firmware_names():
1641        """
1642        Provides list of EC2 capable firmware names. These are
1643        those for which kiwi supports the creation of disk images
1644        bootable within the Amazon EC2 public cloud
1645
1646        :return: firmware names
1647
1648        :rtype: list
1649        """
1650        return ['ec2']
1651
1652    @staticmethod
1653    def get_efi_module_directory_name(arch):
1654        """
1655        Provides architecture specific EFI directory name which
1656        stores the EFI binaries for the desired architecture.
1657
1658        :param string arch: machine architecture name
1659
1660        :return: directory name
1661
1662        :rtype: str
1663        """
1664        default_module_directory_names = {
1665            'x86_64': 'x86_64-efi',
1666            'i386': 'i386-efi',
1667
1668            # There is no dedicated xen architecture but there are
1669            # modules provided for xen. Thus we treat it as an
1670            # architecture
1671            'x86_64_xen': 'x86_64-xen',
1672
1673            'aarch64': 'arm64-efi',
1674            'arm64': 'arm64-efi',
1675            'armv5el': 'arm-efi',
1676            'armv5tel': 'arm-efi',
1677            'armv6l': 'arm-efi',
1678            'armv7l': 'arm-efi',
1679            'armv8l': 'arm-efi',
1680            'loongarch64': 'loongarch64-efi',
1681            'riscv64': 'riscv64-efi'
1682        }
1683        if arch in default_module_directory_names:
1684            return default_module_directory_names[arch]
1685
1686    @staticmethod
1687    def get_grub_platform_module_directory_name():
1688        """
1689        Provides grub platform specific directory name which
1690        stores the grub module binaries
1691
1692        :return: directory name
1693
1694        :rtype: str
1695        """
1696        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1697            Defaults.get_platform_name()
1698        ) else 'i386-pc'
1699
1700    @staticmethod
1701    def get_efi_image_name(arch):
1702        """
1703        Provides architecture specific EFI boot binary name
1704
1705        :param string arch: machine architecture name
1706
1707        :return: name
1708
1709        :rtype: str
1710        """
1711        default_efi_image_names = {
1712            'x86_64': 'bootx64.efi',
1713            'i386': 'bootia32.efi',
1714            'aarch64': 'bootaa64.efi',
1715            'arm64': 'bootaa64.efi',
1716            'armv5el': 'bootarm.efi',
1717            'armv5tel': 'bootarm.efi',
1718            'armv6l': 'bootarm.efi',
1719            'armv7l': 'bootarm.efi',
1720            'armv8l': 'bootarm.efi',
1721            'loongarch64': 'bootloongarch64.efi',
1722            'riscv64': 'bootriscv64.efi'
1723        }
1724        if arch in default_efi_image_names:
1725            return default_efi_image_names[arch]
1726
1727    @staticmethod
1728    def get_grub_platform_image_name():
1729        """
1730        Provides platform specific core boot binary name
1731
1732        :return: name
1733
1734        :rtype: str
1735        """
1736        return 'grub.elf' if Defaults.is_ppc64_arch(
1737            Defaults.get_platform_name()
1738        ) else 'core.img'
1739
1740    @staticmethod
1741    def get_default_boot_timeout_seconds():
1742        """
1743        Provides default boot timeout in seconds
1744
1745        :return: seconds
1746
1747        :rtype: int
1748        """
1749        return 10
1750
1751    @staticmethod
1752    def get_default_disk_start_sector():
1753        """
1754        Provides the default initial disk sector for the first disk
1755        partition.
1756
1757        :return: sector value
1758
1759        :rtype: int
1760        """
1761        return Defaults().defaults['kiwi_startsector']
1762
1763    @staticmethod
1764    def get_default_efi_partition_table_type():
1765        """
1766        Provides the default partition table type for efi firmwares.
1767
1768        :return: partition table type name
1769
1770        :rtype: str
1771        """
1772        return 'gpt'
1773
1774    @staticmethod
1775    def get_default_inode_size():
1776        """
1777        Provides default size of inodes in bytes. This is only
1778        relevant for inode based filesystems
1779
1780        :return: bytesize value
1781
1782        :rtype: int
1783        """
1784        return Defaults().defaults['kiwi_inode_size']
1785
1786    @staticmethod
1787    def get_archive_image_types():
1788        """
1789        Provides list of supported archive image types
1790
1791        :return: archive names
1792
1793        :rtype: list
1794        """
1795        return ['tbz', 'cpio']
1796
1797    @staticmethod
1798    def get_container_image_types():
1799        """
1800        Provides list of supported container image types
1801
1802        :return: container names
1803
1804        :rtype: list
1805        """
1806        return ['docker', 'oci', 'appx', 'wsl']
1807
1808    @staticmethod
1809    def get_filesystem_image_types():
1810        """
1811        Provides list of supported filesystem image types
1812
1813        :return: filesystem names
1814
1815        :rtype: list
1816        """
1817        return [
1818            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1819            'xfs', 'fat16', 'fat32', 'erofs'
1820        ]
1821
1822    @staticmethod
1823    def get_default_live_iso_type():
1824        """
1825        Provides default live iso union type
1826
1827        :return: live iso type
1828
1829        :rtype: str
1830        """
1831        return 'overlay'
1832
1833    @staticmethod
1834    def get_default_uri_type():
1835        """
1836        Provides default URI type
1837
1838        Absolute path specifications used in the context of an URI
1839        will apply the specified default mime type
1840
1841        :return: URI mime type
1842
1843        :rtype: str
1844        """
1845        return 'dir:/'
1846
1847    @staticmethod
1848    def get_dracut_conf_name():
1849        """
1850        Provides file path of dracut config file to be used with KIWI
1851
1852        :return: file path name
1853
1854        :rtype: str
1855        """
1856        return '/etc/dracut.conf.d/02-kiwi.conf'
1857
1858    @staticmethod
1859    def get_live_dracut_modules_from_flag(flag_name):
1860        """
1861        Provides flag_name to dracut modules name map
1862
1863        Depending on the value of the flag attribute in the KIWI image
1864        description specific dracut modules need to be selected
1865
1866        :return: dracut module names as list
1867
1868        :rtype: list
1869        """
1870        live_modules = {
1871            'overlay': ['kiwi-live'],
1872            'dmsquash': ['dmsquash-live', 'livenet']
1873        }
1874        if flag_name in live_modules:
1875            return live_modules[flag_name]
1876        else:
1877            return ['kiwi-live']
1878
1879    @staticmethod
1880    def get_default_live_iso_root_filesystem():
1881        """
1882        Provides default live iso root filesystem type
1883
1884        :return: filesystem name
1885
1886        :rtype: str
1887        """
1888        return 'ext4'
1889
1890    @staticmethod
1891    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1892        """
1893        Provides list of boot options passed to the dracut
1894        kiwi-live module to setup persistent writing
1895
1896        :return: list of boot options
1897
1898        :rtype: list
1899        """
1900        live_iso_persistent_boot_options = [
1901            'rd.live.overlay.persistent'
1902        ]
1903        if persistent_filesystem:
1904            live_iso_persistent_boot_options.append(
1905                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1906            )
1907        return live_iso_persistent_boot_options
1908
1909    @staticmethod
1910    def get_disk_image_types():
1911        """
1912        Provides supported disk image types
1913
1914        :return: disk image type names
1915
1916        :rtype: list
1917        """
1918        return ['oem']
1919
1920    @staticmethod
1921    def get_live_image_types():
1922        """
1923        Provides supported live image types
1924
1925        :return: live image type names
1926
1927        :rtype: list
1928        """
1929        return ['iso']
1930
1931    @staticmethod
1932    def get_kis_image_types():
1933        """
1934        Provides supported kis image types
1935
1936        :return: kis image type names
1937
1938        :rtype: list
1939        """
1940        return ['kis', 'pxe']
1941
1942    @staticmethod
1943    def get_enclaves_image_types():
1944        """
1945        Provides supported enclave(initrd-only) image types
1946
1947        :return: enclave image type names
1948
1949        :rtype: list
1950        """
1951        return ['enclave']
1952
1953    @staticmethod
1954    def get_boot_image_description_path():
1955        """
1956        Provides the path to find custom kiwi boot descriptions
1957
1958        :return: directory path
1959
1960        :rtype: str
1961        """
1962        return '/usr/share/kiwi/custom_boot'
1963
1964    @staticmethod
1965    def get_boot_image_strip_file():
1966        """
1967        Provides the file path to bootloader strip metadata.
1968        This file contains information about the files and directories
1969        automatically striped out from the kiwi initrd
1970
1971        :return: file path
1972
1973        :rtype: str
1974        """
1975        return Defaults.project_file('config/strip.xml')
1976
1977    @staticmethod
1978    def get_schema_file():
1979        """
1980        Provides file path to kiwi RelaxNG schema
1981
1982        :return: file path
1983
1984        :rtype: str
1985        """
1986        return Defaults.project_file('schema/kiwi.rng')
1987
1988    @staticmethod
1989    def get_common_functions_file():
1990        """
1991        Provides the file path to config functions metadata.
1992
1993        This file contains bash functions used for system
1994        configuration or in the boot code from the kiwi initrd
1995
1996        :return: file path
1997
1998        :rtype: str
1999        """
2000        return Defaults.project_file('config/functions.sh')
2001
2002    @staticmethod
2003    def get_xsl_stylesheet_file():
2004        """
2005        Provides the file path to the KIWI XSLT style sheets
2006
2007        :return: file path
2008
2009        :rtype: str
2010        """
2011        return Defaults.project_file('xsl/master.xsl')
2012
2013    @staticmethod
2014    def get_schematron_module_name():
2015        """
2016        Provides module name for XML SchemaTron validations
2017
2018        :return: python module name
2019
2020        :rtype: str
2021        """
2022        return 'lxml.isoschematron'
2023
2024    @staticmethod
2025    def project_file(filename):
2026        """
2027        Provides the python module base directory search path
2028
2029        The method uses the importlib.resources.path method to identify
2030        files and directories from the application
2031
2032        :param string filename: relative project file
2033
2034        :return: absolute file path name
2035
2036        :rtype: str
2037        """
2038        with as_file(importlib.resources.files('kiwi')) as path:
2039            return f'{path}/{filename}'
2040
2041    @staticmethod
2042    def get_imported_root_image(root_dir):
2043        """
2044        Provides the path to an imported root system image
2045
2046        If the image description specified a derived_from attribute
2047        the file from this attribute is copied into the root_dir
2048        using the name as provided by this method
2049
2050        :param string root_dir: image root directory
2051
2052        :return: file path name
2053
2054        :rtype: str
2055        """
2056        return os.sep.join([root_dir, 'image', 'imported_root'])
2057
2058    @staticmethod
2059    def get_iso_boot_path():
2060        """
2061        Provides arch specific relative path to boot files
2062        on kiwi iso filesystems
2063
2064        :return: relative path name
2065
2066        :rtype: str
2067        """
2068        return os.sep.join(
2069            ['boot', Defaults.get_platform_name()]
2070        )
2071
2072    @staticmethod
2073    def get_iso_tool_category():
2074        """
2075        Provides default iso tool category
2076
2077        :return: name
2078
2079        :rtype: str
2080        """
2081        return 'xorriso'
2082
2083    @staticmethod
2084    def get_iso_media_tag_tool():
2085        """
2086        Provides default iso media tag tool
2087
2088        :return: name
2089
2090        :rtype: str
2091        """
2092        return 'checkmedia'
2093
2094    @staticmethod
2095    def get_container_compression():
2096        """
2097        Provides default container compression
2098
2099        :return: True
2100
2101        :rtype: bool
2102        """
2103        return True
2104
2105    @staticmethod
2106    def get_default_container_name():
2107        """
2108        Provides the default container name.
2109
2110        :return: name
2111
2112        :rtype: str
2113        """
2114        return 'kiwi-container'
2115
2116    @staticmethod
2117    def get_container_base_image_tag():
2118        """
2119        Provides the tag used to identify base layers during the build
2120        of derived images.
2121
2122        :return: tag
2123
2124        :rtype: str
2125        """
2126        return 'base_layer'
2127
2128    @staticmethod
2129    def get_oci_archive_tool():
2130        """
2131        Provides the default OCI archive tool name.
2132
2133        :return: name
2134
2135        :rtype: str
2136        """
2137        return 'umoci'
2138
2139    @staticmethod
2140    def get_part_mapper_tool():
2141        """
2142        Provides the default partition mapper tool name.
2143
2144        :return: name
2145
2146        :rtype: str
2147        """
2148        host_architecture = Defaults.get_platform_name()
2149        if 's390' in host_architecture:
2150            return 'kpartx'
2151        return 'partx'
2152
2153    @staticmethod
2154    def get_default_container_tag():
2155        """
2156        Provides the default container tag.
2157
2158        :return: tag
2159
2160        :rtype: str
2161        """
2162        return 'latest'
2163
2164    @staticmethod
2165    def get_default_container_subcommand():
2166        """
2167        Provides the default container subcommand.
2168
2169        :return: command as a list of arguments
2170
2171        :rtype: list
2172        """
2173        return ['/bin/bash']
2174
2175    @staticmethod
2176    def get_default_container_created_by():
2177        """
2178        Provides the default 'created by' history entry for containers.
2179
2180        :return: the specific kiwi version used for the build
2181
2182        :rtype: str
2183        """
2184        return 'KIWI {0}'.format(__version__)
2185
2186    @staticmethod
2187    def get_custom_rpm_macros_path():
2188        """
2189        Returns the custom macros directory for the rpm database.
2190
2191        :return: path name
2192
2193        :rtype: str
2194        """
2195        return 'usr/lib/rpm/macros.d'
2196
2197    @staticmethod
2198    def get_custom_rpm_bootstrap_macro_name():
2199        """
2200        Returns the rpm bootstrap macro file name created
2201        in the custom rpm macros path
2202
2203        :return: filename
2204
2205        :rtype: str
2206        """
2207        return 'macros.kiwi-bootstrap-config'
2208
2209    @staticmethod
2210    def get_custom_rpm_image_macro_name():
2211        """
2212        Returns the rpm image macro file name created
2213        in the custom rpm macros path
2214
2215        :return: filename
2216
2217        :rtype: str
2218        """
2219        return 'macros.kiwi-image-config'
2220
2221    @staticmethod
2222    def get_default_package_manager() -> str:
2223        """
2224        Returns the default package manager name if none
2225        is configured in the image description
2226
2227        :return: package manager name
2228
2229        :rtype: str
2230        """
2231        return 'dnf4'
2232
2233    @staticmethod
2234    def get_default_packager_tool(package_manager):
2235        """
2236        Provides the packager tool according to the package manager
2237
2238        :param string package_manager: package manger name
2239
2240        :return: packager tool binary name
2241
2242        :rtype: str
2243        """
2244        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2245        deb_based = ['apt']
2246        if package_manager in rpm_based:
2247            return 'rpm'
2248        elif package_manager in deb_based:
2249            return 'dpkg'
2250        elif package_manager == 'pacman':
2251            return 'pacman'
2252
2253    @staticmethod
2254    def get_discoverable_partition_ids() -> Dict[str, str]:
2255        """
2256        Provides arch specific partition UUIDs as defined
2257        by the UAPI group
2258
2259        :return: partition UUIDs
2260
2261        :rtype: dict
2262        """
2263        arch = Defaults.get_platform_name()
2264        part_uuids_archs = {
2265            'x86_64': {
2266                'root':
2267                    '4f68bce3e8cd4db196e7fbcaf984b709',
2268                'usr':
2269                    '8484680c952148c69c11b0720656f69e',
2270                'usr-verity':
2271                    '77ff5f63e7b64633acf41565b864c0e6'
2272            },
2273            'ix86': {
2274                'root':
2275                    '44479540f29741b29af7d131d5f0458a',
2276                'usr':
2277                    '75250d768cc6458ebd66bd47cc81a812',
2278                'usr-verity':
2279                    '8f461b0d14ee4e819aa9049b6fb97abd'
2280            },
2281            'aarch64': {
2282                'root':
2283                    'b921b0451df041c3af444c6f280d3fae',
2284                'usr':
2285                    'b0e01050ee5f4390949a9101b17104e9',
2286                'usr-verity':
2287                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2288            },
2289            'riscv64': {
2290                'root':
2291                    '72ec70a6cf7440e6bd494bda08e8f224',
2292                'usr':
2293                    'beaec34b8442439ba40b984381ed097d',
2294                'usr-verity':
2295                    '8f1056be9b0547c481d6be53128e5b54'
2296            }
2297        }
2298        part_uuids_arch = part_uuids_archs.get(arch) or {}
2299        return {
2300            'root':
2301                part_uuids_arch.get('root') or '',
2302            'usr':
2303                part_uuids_arch.get('usr') or '',
2304            'usr-verity':
2305                part_uuids_arch.get('usr-verity') or '',
2306            'usr-secondary':
2307                '75250d768cc6458ebd66bd47cc81a812',
2308            'usr-secondary-verity':
2309                '8f461b0d14ee4e819aa9049b6fb97abd',
2310            'esp':
2311                'c12a7328f81f11d2ba4b00a0c93ec93b',
2312            'xbootldr':
2313                'bc13c2ff59e64262a352b275fd6f7172',
2314            'swap':
2315                '0657fd6da4ab43c484e50933c84b4f4f',
2316            'home':
2317                '933ac7e12eb44f13b8440e14e2aef915',
2318            'srv':
2319                '3b8f842520e04f3b907f1a25a76f98e8',
2320            'var':
2321                '4d21b016b53445c2a9fb5c16e091fd2d',
2322            'tmp':
2323                '7ec6f5573bc54acab29316ef5df639d1',
2324            'user-home':
2325                '773f91ef66d449b5bd83d683bf40ad16',
2326            'linux-generic':
2327                '0fc63daf848347728e793d69d8477de4'
2328        }
2329
2330    @staticmethod
2331    def get_bls_loader_entries_dir() -> str:
2332        """
2333        Provide default loader entries directory for BLS loaders
2334
2335        :return: directory name
2336
2337        :rtype: str
2338        """
2339        return '/boot/loader/entries'
2340
2341    @staticmethod
2342    def get_apk_repo_config() -> str:
2343        """
2344        Repository file for apk
2345
2346        :return: file path name
2347
2348        :rtype: str
2349        """
2350        return '/etc/apk/repositories'
2351
2352    @staticmethod
2353    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2354        return CA_UPDATE_MAP.get(target_distribution)
2355
2356    @staticmethod
2357    def get_ca_target_distributions() -> List[str]:
2358        return sorted(CA_UPDATE_MAP.keys())
2359
2360    def get(self, key):
2361        """
2362        Implements get method for profile elements
2363
2364        :param string key: profile keyname
2365
2366        :return: key value
2367
2368        :rtype: str
2369        """
2370        if key in self.defaults:
2371            return self.defaults[key]
2372
2373    @staticmethod
2374    def get_profile_file(root_dir):
2375        """
2376        Return name of profile file for given root directory
2377        """
2378        return root_dir + '/.profile'
2379
2380    def to_profile(self, profile):
2381        """
2382        Implements method to add list of profile keys and their values
2383        to the specified instance of a Profile class
2384
2385        :param object profile: Profile instance
2386        """
2387        for key in sorted(self.profile_key_list):
2388            # Do not apply default values to any variable that was
2389            # already defined in the profile instance.
2390            cur_profile = profile.dot_profile
2391            if key not in cur_profile or cur_profile[key] is None:
2392                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/almalinux',
1377            'EFI/opensuse',
1378            'EFI/ubuntu',
1379            'EFI/debian'
1380        ]
1381        for efi_vendor_directory in efi_vendor_directories:
1382            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1383            if os.path.exists(efi_vendor_directory):
1384                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):
1386    @staticmethod
1387    def get_vendor_grubenv(efi_path):
1388        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1389        if efi_vendor_directory:
1390            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1391            if os.path.exists(grubenv):
1392                return grubenv
@staticmethod
def get_shim_vendor_directory(root_path):
1394    @staticmethod
1395    def get_shim_vendor_directory(root_path):
1396        """
1397        Provides shim vendor directory
1398
1399        Searches distribution specific locations to find shim.efi
1400        below the given root path and return the directory name
1401        to the file found
1402
1403        :param string root_path: image root path
1404
1405        :return: directory path or None
1406
1407        :rtype: str
1408        """
1409        shim_vendor_patterns = [
1410            '/boot/efi/EFI/*/shim*.efi',
1411            '/EFI/*/shim*.efi'
1412        ]
1413        for shim_vendor_pattern in shim_vendor_patterns:
1414            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1415                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():
1417    @staticmethod
1418    def get_default_volume_group_name():
1419        """
1420        Provides default LVM volume group name
1421
1422        :return: name
1423
1424        :rtype: str
1425        """
1426        return 'systemVG'

Provides default LVM volume group name

Returns

name

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

Provides default minimum partition size in mbytes

Returns

mbsize value

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

Provides default minimum LVM volume size in mbytes per filesystem

Returns

mbsize value

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

Provides empiric LVM overhead size in mbytes

Returns

mbsize value

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

Provides default boot partition size in mbytes

Returns

mbsize value

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

Provides default EFI partition size in mbytes

Returns

mbsize value

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

Provides spare size of recovery partition in mbytes

Returns

mbsize value

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

Provides default size of bios_grub partition in mbytes

Returns

mbsize value

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

Provides default size of prep partition in mbytes

Returns

mbsize value

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

Provides supported disk format types

Returns

disk types

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

Provides supported architecture specific firmware types

Returns

firmware types per architecture

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

Provides platform specific core boot binary name

Returns

name

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

Provides default boot timeout in seconds

Returns

seconds

@staticmethod
def get_default_disk_start_sector():
1751    @staticmethod
1752    def get_default_disk_start_sector():
1753        """
1754        Provides the default initial disk sector for the first disk
1755        partition.
1756
1757        :return: sector value
1758
1759        :rtype: int
1760        """
1761        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():
1763    @staticmethod
1764    def get_default_efi_partition_table_type():
1765        """
1766        Provides the default partition table type for efi firmwares.
1767
1768        :return: partition table type name
1769
1770        :rtype: str
1771        """
1772        return 'gpt'

Provides the default partition table type for efi firmwares.

Returns

partition table type name

@staticmethod
def get_default_inode_size():
1774    @staticmethod
1775    def get_default_inode_size():
1776        """
1777        Provides default size of inodes in bytes. This is only
1778        relevant for inode based filesystems
1779
1780        :return: bytesize value
1781
1782        :rtype: int
1783        """
1784        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():
1786    @staticmethod
1787    def get_archive_image_types():
1788        """
1789        Provides list of supported archive image types
1790
1791        :return: archive names
1792
1793        :rtype: list
1794        """
1795        return ['tbz', 'cpio']

Provides list of supported archive image types

Returns

archive names

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

Provides list of supported container image types

Returns

container names

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

Provides list of supported filesystem image types

Returns

filesystem names

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

Provides default live iso union type

Returns

live iso type

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

Provides default live iso root filesystem type

Returns

filesystem name

@staticmethod
def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1890    @staticmethod
1891    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1892        """
1893        Provides list of boot options passed to the dracut
1894        kiwi-live module to setup persistent writing
1895
1896        :return: list of boot options
1897
1898        :rtype: list
1899        """
1900        live_iso_persistent_boot_options = [
1901            'rd.live.overlay.persistent'
1902        ]
1903        if persistent_filesystem:
1904            live_iso_persistent_boot_options.append(
1905                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1906            )
1907        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():
1909    @staticmethod
1910    def get_disk_image_types():
1911        """
1912        Provides supported disk image types
1913
1914        :return: disk image type names
1915
1916        :rtype: list
1917        """
1918        return ['oem']

Provides supported disk image types

Returns

disk image type names

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

Provides supported live image types

Returns

live image type names

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

Provides supported kis image types

Returns

kis image type names

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

Provides supported enclave(initrd-only) image types

Returns

enclave image type names

@staticmethod
def get_boot_image_description_path():
1953    @staticmethod
1954    def get_boot_image_description_path():
1955        """
1956        Provides the path to find custom kiwi boot descriptions
1957
1958        :return: directory path
1959
1960        :rtype: str
1961        """
1962        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():
1964    @staticmethod
1965    def get_boot_image_strip_file():
1966        """
1967        Provides the file path to bootloader strip metadata.
1968        This file contains information about the files and directories
1969        automatically striped out from the kiwi initrd
1970
1971        :return: file path
1972
1973        :rtype: str
1974        """
1975        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():
1977    @staticmethod
1978    def get_schema_file():
1979        """
1980        Provides file path to kiwi RelaxNG schema
1981
1982        :return: file path
1983
1984        :rtype: str
1985        """
1986        return Defaults.project_file('schema/kiwi.rng')

Provides file path to kiwi RelaxNG schema

Returns

file path

@staticmethod
def get_common_functions_file():
1988    @staticmethod
1989    def get_common_functions_file():
1990        """
1991        Provides the file path to config functions metadata.
1992
1993        This file contains bash functions used for system
1994        configuration or in the boot code from the kiwi initrd
1995
1996        :return: file path
1997
1998        :rtype: str
1999        """
2000        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():
2002    @staticmethod
2003    def get_xsl_stylesheet_file():
2004        """
2005        Provides the file path to the KIWI XSLT style sheets
2006
2007        :return: file path
2008
2009        :rtype: str
2010        """
2011        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():
2013    @staticmethod
2014    def get_schematron_module_name():
2015        """
2016        Provides module name for XML SchemaTron validations
2017
2018        :return: python module name
2019
2020        :rtype: str
2021        """
2022        return 'lxml.isoschematron'

Provides module name for XML SchemaTron validations

Returns

python module name

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

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

Returns

relative path name

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

Provides default iso tool category

Returns

name

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

Provides default iso media tag tool

Returns

name

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

Provides default container compression

Returns

True

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

Provides the default container name.

Returns

name

@staticmethod
def get_container_base_image_tag():
2116    @staticmethod
2117    def get_container_base_image_tag():
2118        """
2119        Provides the tag used to identify base layers during the build
2120        of derived images.
2121
2122        :return: tag
2123
2124        :rtype: str
2125        """
2126        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():
2128    @staticmethod
2129    def get_oci_archive_tool():
2130        """
2131        Provides the default OCI archive tool name.
2132
2133        :return: name
2134
2135        :rtype: str
2136        """
2137        return 'umoci'

Provides the default OCI archive tool name.

Returns

name

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

Provides the default partition mapper tool name.

Returns

name

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

Provides the default container tag.

Returns

tag

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

Provides the default container subcommand.

Returns

command as a list of arguments

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

Provides arch specific partition UUIDs as defined by the UAPI group

Returns

partition UUIDs

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

Provide default loader entries directory for BLS loaders

Returns

directory name

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

Repository file for apk

Returns

file path name

@staticmethod
def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2352    @staticmethod
2353    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2354        return CA_UPDATE_MAP.get(target_distribution)
@staticmethod
def get_ca_target_distributions() -> List[str]:
2356    @staticmethod
2357    def get_ca_target_distributions() -> List[str]:
2358        return sorted(CA_UPDATE_MAP.keys())
def get(self, key):
2360    def get(self, key):
2361        """
2362        Implements get method for profile elements
2363
2364        :param string key: profile keyname
2365
2366        :return: key value
2367
2368        :rtype: str
2369        """
2370        if key in self.defaults:
2371            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):
2373    @staticmethod
2374    def get_profile_file(root_dir):
2375        """
2376        Return name of profile file for given root directory
2377        """
2378        return root_dir + '/.profile'

Return name of profile file for given root directory

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