diff --git a/archinstall/lib/disk/disk_menu.py b/archinstall/lib/disk/disk_menu.py index 77a32b7a62..68d4b376a3 100644 --- a/archinstall/lib/disk/disk_menu.py +++ b/archinstall/lib/disk/disk_menu.py @@ -78,7 +78,7 @@ def _define_menu_options(self) -> list[MenuItem]: ), MenuItem( text=tr('Disk encryption'), - action=self._disk_encryption, + action=self._select_disk_encryption, preview_action=self._prev_disk_encryption, dependencies=['disk_config'], key='disk_encryption', @@ -121,17 +121,20 @@ def _check_dep_btrfs(self) -> bool: return False - def _disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None: + def _select_disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None: disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value + lvm_config: LvmConfiguration | None = self._item_group.find_by_key('lvm_config').value if not disk_config: - # this should not happen as the encryption menu has the disk_config as dependency - raise ValueError('No disk layout specified') + return preset - if not DiskEncryption.validate_enc(disk_config): + modifications = disk_config.device_modifications + + if not DiskEncryption.validate_enc(modifications, lvm_config): return None - disk_encryption = DiskEncryptionMenu(disk_config, preset=preset).run() + disk_encryption = DiskEncryptionMenu(modifications, lvm_config=lvm_config, preset=preset).run() + return disk_encryption def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) -> DiskLayoutConfiguration | None: @@ -146,10 +149,15 @@ def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) -> def _select_lvm_config(self, preset: LvmConfiguration | None) -> LvmConfiguration | None: disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value - if disk_config: - return select_lvm_config(disk_config, preset=preset) + if not disk_config: + return preset + + lvm_config = select_lvm_config(disk_config, preset=preset) + + if lvm_config != preset: + self._menu_item_group.find_by_key('disk_encryption').value = None - return preset + return lvm_config def _select_btrfs_snapshots(self, preset: SnapshotConfig | None) -> SnapshotConfig | None: preset_type = preset.snapshot_type if preset else None @@ -250,7 +258,7 @@ def _prev_disk_encryption(self, item: MenuItem) -> str | None: disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value enc_config: DiskEncryption | None = item.value - if disk_config and not DiskEncryption.validate_enc(disk_config): + if disk_config and not DiskEncryption.validate_enc(disk_config.device_modifications, disk_config.lvm_config): return tr('LVM disk encryption with more than 2 partitions is currently not supported') if enc_config: diff --git a/archinstall/lib/disk/encryption_menu.py b/archinstall/lib/disk/encryption_menu.py index cab811ed4d..c664ba6e19 100644 --- a/archinstall/lib/disk/encryption_menu.py +++ b/archinstall/lib/disk/encryption_menu.py @@ -5,7 +5,6 @@ from archinstall.lib.models.device_model import ( DeviceModification, DiskEncryption, - DiskLayoutConfiguration, EncryptionType, LvmConfiguration, LvmVolume, @@ -28,7 +27,8 @@ class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]): def __init__( self, - disk_config: DiskLayoutConfiguration, + device_modifications: list[DeviceModification], + lvm_config: LvmConfiguration | None = None, preset: DiskEncryption | None = None, ): if preset: @@ -36,7 +36,8 @@ def __init__( else: self._enc_config = DiskEncryption() - self._disk_config = disk_config + self._device_modifications = device_modifications + self._lvm_config = lvm_config menu_optioons = self._define_menu_options() self._item_group = MenuItemGroup(menu_optioons, sort_items=False, checkmarks=True) @@ -51,7 +52,7 @@ def _define_menu_options(self) -> list[MenuItem]: return [ MenuItem( text=tr('Encryption type'), - action=lambda x: select_encryption_type(self._disk_config, x), + action=lambda x: select_encryption_type(self._device_modifications, self._lvm_config, x), value=self._enc_config.encryption_type, preview_action=self._preview, key='encryption_type', @@ -66,7 +67,7 @@ def _define_menu_options(self) -> list[MenuItem]: ), MenuItem( text=tr('Partitions'), - action=lambda x: select_partitions_to_encrypt(self._disk_config.device_modifications, x), + action=lambda x: select_partitions_to_encrypt(self._device_modifications, x), value=self._enc_config.partitions, dependencies=[self._check_dep_partitions], preview_action=self._preview, @@ -91,8 +92,8 @@ def _define_menu_options(self) -> list[MenuItem]: ] def _select_lvm_vols(self, preset: list[LvmVolume]) -> list[LvmVolume]: - if self._disk_config.lvm_config: - return select_lvm_vols_to_encrypt(self._disk_config.lvm_config, preset=preset) + if self._lvm_config: + return select_lvm_vols_to_encrypt(self._lvm_config, preset=preset) return [] def _check_dep_enc_type(self) -> bool: @@ -214,15 +215,23 @@ def _prev_hsm(self) -> str | None: return f'{tr("HSM device")}: {output}' -def select_encryption_type(disk_config: DiskLayoutConfiguration, preset: EncryptionType) -> EncryptionType | None: +def select_encryption_type( + device_modifications: list[DeviceModification], + lvm_config: LvmConfiguration | None = None, + preset: EncryptionType | None = None, +) -> EncryptionType | None: options: list[EncryptionType] = [] - preset_value = EncryptionType.type_to_text(preset) - if disk_config.lvm_config: + if lvm_config: options = [EncryptionType.LvmOnLuks, EncryptionType.LuksOnLvm] else: options = [EncryptionType.Luks] + if not preset: + preset = options[0] + + preset_value = EncryptionType.type_to_text(preset) + items = [MenuItem(EncryptionType.type_to_text(o), value=o) for o in options] group = MenuItemGroup(items) group.set_focus_by_value(preset_value) diff --git a/archinstall/lib/global_menu.py b/archinstall/lib/global_menu.py index 25be5bd7a8..50e4f0de21 100644 --- a/archinstall/lib/global_menu.py +++ b/archinstall/lib/global_menu.py @@ -312,15 +312,15 @@ def _prev_disk_config(self, item: MenuItem) -> str | None: output += tr('Mountpoint') + ': ' + str(disk_layout_conf.mountpoint) if disk_layout_conf.lvm_config: - output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg()) + output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg()) + '\n' if disk_layout_conf.disk_encryption: - output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type) + output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type) + '\n' if disk_layout_conf.btrfs_options: btrfs_options = disk_layout_conf.btrfs_options if btrfs_options.snapshot_config: - output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value) + output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value) + '\n' return output diff --git a/archinstall/lib/models/device_model.py b/archinstall/lib/models/device_model.py index 12d6ec4c78..0c5133ccc0 100644 --- a/archinstall/lib/models/device_model.py +++ b/archinstall/lib/models/device_model.py @@ -1505,15 +1505,19 @@ def json(self) -> _DiskEncryptionSerialization: return obj @classmethod - def validate_enc(cls, disk_config: DiskLayoutConfiguration) -> bool: + def validate_enc( + cls, + modifications: list[DeviceModification], + lvm_config: LvmConfiguration | None = None, + ) -> bool: partitions = [] - for mod in disk_config.device_modifications: + for mod in modifications: for part in mod.partitions: partitions.append(part) if len(partitions) > 2: # assume one boot and at least 2 additional - if disk_config.lvm_config: + if lvm_config: return False return True @@ -1525,7 +1529,7 @@ def parse_arg( disk_encryption: _DiskEncryptionSerialization, password: Password | None = None, ) -> 'DiskEncryption | None': - if not cls.validate_enc(disk_config): + if not cls.validate_enc(disk_config.device_modifications, disk_config.lvm_config): return None if not password: