MCPcopy Index your code
hub / github.com/archlinux/archinstall / validate_bootloader_layout

Function validate_bootloader_layout

archinstall/lib/bootloader/utils.py:23–86  ·  view source on GitHub ↗

Validate bootloader configuration against disk layout. Returns a failure with a human-readable description if the configuration would produce an unbootable system, or None if it is valid.

(
	bootloader_config: BootloaderConfiguration | None,
	disk_config: DiskLayoutConfiguration | None,
)

Source from the content-addressed store, hash-verified

21
22
23def validate_bootloader_layout(
24 bootloader_config: BootloaderConfiguration | None,
25 disk_config: DiskLayoutConfiguration | None,
26) -> BootloaderValidationFailure | None:
27 """Validate bootloader configuration against disk layout.
28
29 Returns a failure with a human-readable description if the configuration
30 would produce an unbootable system, or None if it is valid.
31 """
32 if not (bootloader_config and disk_config):
33 return None
34
35 bootloader = bootloader_config.bootloader
36
37 if bootloader == Bootloader.NO_BOOTLOADER:
38 return None
39
40 if bootloader.is_uefi_only() and not SysInfo.has_uefi():
41 return BootloaderValidationFailure(
42 kind=BootloaderValidationFailureKind.BootloaderRequiresUefi,
43 description=f'{bootloader.value} requires a UEFI system.',
44 )
45
46 boot_part = next(
47 (p for m in disk_config.device_modifications if (p := m.get_boot_partition())),
48 None,
49 )
50
51 if bootloader == Bootloader.Efistub:
52 # The UEFI firmware reads the kernel directly from the boot partition,
53 # which must be FAT.
54 if boot_part and (boot_part.fs_type is None or not boot_part.fs_type.is_fat()):
55 return BootloaderValidationFailure(
56 kind=BootloaderValidationFailureKind.EfistubNonFatBoot,
57 description='Efistub does not support booting with a non-FAT boot partition.',
58 )
59
60 if bootloader == Bootloader.Limine:
61 # Limine reads its config and kernels from the boot partition, which
62 # must be FAT.
63 if boot_part and (boot_part.fs_type is None or not boot_part.fs_type.is_fat()):
64 return BootloaderValidationFailure(
65 kind=BootloaderValidationFailureKind.LimineNonFatBoot,
66 description='Limine does not support booting with a non-FAT boot partition.',
67 )
68
69 # When the ESP is the boot partition but mounted outside /boot and
70 # UKI is disabled, kernels end up on the root filesystem which
71 # Limine cannot access.
72 if not bootloader_config.uki:
73 efi_part = next(
74 (p for m in disk_config.device_modifications if (p := m.get_efi_partition())),
75 None,
76 )
77 if efi_part and efi_part == boot_part and efi_part.mountpoint != Path('/boot'):
78 return BootloaderValidationFailure(
79 kind=BootloaderValidationFailureKind.LimineLayout,
80 description=(

Callers 4

_validate_bootloaderMethod · 0.90
mainFunction · 0.90
mainFunction · 0.90

Calls 6

is_uefi_onlyMethod · 0.80
has_uefiMethod · 0.80
get_boot_partitionMethod · 0.80
is_fatMethod · 0.80
get_efi_partitionMethod · 0.80

Tested by

no test coverage detected