Skip to content

Commit d7f6b7f

Browse files
committed
Extract bootloader layout validation into lib/bootloader/utils
1 parent 71cd6d4 commit d7f6b7f

2 files changed

Lines changed: 41 additions & 31 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from pathlib import Path
2+
3+
from archinstall.lib.models.bootloader import Bootloader, BootloaderConfiguration
4+
from archinstall.lib.models.device import DiskLayoutConfiguration
5+
6+
7+
def validate_bootloader_layout(
8+
bootloader_config: BootloaderConfiguration | None,
9+
disk_config: DiskLayoutConfiguration | None,
10+
) -> str | None:
11+
"""Validate bootloader configuration against disk layout.
12+
13+
Returns an error message if the configuration would produce an
14+
unbootable system, or None if it is valid.
15+
"""
16+
# Limine can only read FAT. When the ESP is the boot partition but
17+
# mounted outside /boot and UKI is disabled, the kernel ends up on the
18+
# root filesystem which Limine cannot access.
19+
if not (bootloader_config and bootloader_config.bootloader == Bootloader.Limine and not bootloader_config.uki and disk_config):
20+
return None
21+
22+
efi_part = next(
23+
(p for m in disk_config.device_modifications if (p := m.get_efi_partition())),
24+
None,
25+
)
26+
boot_part = next(
27+
(p for m in disk_config.device_modifications if (p := m.get_boot_partition())),
28+
None,
29+
)
30+
31+
if efi_part and boot_part == efi_part and efi_part.mountpoint != Path('/boot'):
32+
return (
33+
f'Limine requires kernels on a FAT partition. The ESP is mounted at {efi_part.mountpoint}, '
34+
'enable UKI or add a separate /boot partition to install Limine.'
35+
)
36+
return None

archinstall/scripts/guided.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import os
22
import sys
33
import time
4-
from pathlib import Path
54

65
from archinstall.lib.applications.application_handler import ApplicationHandler
76
from archinstall.lib.args import ArchConfig, ArchConfigHandler
87
from archinstall.lib.authentication.authentication_handler import AuthenticationHandler
8+
from archinstall.lib.bootloader.utils import validate_bootloader_layout
99
from archinstall.lib.configuration import ConfigurationOutput
1010
from archinstall.lib.disk.filesystem import FilesystemHandler
1111
from archinstall.lib.disk.utils import disk_layouts
@@ -196,35 +196,6 @@ def perform_installation(
196196
pass
197197

198198

199-
def _check_bootloader_layout(config: ArchConfig) -> str | None:
200-
"""Validate bootloader configuration against disk layout.
201-
202-
Returns an error message if the configuration would produce an
203-
unbootable system, or None if it is valid.
204-
"""
205-
# Limine can only read FAT. When the ESP is the boot partition but
206-
# mounted outside /boot and UKI is disabled, the kernel ends up on the
207-
# root filesystem which Limine cannot access.
208-
if not (config.bootloader_config and config.bootloader_config.bootloader == Bootloader.Limine and not config.bootloader_config.uki and config.disk_config):
209-
return None
210-
211-
efi_part = next(
212-
(p for m in config.disk_config.device_modifications if (p := m.get_efi_partition())),
213-
None,
214-
)
215-
boot_part = next(
216-
(p for m in config.disk_config.device_modifications if (p := m.get_boot_partition())),
217-
None,
218-
)
219-
220-
if efi_part and boot_part == efi_part and efi_part.mountpoint != Path('/boot'):
221-
return (
222-
f'Limine requires kernels on a FAT partition. The ESP is mounted at {efi_part.mountpoint}, '
223-
'enable UKI or add a separate /boot partition to install Limine.'
224-
)
225-
return None
226-
227-
228199
def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
229200
if arch_config_handler is None:
230201
arch_config_handler = ArchConfigHandler()
@@ -243,7 +214,10 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
243214

244215
# Safety net for silent/config-file flow. The TUI menu blocks Install via
245216
# GlobalMenu._validate_bootloader() before reaching this point.
246-
if err_msg := _check_bootloader_layout(arch_config_handler.config):
217+
if err_msg := validate_bootloader_layout(
218+
arch_config_handler.config.bootloader_config,
219+
arch_config_handler.config.disk_config,
220+
):
247221
error(err_msg)
248222
return
249223

0 commit comments

Comments
 (0)