Keep standalone initramfs for grub-btrfs when UKI is enabled (#4513)

* Keep standalone initramfs for grub-btrfs when UKI is enabled

Fixes #4505

* Move keep_initramfs logic into add_bootloader()

The grub-btrfs snapshot detection was in guided.py, forcing custom
script authors to replicate it. Since Installer already holds
disk_config, the check belongs inside add_bootloader().
This commit is contained in:
Softer 2026-05-06 07:26:59 +03:00 committed by GitHub
parent ba7dbeadfc
commit 11607851c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 7 deletions

View File

@ -1754,6 +1754,7 @@ class Installer:
self,
root: PartitionModification | LvmVolume,
efi_partition: PartitionModification | None,
keep_initramfs: bool = False,
) -> None:
if not efi_partition or not efi_partition.mountpoint:
raise ValueError(f'Could not detect ESP at mountpoint {self.target}')
@ -1777,11 +1778,11 @@ class Installer:
config = preset.read_text().splitlines(True)
for index, line in enumerate(config):
# Avoid storing redundant image file
if m := image_re.match(line):
image = self.target / m.group(2)
image.unlink(missing_ok=True)
config[index] = '#' + m.group(1)
if not keep_initramfs:
image = self.target / m.group(2)
image.unlink(missing_ok=True)
config[index] = '#' + m.group(1)
elif m := uki_re.match(line):
if diff_mountpoint:
config[index] = m.group(2) + diff_mountpoint + m.group(3)
@ -1800,7 +1801,12 @@ class Installer:
if not self.mkinitcpio(['-P']):
error('Error generating initramfs (continuing anyway)')
def add_bootloader(self, bootloader: Bootloader, uki_enabled: bool = False, bootloader_removable: bool = False) -> None:
def add_bootloader(
self,
bootloader: Bootloader,
uki_enabled: bool = False,
bootloader_removable: bool = False,
) -> None:
"""
Adds a bootloader to the installation instance.
Archinstall supports one of five types:
@ -1849,7 +1855,13 @@ class Installer:
bootloader_removable = False
if uki_enabled:
self._config_uki(root, efi_partition)
keep_initramfs = (
bootloader == Bootloader.Grub
and self._disk_config.has_default_btrfs_vols()
and self._disk_config.btrfs_options is not None
and self._disk_config.btrfs_options.snapshot_config is not None
)
self._config_uki(root, efi_partition, keep_initramfs)
match bootloader:
case Bootloader.Systemd:

View File

@ -115,7 +115,11 @@ def perform_installation(
installation.setup_swap(algo=config.swap.algorithm)
if config.bootloader_config and config.bootloader_config.bootloader != Bootloader.NO_BOOTLOADER:
installation.add_bootloader(config.bootloader_config.bootloader, config.bootloader_config.uki, config.bootloader_config.removable)
installation.add_bootloader(
config.bootloader_config.bootloader,
config.bootloader_config.uki,
config.bootloader_config.removable,
)
if config.network_config:
install_network_config(