Zram - remove custom size in config (#4272)

This commit is contained in:
Daniel Girtler 2026-03-21 17:56:59 +11:00 committed by GitHub
parent 8e34303175
commit e06dd6299f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 19 deletions

View File

@ -1004,27 +1004,19 @@ class Installer:
self._configure_grub_btrfsd(snapshot_type)
self.enable_service('grub-btrfsd.service')
def setup_swap(self, kind: str = 'zram', algo: ZramAlgorithm = ZramAlgorithm.ZSTD) -> None:
if kind == 'zram':
info('Setting up swap on zram')
self.pacman.strap('zram-generator')
# Get RAM size in MB from hardware info
ram_kb = SysInfo.mem_total()
# Convert KB to MB and divide by 2, with minimum of 4096 MB
size_mb = max(ram_kb // 2048, 4096)
info(f'Zram size: {size_mb} from RAM: {ram_kb}')
info(f'Zram compression algorithm: {algo.value}')
def setup_swap(self, algo: ZramAlgorithm = ZramAlgorithm.ZSTD) -> None:
info('Setting up swap on zram')
self.pacman.strap('zram-generator')
with open(f'{self.target}/etc/systemd/zram-generator.conf', 'w') as zram_conf:
zram_conf.write('[zram0]\n')
zram_conf.write(f'zram-size = {size_mb}\n')
zram_conf.write(f'compression-algorithm = {algo.value}\n')
info(f'Zram compression algorithm: {algo.value}')
self.enable_service('systemd-zram-setup@zram0.service')
with open(f'{self.target}/etc/systemd/zram-generator.conf', 'w') as zram_conf:
zram_conf.write('[zram0]\n')
zram_conf.write(f'compression-algorithm = {algo.value}\n')
self._zram_enabled = True
else:
raise ValueError('Archinstall currently only supports setting up swap on zram')
self.enable_service('systemd-zram-setup@zram0.service')
self._zram_enabled = True
def _get_efi_partition(self) -> PartitionModification | None:
for layout in self._disk_config.device_modifications:

View File

@ -112,7 +112,7 @@ def perform_installation(
installation.set_mirrors(mirror_list_handler, mirror_config, on_target=True)
if config.swap and config.swap.enabled:
installation.setup_swap('zram', algo=config.swap.algorithm)
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)