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