kiwi.defaults

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

shim_loader_type(filename, binaryname)

shim_loader_type(filename: str, binaryname: str)

Create new instance of shim_loader_type(filename, binaryname)

filename: str

Alias for field number 0

binaryname: str

Alias for field number 1

class grub_loader_type(builtins.tuple):

grub_loader_type(filename, binaryname, targetname)

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

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

filename: str

Alias for field number 0

binaryname: str

Alias for field number 1

targetname: str

Alias for field number 2

class unit_type(builtins.tuple):

unit_type(byte, kb, mb, gb)

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

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

byte: str

Alias for field number 0

kb: str

Alias for field number 1

mb: str

Alias for field number 2

gb: str

Alias for field number 3

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

Implements default values

Provides static methods for default values and state information

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

Provides key length to use for random luks keys

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

Provides swapsize in MB

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

Provides compression options for the xz compressor

Returns
Contains list of options

.. code:: python

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

Provides the machine architecture name as used by KIWI

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

Returns

architecture name

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

Sets the platform architecture once

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

Checks if machine architecture is x86 based

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

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

Checks if machine architecture is ppc64 based

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

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

Checks if build host is an open buildservice machine

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

Returns

True if obs worker, else False

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

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

Returns

file basename

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

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

Returns

url path

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

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

Returns

url path

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

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

Returns

directory path

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

Sets the runtime checker metadata filename

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

Sets the shared cache location once

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

Sets the runtime config file once

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

Sets the temp directory location once

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

Provides the shared cache location

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

Returns

directory path

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

Provides the base temp directory location

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

Returns

directory path

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

Provides list of default data sync options

Returns

list of rsync options

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

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

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

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

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

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

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

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

Returns

list of file and directory names

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

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

Returns

list of paths and glob patterns

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

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

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

Returns

list of paths and glob patterns

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

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

Returns

list of file and directory names

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

Provides failsafe boot kernel options

Returns
list of kernel options

.. code:: python

    ['option=value', 'option']
@staticmethod
def get_volume_id():
585    @staticmethod
586    def get_volume_id():
587        """
588        Provides default value for ISO volume ID
589
590        :return: name
591
592        :rtype: str
593        """
594        return 'CDROM'

Provides default value for ISO volume ID

Returns

name

@staticmethod
def get_install_volume_id():
596    @staticmethod
597    def get_install_volume_id():
598        """
599        Provides default value for ISO volume ID for install media
600
601        :return: name
602
603        :rtype: str
604        """
605        return 'INSTALL'

Provides default value for ISO volume ID for install media

Returns

name

@staticmethod
def get_snapper_config_template_file(root: str) -> str:
607    @staticmethod
608    def get_snapper_config_template_file(root: str) -> str:
609        """
610        Provides the default configuration template file for snapper.
611        The location in etc/ are preferred over files in usr/
612
613        :return: file path
614
615        :rtype: str
616        """
617        snapper_templates = [
618            'etc/snapper/config-templates/default',
619            'usr/share/snapper/config-templates/default'
620        ]
621        snapper_default_conf = ''
622        for snapper_template in snapper_templates:
623            template_config = os.path.join(root, snapper_template)
624            if os.path.exists(template_config):
625                snapper_default_conf = template_config
626                break
627        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_bootloader():
629    @staticmethod
630    def get_default_bootloader():
631        """
632        Return default bootloader name which is grub2
633
634        :return: bootloader name
635
636        :rtype: str
637        """
638        return 'grub2'

Return default bootloader name which is grub2

Returns

bootloader name

@staticmethod
def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
640    @staticmethod
641    def get_grub_custom_arguments(root_dir: str) -> Dict[str, str]:
642        return {
643            'grub_directory_name':
644                Defaults.get_grub_boot_directory_name(root_dir),
645            'grub_load_command':
646                'configfile'
647        }
@staticmethod
def get_grub_boot_directory_name(lookup_path):
649    @staticmethod
650    def get_grub_boot_directory_name(lookup_path):
651        """
652        Provides grub2 data directory name in boot/ directory
653
654        Depending on the distribution the grub2 boot path could be
655        either boot/grub2 or boot/grub. The method will decide for
656        the correct base directory name according to the name pattern
657        of the installed grub2 tools
658
659        :return: directory basename
660
661        :rtype: str
662        """
663        if Path.which(filename='grub2-install', root_dir=lookup_path):
664            # the presence of grub2-install is an indicator to put all
665            # grub2 data below boot/grub2
666            return 'grub2'
667        else:
668            # in any other case the assumption is made that all grub
669            # boot data should live below boot/grub
670            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):
672    @staticmethod
673    def get_grub_basic_modules(multiboot):
674        """
675        Provides list of basic grub modules
676
677        :param bool multiboot: grub multiboot mode
678
679        :return: list of module names
680
681        :rtype: list
682        """
683        modules = [
684            'ext2',
685            'iso9660',
686            'linux',
687            'echo',
688            'configfile',
689            'search_label',
690            'search_fs_file',
691            'search',
692            'search_fs_uuid',
693            'ls',
694            'normal',
695            'gzio',
696            'png',
697            'fat',
698            'gettext',
699            'font',
700            'minicmd',
701            'gfxterm',
702            'gfxmenu',
703            'all_video',
704            'xfs',
705            'btrfs',
706            'squash4',
707            'lvm',
708            'luks',
709            'gcry_rijndael',
710            'gcry_sha256',
711            'gcry_sha512',
712            'crypto',
713            'cryptodisk',
714            'test',
715            'true',
716            'loadenv'
717        ]
718        if multiboot:
719            modules.append('multiboot')
720        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):
722    @staticmethod
723    def get_grub_efi_modules(multiboot=False):
724        """
725        Provides list of grub efi modules
726
727        :param bool multiboot: grub multiboot mode
728
729        :return: list of module names
730
731        :rtype: list
732        """
733        modules = Defaults.get_grub_basic_modules(multiboot) + [
734            'part_gpt',
735            'part_msdos',
736            'efi_gop'
737        ]
738        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):
740    @staticmethod
741    def get_grub_platform_modules(multiboot=False):
742        """
743        Provides list of platform specific grub modules
744
745        :param bool multiboot: grub multiboot mode
746
747        :return: list of module names
748
749        :rtype: list
750        """
751        modules = Defaults.get_grub_basic_modules(multiboot)
752        if Defaults.is_ppc64_arch(Defaults.get_platform_name()):
753            return Defaults.get_grub_ofw_modules()
754        else:
755            modules += [
756                'part_gpt',
757                'part_msdos',
758                'biosdisk',
759                'vga',
760                'vbe',
761                'chain',
762                'boot'
763            ]
764        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():
766    @staticmethod
767    def get_grub_ofw_modules():
768        """
769        Provides list of grub ofw modules (ppc)
770
771        :return: list of module names
772
773        :rtype: list
774        """
775        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
776            'part_gpt',
777            'part_msdos',
778            'boot'
779        ]
780        return modules

Provides list of grub ofw modules (ppc)

Returns

list of module names

@staticmethod
def get_grub_s390_modules():
782    @staticmethod
783    def get_grub_s390_modules():
784        """
785        Provides list of grub ofw modules (s390)
786
787        :return: list of module names
788
789        :rtype: list
790        """
791        modules = Defaults.get_grub_basic_modules(multiboot=False) + [
792            'part_gpt',
793            'part_msdos',
794            'boot'
795        ]
796        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:
798    @staticmethod
799    def get_grub_path(
800        root_path: str, filename: str, raise_on_error: bool = True
801    ) -> str:
802        """
803        Provides grub path to given search file
804
805        Depending on the distribution grub could be installed below
806        a grub2 or grub directory. grub could also reside in /usr/lib
807        as well as in /usr/share. Therefore this information needs
808        to be dynamically looked up
809
810        :param string root_path: root path to start the lookup from
811        :param string filename: filename to search
812        :param bool raise_on_error: raise on not found, defaults to True
813
814        The method returns the path to the given grub search file.
815        By default it raises a KiwiBootLoaderGrubDataError exception
816        if the file could not be found in any of the search locations.
817        If raise_on_error is set to False and no file could be found
818        the function returns None
819
820        :return: filepath
821
822        :rtype: str
823        """
824        log.debug(f'Searching grub file: {filename}')
825        install_dirs = [
826            'usr/share', 'usr/lib'
827        ]
828        lookup_list = []
829        for grub_name in ['grub2', 'grub']:
830            for install_dir in install_dirs:
831                grub_path = os.path.join(
832                    root_path, install_dir, grub_name, filename
833                )
834                log.debug(f'--> {grub_path}')
835                if os.path.exists(grub_path):
836                    log.debug(f'--> Found in: {grub_path}')
837                    return grub_path
838                lookup_list.append(grub_path)
839        if raise_on_error:
840            raise KiwiBootLoaderGrubDataError(
841                'grub path {0} not found in {1}'.format(filename, lookup_list)
842            )
843        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():
845    @staticmethod
846    def get_preparer():
847        """
848        Provides ISO preparer name
849
850        :return: name
851
852        :rtype: str
853        """
854        return 'KIWI - https://github.com/OSInside/kiwi'

Provides ISO preparer name

Returns

name

@staticmethod
def get_publisher():
856    @staticmethod
857    def get_publisher():
858        """
859        Provides ISO publisher name
860
861        :return: name
862
863        :rtype: str
864        """
865        return 'SUSE LINUX GmbH'

Provides ISO publisher name

Returns

name

@staticmethod
def get_shim_loader(root_path: str) -> List[shim_loader_type]:
867    @staticmethod
868    def get_shim_loader(root_path: str) -> List[shim_loader_type]:
869        """
870        Provides shim loader file path
871
872        Searches distribution specific locations to find shim.efi
873        below the given root path
874
875        :param string root_path: image root path
876
877        :return: list of shim_loader_type
878
879        :rtype: list
880        """
881        result = []
882        shim_pattern_type = namedtuple(
883            'shim_pattern_type', ['pattern', 'binaryname']
884        )
885        shim_file_patterns = [
886            shim_pattern_type(
887                '/usr/lib/shim/shim*.efi.signed.latest',
888                'bootx64.efi'
889            ),
890            shim_pattern_type(
891                '/usr/lib/shim/shim*.efi.signed',
892                'bootx64.efi'
893            ),
894            shim_pattern_type(
895                '/usr/lib/grub/*-efi-signed',
896                'bootx64.efi'
897            ),
898            shim_pattern_type(
899                '/usr/share/efi/x86_64/shim.efi',
900                'bootx64.efi'
901            ),
902            shim_pattern_type(
903                '/usr/share/efi/aarch64/shim.efi',
904                'bootaa64.efi'
905            ),
906            shim_pattern_type(
907                '/usr/lib64/efi/shim.efi',
908                'bootx64.efi'
909            ),
910            shim_pattern_type(
911                '/boot/efi/EFI/*/shimx64.efi',
912                'bootx64.efi'
913            ),
914            shim_pattern_type(
915                '/boot/efi/EFI/*/shimia32.efi',
916                'bootia32.efi'
917            ),
918            shim_pattern_type(
919                '/boot/efi/EFI/*/shimaa64.efi',
920                'bootaa64.efi'
921            ),
922            shim_pattern_type(
923                '/boot/efi/EFI/*/shimriscv64.efi',
924                'bootriscv64.efi'
925            ),
926            shim_pattern_type(
927                '/boot/efi/EFI/*/shim.efi',
928                'bootx64.efi'
929            ),
930            shim_pattern_type(
931                '/usr/lib/shim/shim*.efi',
932                'bootx64.efi'
933            )
934        ]
935        for shim_file_pattern in shim_file_patterns:
936            for shim_file in sorted(
937                glob.iglob(root_path + shim_file_pattern.pattern), key=len
938            ):
939                result.append(
940                    shim_loader_type(shim_file, shim_file_pattern.binaryname)
941                )
942                # one match only expected, per pattern
943                break
944        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]:
946    @staticmethod
947    def get_mok_manager(root_path: str) -> List[str]:
948        """
949        Provides Mok Manager file path
950
951        Searches distribution specific locations to find
952        the Mok Manager EFI binary
953
954        :param str root_path: image root path
955
956        :return: file path or None
957
958        :rtype: str
959        """
960        result = []
961        mok_manager_file_patterns = [
962            '/usr/share/efi/*/MokManager.efi',
963            '/usr/lib64/efi/MokManager.efi',
964            '/boot/efi/EFI/*/mm*.efi',
965            '/usr/lib/shim/mm*.efi'
966        ]
967        for mok_manager_file_pattern in mok_manager_file_patterns:
968            for mm_file in glob.iglob(root_path + mok_manager_file_pattern):
969                result.append(mm_file)
970        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):
972    @staticmethod
973    def get_grub_efi_font_directory(root_path):
974        """
975        Provides distribution specific EFI font directory used with grub.
976
977        :param string root_path: image root path
978
979        :return: file path or None
980
981        :rtype: str
982        """
983        font_dir_patterns = [
984            '/boot/efi/EFI/*/fonts'
985        ]
986        for font_dir_pattern in font_dir_patterns:
987            for font_dir in glob.iglob(root_path + font_dir_pattern):
988                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]:
 990    @staticmethod
 991    def get_unsigned_grub_loader(
 992        root_path: str, target_type: str = 'disk'
 993    ) -> List[grub_loader_type]:
 994        """
 995        Provides unsigned grub efi loader file path
 996
 997        Searches distribution specific locations to find a distro
 998        grub EFI binary within the given root path
 999
1000        :param string root_path: image root path
1001
1002        :return: list of grub_loader_type
1003
1004        :rtype: list
1005        """
1006        result = []
1007        grub_pattern_type = namedtuple(
1008            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1009        )
1010        unsigned_grub_file_patterns = {
1011            'disk': [
1012                grub_pattern_type(
1013                    '/usr/share/grub*/x86_64-efi/grub.efi',
1014                    'grub.efi',
1015                    'bootx64.efi'
1016                ),
1017                grub_pattern_type(
1018                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1019                    'grub.efi',
1020                    'bootx64.efi'
1021                ),
1022                grub_pattern_type(
1023                    '/boot/efi/EFI/*/grubx64.efi',
1024                    'grubx64.efi',
1025                    'bootx64.efi'
1026                ),
1027                grub_pattern_type(
1028                    '/boot/efi/EFI/*/grubia32.efi',
1029                    'grubia32.efi',
1030                    'bootia32.efi'
1031                ),
1032                grub_pattern_type(
1033                    '/boot/efi/EFI/*/grubaa64.efi',
1034                    'grubaa64.efi',
1035                    'bootaa64.efi'
1036                ),
1037                grub_pattern_type(
1038                    '/boot/efi/EFI/*/grubriscv64.efi',
1039                    'grubriscv64.efi',
1040                    'bootriscv64.efi'
1041                )
1042            ],
1043            'iso': [
1044                grub_pattern_type(
1045                    '/boot/efi/EFI/*/gcdx64.efi',
1046                    'grubx64.efi',
1047                    'bootx64.efi'
1048                ),
1049                grub_pattern_type(
1050                    '/usr/share/grub*/x86_64-efi/grub.efi',
1051                    'grub.efi',
1052                    'bootx64.efi'
1053                ),
1054                grub_pattern_type(
1055                    '/usr/lib/grub*/x86_64-efi/grub.efi',
1056                    'grub.efi',
1057                    'bootx64.efi'
1058                ),
1059                grub_pattern_type(
1060                    '/boot/efi/EFI/*/grubx64.efi',
1061                    'grubx64.efi',
1062                    'bootx64.efi'
1063                ),
1064                grub_pattern_type(
1065                    '/boot/efi/EFI/*/grubia32.efi',
1066                    'grubia32.efi',
1067                    'bootia32.efi'
1068                ),
1069                grub_pattern_type(
1070                    '/boot/efi/EFI/*/grubaa64.efi',
1071                    'grubaa64.efi',
1072                    'bootaa64.efi'
1073                ),
1074                grub_pattern_type(
1075                    '/boot/efi/EFI/*/grubriscv64.efi',
1076                    'grubriscv64.efi',
1077                    'bootriscv64.efi'
1078                )
1079            ]
1080        }
1081        for unsigned_grub_file_pattern in unsigned_grub_file_patterns[target_type]:
1082            for unsigned_grub_file in glob.iglob(
1083                root_path + unsigned_grub_file_pattern.pattern
1084            ):
1085                result.append(
1086                    grub_loader_type(
1087                        unsigned_grub_file,
1088                        unsigned_grub_file_pattern.binaryname,
1089                        unsigned_grub_file_pattern.targetname
1090                    )
1091                )
1092                # one match only expected, per pattern
1093                break
1094        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:
1096    @staticmethod
1097    def get_grub_chrp_loader(boot_path: str) -> str:
1098        """
1099        Lookup CHRP boot loader (ppc)
1100
1101        :param string boot_path: boot path
1102
1103        :return: file base name
1104
1105        :rtype: str
1106        """
1107        for chrp_loader in ['grub.elf', 'core.elf']:
1108            for grub_chrp in glob.iglob(
1109                os.sep.join(
1110                    [boot_path, 'boot/grub*/powerpc-ieee1275', chrp_loader]
1111                )
1112            ):
1113                log.info(f'Found CHRP loader at: {grub_chrp}')
1114                return os.path.basename(grub_chrp)
1115        raise KiwiBootLoaderGrubDataError(
1116            f'CHRP loader not found in {boot_path}'
1117        )

Lookup CHRP boot loader (ppc)

Parameters
  • string boot_path: boot path
Returns

file base name

@staticmethod
def get_grub_platform_core_loader(root_path):
1119    @staticmethod
1120    def get_grub_platform_core_loader(root_path):
1121        """
1122        Provides grub bios image
1123
1124        Searches distribution specific locations to find the
1125        core bios image below the given root path
1126
1127        :param string root_path: image root path
1128
1129        :return: file path or None
1130
1131        :rtype: str
1132        """
1133        bios_grub_core_patterns = [
1134            '/usr/share/grub*/{0}/{1}'.format(
1135                Defaults.get_grub_platform_module_directory_name(),
1136                Defaults.get_grub_platform_image_name()
1137            ),
1138            '/usr/lib/grub*/{0}/{1}'.format(
1139                Defaults.get_grub_platform_module_directory_name(),
1140                Defaults.get_grub_platform_image_name()
1141            )
1142        ]
1143        for bios_grub_core_pattern in bios_grub_core_patterns:
1144            for bios_grub_core in glob.iglob(
1145                root_path + bios_grub_core_pattern
1146            ):
1147                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():
1149    @staticmethod
1150    def get_iso_grub_loader():
1151        """
1152        Return name of eltorito grub image used as ISO loader
1153
1154        :return: file base name
1155
1156        :rtype: str
1157        """
1158        return 'eltorito.img'

Return name of eltorito grub image used as ISO loader

Returns

file base name

@staticmethod
def get_iso_grub_mbr():
1160    @staticmethod
1161    def get_iso_grub_mbr():
1162        """
1163        Return name of hybrid MBR image used as ISO boot record
1164
1165        :return: file base name
1166
1167        :rtype: str
1168        """
1169        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]:
1171    @staticmethod
1172    def get_signed_grub_loader(
1173        root_path: str, target_type: str = 'disk'
1174    ) -> List[grub_loader_type]:
1175        """
1176        Provides shim signed grub loader file path
1177
1178        Searches distribution specific locations to find a grub
1179        EFI binary within the given root path
1180
1181        :param str root_path: image root path
1182
1183        :return: list of grub_loader_type
1184
1185        :rtype: list
1186        """
1187        result = []
1188        grub_pattern_type = namedtuple(
1189            'grub_pattern_type', ['pattern', 'binaryname', 'targetname']
1190        )
1191        signed_grub_file_patterns = {
1192            'disk': [
1193                grub_pattern_type(
1194                    '/usr/share/efi/*/grub.efi',
1195                    'grub.efi',
1196                    'bootx64.efi'
1197                ),
1198                grub_pattern_type(
1199                    '/usr/lib64/efi/grub.efi',
1200                    'grub.efi',
1201                    'bootx64.efi'
1202                ),
1203                grub_pattern_type(
1204                    '/boot/efi/EFI/*/grubx64.efi',
1205                    'grubx64.efi',
1206                    'bootx64.efi'
1207                ),
1208                grub_pattern_type(
1209                    '/boot/efi/EFI/*/grubia32.efi',
1210                    'grubia32.efi',
1211                    'bootia32.efi'
1212                ),
1213                grub_pattern_type(
1214                    '/boot/efi/EFI/*/grubaa64.efi',
1215                    'grubaa64.efi',
1216                    'bootaa64.efi'
1217                ),
1218                grub_pattern_type(
1219                    '/boot/efi/EFI/*/grubriscv64.efi',
1220                    'grubriscv64.efi',
1221                    'bootriscv64.efi'
1222                ),
1223                grub_pattern_type(
1224                    '/usr/share/grub*/*-efi/grub.efi',
1225                    'grub.efi',
1226                    'bootx64.efi'
1227                ),
1228                grub_pattern_type(
1229                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1230                    'grubx64.efi',
1231                    'bootx64.efi'
1232                )
1233            ],
1234            'iso': [
1235                grub_pattern_type(
1236                    '/boot/efi/EFI/*/gcdx64.efi',
1237                    'grubx64.efi',
1238                    'bootx64.efi'
1239                ),
1240                grub_pattern_type(
1241                    '/boot/efi/EFI/*/gcdaa64.efi',
1242                    'grubaa64.efi',
1243                    'bootaa64.efi'
1244                ),
1245                grub_pattern_type(
1246                    '/usr/share/efi/x86_64/grub.efi',
1247                    'grub.efi',
1248                    'grubx64.efi'
1249                ),
1250                grub_pattern_type(
1251                    '/usr/share/efi/aarch64/grub.efi',
1252                    'grub.efi',
1253                    'grubaa64.efi'
1254                ),
1255                grub_pattern_type(
1256                    '/usr/lib64/efi/grub.efi',
1257                    'grub.efi',
1258                    'bootx64.efi'
1259                ),
1260                grub_pattern_type(
1261                    '/boot/efi/EFI/*/grubx64.efi',
1262                    'grubx64.efi',
1263                    'bootx64.efi'
1264                ),
1265                grub_pattern_type(
1266                    '/boot/efi/EFI/*/grubia32.efi',
1267                    'grubia32.efi',
1268                    'bootia32.efi'
1269                ),
1270                grub_pattern_type(
1271                    '/boot/efi/EFI/*/grubaa64.efi',
1272                    'grubaa64.efi',
1273                    'bootaa64.efi'
1274                ),
1275                grub_pattern_type(
1276                    '/boot/efi/EFI/*/grubriscv64.efi',
1277                    'grubriscv64.efi',
1278                    'bootriscv64.efi'
1279                ),
1280                grub_pattern_type(
1281                    '/usr/share/grub*/x86_64-efi/grub.efi',
1282                    'grub.efi',
1283                    'bootx64.efi'
1284                ),
1285                grub_pattern_type(
1286                    '/usr/lib/grub/x86_64-efi-signed/grubx64.efi.signed',
1287                    'grubx64.efi',
1288                    'bootx64.efi'
1289                )
1290            ]
1291        }
1292        for signed_grub in signed_grub_file_patterns[target_type]:
1293            for signed_grub_file in glob.iglob(root_path + signed_grub.pattern):
1294                result.append(
1295                    grub_loader_type(
1296                        signed_grub_file,
1297                        signed_grub.binaryname,
1298                        signed_grub.targetname
1299                    )
1300                )
1301                # one match only expected, per pattern
1302                break
1303        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):
1305    @staticmethod
1306    def get_efi_vendor_directory(efi_path):
1307        """
1308        Provides EFI vendor directory if present
1309
1310        Looks up distribution specific EFI vendor directory
1311
1312        :param string root_path: path to efi mountpoint
1313
1314        :return: directory path or None
1315
1316        :rtype: str
1317        """
1318        efi_vendor_directories = [
1319            'EFI/fedora',
1320            'EFI/redhat',
1321            'EFI/centos',
1322            'EFI/almalinux',
1323            'EFI/opensuse',
1324            'EFI/ubuntu',
1325            'EFI/debian'
1326        ]
1327        for efi_vendor_directory in efi_vendor_directories:
1328            efi_vendor_directory = os.sep.join([efi_path, efi_vendor_directory])
1329            if os.path.exists(efi_vendor_directory):
1330                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):
1332    @staticmethod
1333    def get_vendor_grubenv(efi_path):
1334        efi_vendor_directory = Defaults.get_efi_vendor_directory(efi_path)
1335        if efi_vendor_directory:
1336            grubenv = os.sep.join([efi_vendor_directory, 'grubenv'])
1337            if os.path.exists(grubenv):
1338                return grubenv
@staticmethod
def get_shim_vendor_directory(root_path):
1340    @staticmethod
1341    def get_shim_vendor_directory(root_path):
1342        """
1343        Provides shim vendor directory
1344
1345        Searches distribution specific locations to find shim.efi
1346        below the given root path and return the directory name
1347        to the file found
1348
1349        :param string root_path: image root path
1350
1351        :return: directory path or None
1352
1353        :rtype: str
1354        """
1355        shim_vendor_patterns = [
1356            '/boot/efi/EFI/*/shim*.efi',
1357            '/EFI/*/shim*.efi'
1358        ]
1359        for shim_vendor_pattern in shim_vendor_patterns:
1360            for shim_file in glob.iglob(root_path + shim_vendor_pattern):
1361                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():
1363    @staticmethod
1364    def get_default_volume_group_name():
1365        """
1366        Provides default LVM volume group name
1367
1368        :return: name
1369
1370        :rtype: str
1371        """
1372        return 'systemVG'

Provides default LVM volume group name

Returns

name

@staticmethod
def get_min_partition_mbytes():
1374    @staticmethod
1375    def get_min_partition_mbytes():
1376        """
1377        Provides default minimum partition size in mbytes
1378
1379        :return: mbsize value
1380
1381        :rtype: int
1382        """
1383        return 10

Provides default minimum partition size in mbytes

Returns

mbsize value

@staticmethod
def get_min_volume_mbytes(filesystem: str):
1385    @staticmethod
1386    def get_min_volume_mbytes(filesystem: str):
1387        """
1388        Provides default minimum LVM volume size in mbytes
1389        per filesystem
1390
1391        :return: mbsize value
1392
1393        :rtype: int
1394        """
1395        if filesystem == 'btrfs':
1396            return 120
1397        elif filesystem == 'xfs':
1398            return 300
1399        else:
1400            return 30

Provides default minimum LVM volume size in mbytes per filesystem

Returns

mbsize value

@staticmethod
def get_lvm_overhead_mbytes():
1402    @staticmethod
1403    def get_lvm_overhead_mbytes():
1404        """
1405        Provides empiric LVM overhead size in mbytes
1406
1407        :return: mbsize value
1408
1409        :rtype: int
1410        """
1411        return 80

Provides empiric LVM overhead size in mbytes

Returns

mbsize value

@staticmethod
def get_default_boot_mbytes():
1413    @staticmethod
1414    def get_default_boot_mbytes():
1415        """
1416        Provides default boot partition size in mbytes
1417
1418        :return: mbsize value
1419
1420        :rtype: int
1421        """
1422        return 300

Provides default boot partition size in mbytes

Returns

mbsize value

@staticmethod
def get_default_efi_boot_mbytes():
1424    @staticmethod
1425    def get_default_efi_boot_mbytes():
1426        """
1427        Provides default EFI partition size in mbytes
1428
1429        :return: mbsize value
1430
1431        :rtype: int
1432        """
1433        return 20

Provides default EFI partition size in mbytes

Returns

mbsize value

@staticmethod
def get_recovery_spare_mbytes():
1435    @staticmethod
1436    def get_recovery_spare_mbytes():
1437        """
1438        Provides spare size of recovery partition in mbytes
1439
1440        :return: mbsize value
1441
1442        :rtype: int
1443        """
1444        return 300

Provides spare size of recovery partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_legacy_bios_mbytes():
1446    @staticmethod
1447    def get_default_legacy_bios_mbytes():
1448        """
1449        Provides default size of bios_grub partition in mbytes
1450
1451        :return: mbsize value
1452
1453        :rtype: int
1454        """
1455        return 2

Provides default size of bios_grub partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_prep_mbytes():
1457    @staticmethod
1458    def get_default_prep_mbytes():
1459        """
1460        Provides default size of prep partition in mbytes
1461
1462        :return: mbsize value
1463
1464        :rtype: int
1465        """
1466        return 8

Provides default size of prep partition in mbytes

Returns

mbsize value

@staticmethod
def get_disk_format_types():
1468    @staticmethod
1469    def get_disk_format_types():
1470        """
1471        Provides supported disk format types
1472
1473        :return: disk types
1474
1475        :rtype: list
1476        """
1477        return [
1478            'gce',
1479            'qcow2',
1480            'vmdk',
1481            'ova',
1482            'meta',
1483            'vmx',
1484            'vhd',
1485            'vhdx',
1486            'vhdfixed',
1487            'vdi',
1488            'vagrant.libvirt.box',
1489            'vagrant.virtualbox.box',
1490            'oci'
1491        ]

Provides supported disk format types

Returns

disk types

@staticmethod
def get_vagrant_config_virtualbox_guest_additions():
1493    @staticmethod
1494    def get_vagrant_config_virtualbox_guest_additions():
1495        """
1496        Provides the default value for
1497        ``vagrantconfig.virtualbox_guest_additions_present``
1498
1499        :return: whether guest additions are expected to be present in the
1500            vagrant box
1501
1502        :rtype: bool
1503        """
1504        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():
1506    @staticmethod
1507    def get_firmware_types():
1508        """
1509        Provides supported architecture specific firmware types
1510
1511        :return: firmware types per architecture
1512
1513        :rtype: dict
1514        """
1515        return {
1516            'x86_64': ['efi', 'uefi', 'bios', 'ec2'],
1517            'i586': ['bios'],
1518            'i686': ['bios'],
1519            'ix86': ['bios'],
1520            'aarch64': ['efi', 'uefi'],
1521            'arm64': ['efi', 'uefi'],
1522            'armv5el': ['efi', 'uefi'],
1523            'armv5tel': ['efi', 'uefi'],
1524            'armv6hl': ['efi', 'uefi'],
1525            'armv6l': ['efi', 'uefi'],
1526            'armv7hl': ['efi', 'uefi'],
1527            'armv7l': ['efi', 'uefi'],
1528            'armv8l': ['efi', 'uefi'],
1529            'loongarch64': ['efi', 'uefi'],
1530            'ppc': ['ofw'],
1531            'ppc64': ['ofw', 'opal'],
1532            'ppc64le': ['ofw', 'opal'],
1533            'riscv64': ['efi', 'uefi'],
1534            's390': [],
1535            's390x': []
1536        }

Provides supported architecture specific firmware types

Returns

firmware types per architecture

@staticmethod
def get_default_firmware(arch):
1538    @staticmethod
1539    def get_default_firmware(arch):
1540        """
1541        Provides default firmware for specified architecture
1542
1543        :param string arch: machine architecture name
1544
1545        :return: firmware name
1546
1547        :rtype: str
1548        """
1549        default_firmware = {
1550            'x86_64': 'bios',
1551            'i586': 'bios',
1552            'i686': 'bios',
1553            'ix86': 'bios',
1554            'loongarch64': 'efi',
1555            'ppc': 'ofw',
1556            'ppc64': 'ofw',
1557            'ppc64le': 'ofw',
1558            'arm64': 'efi',
1559            'aarch64': 'efi',
1560            'armv5el': 'efi',
1561            'armv5tel': 'efi',
1562            'armv6hl': 'efi',
1563            'armv6l': 'efi',
1564            'armv7hl': 'efi',
1565            'armv7l': 'efi',
1566            'armv8l': 'efi',
1567            'riscv64': 'efi'
1568        }
1569        if arch in default_firmware:
1570            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():
1572    @staticmethod
1573    def get_efi_capable_firmware_names():
1574        """
1575        Provides list of EFI capable firmware names. These are
1576        those for which kiwi supports the creation of an EFI
1577        bootable disk image
1578
1579        :return: firmware names
1580
1581        :rtype: list
1582        """
1583        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():
1585    @staticmethod
1586    def get_ec2_capable_firmware_names():
1587        """
1588        Provides list of EC2 capable firmware names. These are
1589        those for which kiwi supports the creation of disk images
1590        bootable within the Amazon EC2 public cloud
1591
1592        :return: firmware names
1593
1594        :rtype: list
1595        """
1596        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):
1598    @staticmethod
1599    def get_efi_module_directory_name(arch):
1600        """
1601        Provides architecture specific EFI directory name which
1602        stores the EFI binaries for the desired architecture.
1603
1604        :param string arch: machine architecture name
1605
1606        :return: directory name
1607
1608        :rtype: str
1609        """
1610        default_module_directory_names = {
1611            'x86_64': 'x86_64-efi',
1612            'i386': 'i386-efi',
1613
1614            # There is no dedicated xen architecture but there are
1615            # modules provided for xen. Thus we treat it as an
1616            # architecture
1617            'x86_64_xen': 'x86_64-xen',
1618
1619            'aarch64': 'arm64-efi',
1620            'arm64': 'arm64-efi',
1621            'armv5el': 'arm-efi',
1622            'armv5tel': 'arm-efi',
1623            'armv6l': 'arm-efi',
1624            'armv7l': 'arm-efi',
1625            'armv8l': 'arm-efi',
1626            'loongarch64': 'loongarch64-efi',
1627            'riscv64': 'riscv64-efi'
1628        }
1629        if arch in default_module_directory_names:
1630            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():
1632    @staticmethod
1633    def get_grub_platform_module_directory_name():
1634        """
1635        Provides grub platform specific directory name which
1636        stores the grub module binaries
1637
1638        :return: directory name
1639
1640        :rtype: str
1641        """
1642        return 'powerpc-ieee1275' if Defaults.is_ppc64_arch(
1643            Defaults.get_platform_name()
1644        ) 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):
1646    @staticmethod
1647    def get_efi_image_name(arch):
1648        """
1649        Provides architecture specific EFI boot binary name
1650
1651        :param string arch: machine architecture name
1652
1653        :return: name
1654
1655        :rtype: str
1656        """
1657        default_efi_image_names = {
1658            'x86_64': 'bootx64.efi',
1659            'i386': 'bootia32.efi',
1660            'aarch64': 'bootaa64.efi',
1661            'arm64': 'bootaa64.efi',
1662            'armv5el': 'bootarm.efi',
1663            'armv5tel': 'bootarm.efi',
1664            'armv6l': 'bootarm.efi',
1665            'armv7l': 'bootarm.efi',
1666            'armv8l': 'bootarm.efi',
1667            'loongarch64': 'bootloongarch64.efi',
1668            'riscv64': 'bootriscv64.efi'
1669        }
1670        if arch in default_efi_image_names:
1671            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():
1673    @staticmethod
1674    def get_grub_platform_image_name():
1675        """
1676        Provides platform specific core boot binary name
1677
1678        :return: name
1679
1680        :rtype: str
1681        """
1682        return 'grub.elf' if Defaults.is_ppc64_arch(
1683            Defaults.get_platform_name()
1684        ) else 'core.img'

Provides platform specific core boot binary name

Returns

name

@staticmethod
def get_default_boot_timeout_seconds():
1686    @staticmethod
1687    def get_default_boot_timeout_seconds():
1688        """
1689        Provides default boot timeout in seconds
1690
1691        :return: seconds
1692
1693        :rtype: int
1694        """
1695        return 10

Provides default boot timeout in seconds

Returns

seconds

@staticmethod
def get_default_disk_start_sector():
1697    @staticmethod
1698    def get_default_disk_start_sector():
1699        """
1700        Provides the default initial disk sector for the first disk
1701        partition.
1702
1703        :return: sector value
1704
1705        :rtype: int
1706        """
1707        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():
1709    @staticmethod
1710    def get_default_efi_partition_table_type():
1711        """
1712        Provides the default partition table type for efi firmwares.
1713
1714        :return: partition table type name
1715
1716        :rtype: str
1717        """
1718        return 'gpt'

Provides the default partition table type for efi firmwares.

Returns

partition table type name

@staticmethod
def get_default_inode_size():
1720    @staticmethod
1721    def get_default_inode_size():
1722        """
1723        Provides default size of inodes in bytes. This is only
1724        relevant for inode based filesystems
1725
1726        :return: bytesize value
1727
1728        :rtype: int
1729        """
1730        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():
1732    @staticmethod
1733    def get_archive_image_types():
1734        """
1735        Provides list of supported archive image types
1736
1737        :return: archive names
1738
1739        :rtype: list
1740        """
1741        return ['tbz', 'cpio']

Provides list of supported archive image types

Returns

archive names

@staticmethod
def get_container_image_types():
1743    @staticmethod
1744    def get_container_image_types():
1745        """
1746        Provides list of supported container image types
1747
1748        :return: container names
1749
1750        :rtype: list
1751        """
1752        return ['docker', 'oci', 'appx', 'wsl']

Provides list of supported container image types

Returns

container names

@staticmethod
def get_filesystem_image_types():
1754    @staticmethod
1755    def get_filesystem_image_types():
1756        """
1757        Provides list of supported filesystem image types
1758
1759        :return: filesystem names
1760
1761        :rtype: list
1762        """
1763        return [
1764            'ext2', 'ext3', 'ext4', 'btrfs', 'squashfs',
1765            'xfs', 'fat16', 'fat32', 'erofs'
1766        ]

Provides list of supported filesystem image types

Returns

filesystem names

@staticmethod
def get_default_live_iso_type():
1768    @staticmethod
1769    def get_default_live_iso_type():
1770        """
1771        Provides default live iso union type
1772
1773        :return: live iso type
1774
1775        :rtype: str
1776        """
1777        return 'overlay'

Provides default live iso union type

Returns

live iso type

@staticmethod
def get_default_uri_type():
1779    @staticmethod
1780    def get_default_uri_type():
1781        """
1782        Provides default URI type
1783
1784        Absolute path specifications used in the context of an URI
1785        will apply the specified default mime type
1786
1787        :return: URI mime type
1788
1789        :rtype: str
1790        """
1791        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():
1793    @staticmethod
1794    def get_dracut_conf_name():
1795        """
1796        Provides file path of dracut config file to be used with KIWI
1797
1798        :return: file path name
1799
1800        :rtype: str
1801        """
1802        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):
1804    @staticmethod
1805    def get_live_dracut_modules_from_flag(flag_name):
1806        """
1807        Provides flag_name to dracut modules name map
1808
1809        Depending on the value of the flag attribute in the KIWI image
1810        description specific dracut modules need to be selected
1811
1812        :return: dracut module names as list
1813
1814        :rtype: list
1815        """
1816        live_modules = {
1817            'overlay': ['kiwi-live'],
1818            'dmsquash': ['dmsquash-live', 'livenet']
1819        }
1820        if flag_name in live_modules:
1821            return live_modules[flag_name]
1822        else:
1823            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():
1825    @staticmethod
1826    def get_default_live_iso_root_filesystem():
1827        """
1828        Provides default live iso root filesystem type
1829
1830        :return: filesystem name
1831
1832        :rtype: str
1833        """
1834        return 'ext4'

Provides default live iso root filesystem type

Returns

filesystem name

@staticmethod
def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1836    @staticmethod
1837    def get_live_iso_persistent_boot_options(persistent_filesystem=None):
1838        """
1839        Provides list of boot options passed to the dracut
1840        kiwi-live module to setup persistent writing
1841
1842        :return: list of boot options
1843
1844        :rtype: list
1845        """
1846        live_iso_persistent_boot_options = [
1847            'rd.live.overlay.persistent'
1848        ]
1849        if persistent_filesystem:
1850            live_iso_persistent_boot_options.append(
1851                'rd.live.overlay.cowfs={0}'.format(persistent_filesystem)
1852            )
1853        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():
1855    @staticmethod
1856    def get_disk_image_types():
1857        """
1858        Provides supported disk image types
1859
1860        :return: disk image type names
1861
1862        :rtype: list
1863        """
1864        return ['oem']

Provides supported disk image types

Returns

disk image type names

@staticmethod
def get_live_image_types():
1866    @staticmethod
1867    def get_live_image_types():
1868        """
1869        Provides supported live image types
1870
1871        :return: live image type names
1872
1873        :rtype: list
1874        """
1875        return ['iso']

Provides supported live image types

Returns

live image type names

@staticmethod
def get_kis_image_types():
1877    @staticmethod
1878    def get_kis_image_types():
1879        """
1880        Provides supported kis image types
1881
1882        :return: kis image type names
1883
1884        :rtype: list
1885        """
1886        return ['kis', 'pxe']

Provides supported kis image types

Returns

kis image type names

@staticmethod
def get_enclaves_image_types():
1888    @staticmethod
1889    def get_enclaves_image_types():
1890        """
1891        Provides supported enclave(initrd-only) image types
1892
1893        :return: enclave image type names
1894
1895        :rtype: list
1896        """
1897        return ['enclave']

Provides supported enclave(initrd-only) image types

Returns

enclave image type names

@staticmethod
def get_boot_image_description_path():
1899    @staticmethod
1900    def get_boot_image_description_path():
1901        """
1902        Provides the path to find custom kiwi boot descriptions
1903
1904        :return: directory path
1905
1906        :rtype: str
1907        """
1908        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():
1910    @staticmethod
1911    def get_boot_image_strip_file():
1912        """
1913        Provides the file path to bootloader strip metadata.
1914        This file contains information about the files and directories
1915        automatically striped out from the kiwi initrd
1916
1917        :return: file path
1918
1919        :rtype: str
1920        """
1921        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():
1923    @staticmethod
1924    def get_schema_file():
1925        """
1926        Provides file path to kiwi RelaxNG schema
1927
1928        :return: file path
1929
1930        :rtype: str
1931        """
1932        return Defaults.project_file('schema/kiwi.rng')

Provides file path to kiwi RelaxNG schema

Returns

file path

@staticmethod
def get_common_functions_file():
1934    @staticmethod
1935    def get_common_functions_file():
1936        """
1937        Provides the file path to config functions metadata.
1938
1939        This file contains bash functions used for system
1940        configuration or in the boot code from the kiwi initrd
1941
1942        :return: file path
1943
1944        :rtype: str
1945        """
1946        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():
1948    @staticmethod
1949    def get_xsl_stylesheet_file():
1950        """
1951        Provides the file path to the KIWI XSLT style sheets
1952
1953        :return: file path
1954
1955        :rtype: str
1956        """
1957        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():
1959    @staticmethod
1960    def get_schematron_module_name():
1961        """
1962        Provides module name for XML SchemaTron validations
1963
1964        :return: python module name
1965
1966        :rtype: str
1967        """
1968        return 'lxml.isoschematron'

Provides module name for XML SchemaTron validations

Returns

python module name

@staticmethod
def project_file(filename):
1970    @staticmethod
1971    def project_file(filename):
1972        """
1973        Provides the python module base directory search path
1974
1975        The method uses the importlib.resources.path method to identify
1976        files and directories from the application
1977
1978        :param string filename: relative project file
1979
1980        :return: absolute file path name
1981
1982        :rtype: str
1983        """
1984        with as_file(importlib.resources.files('kiwi')) as path:
1985            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):
1987    @staticmethod
1988    def get_imported_root_image(root_dir):
1989        """
1990        Provides the path to an imported root system image
1991
1992        If the image description specified a derived_from attribute
1993        the file from this attribute is copied into the root_dir
1994        using the name as provided by this method
1995
1996        :param string root_dir: image root directory
1997
1998        :return: file path name
1999
2000        :rtype: str
2001        """
2002        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():
2004    @staticmethod
2005    def get_iso_boot_path():
2006        """
2007        Provides arch specific relative path to boot files
2008        on kiwi iso filesystems
2009
2010        :return: relative path name
2011
2012        :rtype: str
2013        """
2014        return os.sep.join(
2015            ['boot', Defaults.get_platform_name()]
2016        )

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

Returns

relative path name

@staticmethod
def get_iso_tool_category():
2018    @staticmethod
2019    def get_iso_tool_category():
2020        """
2021        Provides default iso tool category
2022
2023        :return: name
2024
2025        :rtype: str
2026        """
2027        return 'xorriso'

Provides default iso tool category

Returns

name

@staticmethod
def get_iso_media_tag_tool():
2029    @staticmethod
2030    def get_iso_media_tag_tool():
2031        """
2032        Provides default iso media tag tool
2033
2034        :return: name
2035
2036        :rtype: str
2037        """
2038        return 'checkmedia'

Provides default iso media tag tool

Returns

name

@staticmethod
def get_container_compression():
2040    @staticmethod
2041    def get_container_compression():
2042        """
2043        Provides default container compression
2044
2045        :return: True
2046
2047        :rtype: bool
2048        """
2049        return True

Provides default container compression

Returns

True

@staticmethod
def get_default_container_name():
2051    @staticmethod
2052    def get_default_container_name():
2053        """
2054        Provides the default container name.
2055
2056        :return: name
2057
2058        :rtype: str
2059        """
2060        return 'kiwi-container'

Provides the default container name.

Returns

name

@staticmethod
def get_container_base_image_tag():
2062    @staticmethod
2063    def get_container_base_image_tag():
2064        """
2065        Provides the tag used to identify base layers during the build
2066        of derived images.
2067
2068        :return: tag
2069
2070        :rtype: str
2071        """
2072        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():
2074    @staticmethod
2075    def get_oci_archive_tool():
2076        """
2077        Provides the default OCI archive tool name.
2078
2079        :return: name
2080
2081        :rtype: str
2082        """
2083        return 'umoci'

Provides the default OCI archive tool name.

Returns

name

@staticmethod
def get_part_mapper_tool():
2085    @staticmethod
2086    def get_part_mapper_tool():
2087        """
2088        Provides the default partition mapper tool name.
2089
2090        :return: name
2091
2092        :rtype: str
2093        """
2094        host_architecture = Defaults.get_platform_name()
2095        if 's390' in host_architecture:
2096            return 'kpartx'
2097        return 'partx'

Provides the default partition mapper tool name.

Returns

name

@staticmethod
def get_default_container_tag():
2099    @staticmethod
2100    def get_default_container_tag():
2101        """
2102        Provides the default container tag.
2103
2104        :return: tag
2105
2106        :rtype: str
2107        """
2108        return 'latest'

Provides the default container tag.

Returns

tag

@staticmethod
def get_default_container_subcommand():
2110    @staticmethod
2111    def get_default_container_subcommand():
2112        """
2113        Provides the default container subcommand.
2114
2115        :return: command as a list of arguments
2116
2117        :rtype: list
2118        """
2119        return ['/bin/bash']

Provides the default container subcommand.

Returns

command as a list of arguments

@staticmethod
def get_default_container_created_by():
2121    @staticmethod
2122    def get_default_container_created_by():
2123        """
2124        Provides the default 'created by' history entry for containers.
2125
2126        :return: the specific kiwi version used for the build
2127
2128        :rtype: str
2129        """
2130        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():
2132    @staticmethod
2133    def get_custom_rpm_macros_path():
2134        """
2135        Returns the custom macros directory for the rpm database.
2136
2137        :return: path name
2138
2139        :rtype: str
2140        """
2141        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():
2143    @staticmethod
2144    def get_custom_rpm_bootstrap_macro_name():
2145        """
2146        Returns the rpm bootstrap macro file name created
2147        in the custom rpm macros path
2148
2149        :return: filename
2150
2151        :rtype: str
2152        """
2153        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():
2155    @staticmethod
2156    def get_custom_rpm_image_macro_name():
2157        """
2158        Returns the rpm image macro file name created
2159        in the custom rpm macros path
2160
2161        :return: filename
2162
2163        :rtype: str
2164        """
2165        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:
2167    @staticmethod
2168    def get_default_package_manager() -> str:
2169        """
2170        Returns the default package manager name if none
2171        is configured in the image description
2172
2173        :return: package manager name
2174
2175        :rtype: str
2176        """
2177        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):
2179    @staticmethod
2180    def get_default_packager_tool(package_manager):
2181        """
2182        Provides the packager tool according to the package manager
2183
2184        :param string package_manager: package manger name
2185
2186        :return: packager tool binary name
2187
2188        :rtype: str
2189        """
2190        rpm_based = ['zypper', 'dnf4', 'dnf5', 'microdnf']
2191        deb_based = ['apt']
2192        if package_manager in rpm_based:
2193            return 'rpm'
2194        elif package_manager in deb_based:
2195            return 'dpkg'
2196        elif package_manager == 'pacman':
2197            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]:
2199    @staticmethod
2200    def get_discoverable_partition_ids() -> Dict[str, str]:
2201        """
2202        Provides arch specific partition UUIDs as defined
2203        by the UAPI group
2204
2205        :return: partition UUIDs
2206
2207        :rtype: dict
2208        """
2209        arch = Defaults.get_platform_name()
2210        part_uuids_archs = {
2211            'x86_64': {
2212                'root':
2213                    '4f68bce3e8cd4db196e7fbcaf984b709',
2214                'usr':
2215                    '8484680c952148c69c11b0720656f69e',
2216                'usr-verity':
2217                    '77ff5f63e7b64633acf41565b864c0e6'
2218            },
2219            'ix86': {
2220                'root':
2221                    '44479540f29741b29af7d131d5f0458a',
2222                'usr':
2223                    '75250d768cc6458ebd66bd47cc81a812',
2224                'usr-verity':
2225                    '8f461b0d14ee4e819aa9049b6fb97abd'
2226            },
2227            'aarch64': {
2228                'root':
2229                    'b921b0451df041c3af444c6f280d3fae',
2230                'usr':
2231                    'b0e01050ee5f4390949a9101b17104e9',
2232                'usr-verity':
2233                    '6e11a4e7fbca4dedb9e9e1a512bb664e'
2234            },
2235            'riscv64': {
2236                'root':
2237                    '72ec70a6cf7440e6bd494bda08e8f224',
2238                'usr':
2239                    'beaec34b8442439ba40b984381ed097d',
2240                'usr-verity':
2241                    '8f1056be9b0547c481d6be53128e5b54'
2242            }
2243        }
2244        part_uuids_arch = part_uuids_archs.get(arch) or {}
2245        return {
2246            'root':
2247                part_uuids_arch.get('root') or '',
2248            'usr':
2249                part_uuids_arch.get('usr') or '',
2250            'usr-verity':
2251                part_uuids_arch.get('usr-verity') or '',
2252            'usr-secondary':
2253                '75250d768cc6458ebd66bd47cc81a812',
2254            'usr-secondary-verity':
2255                '8f461b0d14ee4e819aa9049b6fb97abd',
2256            'esp':
2257                'c12a7328f81f11d2ba4b00a0c93ec93b',
2258            'xbootldr':
2259                'bc13c2ff59e64262a352b275fd6f7172',
2260            'swap':
2261                '0657fd6da4ab43c484e50933c84b4f4f',
2262            'home':
2263                '933ac7e12eb44f13b8440e14e2aef915',
2264            'srv':
2265                '3b8f842520e04f3b907f1a25a76f98e8',
2266            'var':
2267                '4d21b016b53445c2a9fb5c16e091fd2d',
2268            'tmp':
2269                '7ec6f5573bc54acab29316ef5df639d1',
2270            'user-home':
2271                '773f91ef66d449b5bd83d683bf40ad16',
2272            'linux-generic':
2273                '0fc63daf848347728e793d69d8477de4'
2274        }

Provides arch specific partition UUIDs as defined by the UAPI group

Returns

partition UUIDs

@staticmethod
def get_bls_loader_entries_dir() -> str:
2276    @staticmethod
2277    def get_bls_loader_entries_dir() -> str:
2278        """
2279        Provide default loader entries directory for BLS loaders
2280
2281        :return: directory name
2282
2283        :rtype: str
2284        """
2285        return '/boot/loader/entries'

Provide default loader entries directory for BLS loaders

Returns

directory name

@staticmethod
def get_apk_repo_config() -> str:
2287    @staticmethod
2288    def get_apk_repo_config() -> str:
2289        """
2290        Repository file for apk
2291
2292        :return: file path name
2293
2294        :rtype: str
2295        """
2296        return '/etc/apk/repositories'

Repository file for apk

Returns

file path name

@staticmethod
def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2298    @staticmethod
2299    def get_ca_update_map(target_distribution) -> Optional[Dict[str, str]]:
2300        return CA_UPDATE_MAP.get(target_distribution)
@staticmethod
def get_ca_target_distributions() -> List[str]:
2302    @staticmethod
2303    def get_ca_target_distributions() -> List[str]:
2304        return sorted(CA_UPDATE_MAP.keys())
def get(self, key):
2306    def get(self, key):
2307        """
2308        Implements get method for profile elements
2309
2310        :param string key: profile keyname
2311
2312        :return: key value
2313
2314        :rtype: str
2315        """
2316        if key in self.defaults:
2317            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):
2319    @staticmethod
2320    def get_profile_file(root_dir):
2321        """
2322        Return name of profile file for given root directory
2323        """
2324        return root_dir + '/.profile'

Return name of profile file for given root directory

def to_profile(self, profile):
2326    def to_profile(self, profile):
2327        """
2328        Implements method to add list of profile keys and their values
2329        to the specified instance of a Profile class
2330
2331        :param object profile: Profile instance
2332        """
2333        for key in sorted(self.profile_key_list):
2334            # Do not apply default values to any variable that was
2335            # already defined in the profile instance.
2336            cur_profile = profile.dot_profile
2337            if key not in cur_profile or cur_profile[key] is None:
2338                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