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

Provides list of shim vendor directories

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

Parameters
  • string root_path: image root path
Returns

list of directory names or empty list

@staticmethod
def get_default_volume_group_name():
1367    @staticmethod
1368    def get_default_volume_group_name():
1369        """
1370        Provides default LVM volume group name
1371
1372        :return: name
1373
1374        :rtype: str
1375        """
1376        return 'systemVG'

Provides default LVM volume group name

Returns

name

@staticmethod
def get_min_partition_mbytes():
1378    @staticmethod
1379    def get_min_partition_mbytes():
1380        """
1381        Provides default minimum partition size in mbytes
1382
1383        :return: mbsize value
1384
1385        :rtype: int
1386        """
1387        return 10

Provides default minimum partition size in mbytes

Returns

mbsize value

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

Provides default minimum LVM volume size in mbytes per filesystem

Returns

mbsize value

@staticmethod
def get_lvm_overhead_mbytes():
1406    @staticmethod
1407    def get_lvm_overhead_mbytes():
1408        """
1409        Provides empiric LVM overhead size in mbytes
1410
1411        :return: mbsize value
1412
1413        :rtype: int
1414        """
1415        return 80

Provides empiric LVM overhead size in mbytes

Returns

mbsize value

@staticmethod
def get_default_boot_mbytes():
1417    @staticmethod
1418    def get_default_boot_mbytes():
1419        """
1420        Provides default boot partition size in mbytes
1421
1422        :return: mbsize value
1423
1424        :rtype: int
1425        """
1426        return 300

Provides default boot partition size in mbytes

Returns

mbsize value

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

Provides default EFI partition size in mbytes

Returns

mbsize value

@staticmethod
def get_recovery_spare_mbytes():
1439    @staticmethod
1440    def get_recovery_spare_mbytes():
1441        """
1442        Provides spare size of recovery partition in mbytes
1443
1444        :return: mbsize value
1445
1446        :rtype: int
1447        """
1448        return 300

Provides spare size of recovery partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_legacy_bios_mbytes():
1450    @staticmethod
1451    def get_default_legacy_bios_mbytes():
1452        """
1453        Provides default size of bios_grub partition in mbytes
1454
1455        :return: mbsize value
1456
1457        :rtype: int
1458        """
1459        return 2

Provides default size of bios_grub partition in mbytes

Returns

mbsize value

@staticmethod
def get_default_prep_mbytes():
1461    @staticmethod
1462    def get_default_prep_mbytes():
1463        """
1464        Provides default size of prep partition in mbytes
1465
1466        :return: mbsize value
1467
1468        :rtype: int
1469        """
1470        return 8

Provides default size of prep partition in mbytes

Returns

mbsize value

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

Provides supported disk format types

Returns

disk types

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

Provides supported architecture specific firmware types

Returns

firmware types per architecture

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

Provides platform specific core boot binary name

Returns

name

@staticmethod
def get_default_boot_timeout_seconds():
1690    @staticmethod
1691    def get_default_boot_timeout_seconds():
1692        """
1693        Provides default boot timeout in seconds
1694
1695        :return: seconds
1696
1697        :rtype: int
1698        """
1699        return 10

Provides default boot timeout in seconds

Returns

seconds

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

Provides the default partition table type for efi firmwares.

Returns

partition table type name

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

Provides list of supported archive image types

Returns

archive names

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

Provides list of supported container image types

Returns

container names

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

Provides list of supported filesystem image types

Returns

filesystem names

@staticmethod
def get_default_live_iso_type():
1772    @staticmethod
1773    def get_default_live_iso_type():
1774        """
1775        Provides default live iso union type
1776
1777        :return: live iso type
1778
1779        :rtype: str
1780        """
1781        return 'overlay'

Provides default live iso union type

Returns

live iso type

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

Provides default live iso root filesystem type

Returns

filesystem name

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

Provides supported disk image types

Returns

disk image type names

@staticmethod
def get_live_image_types():
1870    @staticmethod
1871    def get_live_image_types():
1872        """
1873        Provides supported live image types
1874
1875        :return: live image type names
1876
1877        :rtype: list
1878        """
1879        return ['iso']

Provides supported live image types

Returns

live image type names

@staticmethod
def get_kis_image_types():
1881    @staticmethod
1882    def get_kis_image_types():
1883        """
1884        Provides supported kis image types
1885
1886        :return: kis image type names
1887
1888        :rtype: list
1889        """
1890        return ['kis', 'pxe']

Provides supported kis image types

Returns

kis image type names

@staticmethod
def get_enclaves_image_types():
1892    @staticmethod
1893    def get_enclaves_image_types():
1894        """
1895        Provides supported enclave(initrd-only) image types
1896
1897        :return: enclave image type names
1898
1899        :rtype: list
1900        """
1901        return ['enclave']

Provides supported enclave(initrd-only) image types

Returns

enclave image type names

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

Provides file path to kiwi RelaxNG schema

Returns

file path

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

Provides module name for XML SchemaTron validations

Returns

python module name

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

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

Returns

relative path name

@staticmethod
def get_iso_tool_category():
2022    @staticmethod
2023    def get_iso_tool_category():
2024        """
2025        Provides default iso tool category
2026
2027        :return: name
2028
2029        :rtype: str
2030        """
2031        return 'xorriso'

Provides default iso tool category

Returns

name

@staticmethod
def get_iso_media_tag_tool():
2033    @staticmethod
2034    def get_iso_media_tag_tool():
2035        """
2036        Provides default iso media tag tool
2037
2038        :return: name
2039
2040        :rtype: str
2041        """
2042        return 'checkmedia'

Provides default iso media tag tool

Returns

name

@staticmethod
def get_container_compression():
2044    @staticmethod
2045    def get_container_compression():
2046        """
2047        Provides default container compression
2048
2049        :return: True
2050
2051        :rtype: bool
2052        """
2053        return True

Provides default container compression

Returns

True

@staticmethod
def get_default_container_name():
2055    @staticmethod
2056    def get_default_container_name():
2057        """
2058        Provides the default container name.
2059
2060        :return: name
2061
2062        :rtype: str
2063        """
2064        return 'kiwi-container'

Provides the default container name.

Returns

name

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

Provides the default OCI archive tool name.

Returns

name

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

Provides the default partition mapper tool name.

Returns

name

@staticmethod
def get_default_container_tag():
2103    @staticmethod
2104    def get_default_container_tag():
2105        """
2106        Provides the default container tag.
2107
2108        :return: tag
2109
2110        :rtype: str
2111        """
2112        return 'latest'

Provides the default container tag.

Returns

tag

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

Provides the default container subcommand.

Returns

command as a list of arguments

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

Provides arch specific partition UUIDs as defined by the UAPI group

Returns

partition UUIDs

@staticmethod
def get_bls_loader_entries_dir() -> str:
2280    @staticmethod
2281    def get_bls_loader_entries_dir() -> str:
2282        """
2283        Provide default loader entries directory for BLS loaders
2284
2285        :return: directory name
2286
2287        :rtype: str
2288        """
2289        return '/boot/loader/entries'

Provide default loader entries directory for BLS loaders

Returns

directory name

@staticmethod
def get_apk_repo_config() -> str:
2291    @staticmethod
2292    def get_apk_repo_config() -> str:
2293        """
2294        Repository file for apk
2295
2296        :return: file path name
2297
2298        :rtype: str
2299        """
2300        return '/etc/apk/repositories'

Repository file for apk

Returns

file path name

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

Return name of profile file for given root directory

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