Skip to content

Commit 8c12d15

Browse files
authored
Fix disk encryption emnu (archlinux#3506)
1 parent 6c7260f commit 8c12d15

File tree

4 files changed

+48
-27
lines changed

4 files changed

+48
-27
lines changed

archinstall/lib/disk/disk_menu.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _define_menu_options(self) -> list[MenuItem]:
7878
),
7979
MenuItem(
8080
text=tr('Disk encryption'),
81-
action=self._disk_encryption,
81+
action=self._select_disk_encryption,
8282
preview_action=self._prev_disk_encryption,
8383
dependencies=['disk_config'],
8484
key='disk_encryption',
@@ -121,17 +121,20 @@ def _check_dep_btrfs(self) -> bool:
121121

122122
return False
123123

124-
def _disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None:
124+
def _select_disk_encryption(self, preset: DiskEncryption | None) -> DiskEncryption | None:
125125
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
126+
lvm_config: LvmConfiguration | None = self._item_group.find_by_key('lvm_config').value
126127

127128
if not disk_config:
128-
# this should not happen as the encryption menu has the disk_config as dependency
129-
raise ValueError('No disk layout specified')
129+
return preset
130130

131-
if not DiskEncryption.validate_enc(disk_config):
131+
modifications = disk_config.device_modifications
132+
133+
if not DiskEncryption.validate_enc(modifications, lvm_config):
132134
return None
133135

134-
disk_encryption = DiskEncryptionMenu(disk_config, preset=preset).run()
136+
disk_encryption = DiskEncryptionMenu(modifications, lvm_config=lvm_config, preset=preset).run()
137+
135138
return disk_encryption
136139

137140
def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) -> DiskLayoutConfiguration | None:
@@ -146,10 +149,15 @@ def _select_disk_layout_config(self, preset: DiskLayoutConfiguration | None) ->
146149
def _select_lvm_config(self, preset: LvmConfiguration | None) -> LvmConfiguration | None:
147150
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
148151

149-
if disk_config:
150-
return select_lvm_config(disk_config, preset=preset)
152+
if not disk_config:
153+
return preset
154+
155+
lvm_config = select_lvm_config(disk_config, preset=preset)
156+
157+
if lvm_config != preset:
158+
self._menu_item_group.find_by_key('disk_encryption').value = None
151159

152-
return preset
160+
return lvm_config
153161

154162
def _select_btrfs_snapshots(self, preset: SnapshotConfig | None) -> SnapshotConfig | None:
155163
preset_type = preset.snapshot_type if preset else None
@@ -250,7 +258,7 @@ def _prev_disk_encryption(self, item: MenuItem) -> str | None:
250258
disk_config: DiskLayoutConfiguration | None = self._item_group.find_by_key('disk_config').value
251259
enc_config: DiskEncryption | None = item.value
252260

253-
if disk_config and not DiskEncryption.validate_enc(disk_config):
261+
if disk_config and not DiskEncryption.validate_enc(disk_config.device_modifications, disk_config.lvm_config):
254262
return tr('LVM disk encryption with more than 2 partitions is currently not supported')
255263

256264
if enc_config:

archinstall/lib/disk/encryption_menu.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from archinstall.lib.models.device_model import (
66
DeviceModification,
77
DiskEncryption,
8-
DiskLayoutConfiguration,
98
EncryptionType,
109
LvmConfiguration,
1110
LvmVolume,
@@ -28,15 +27,17 @@
2827
class DiskEncryptionMenu(AbstractSubMenu[DiskEncryption]):
2928
def __init__(
3029
self,
31-
disk_config: DiskLayoutConfiguration,
30+
device_modifications: list[DeviceModification],
31+
lvm_config: LvmConfiguration | None = None,
3232
preset: DiskEncryption | None = None,
3333
):
3434
if preset:
3535
self._enc_config = preset
3636
else:
3737
self._enc_config = DiskEncryption()
3838

39-
self._disk_config = disk_config
39+
self._device_modifications = device_modifications
40+
self._lvm_config = lvm_config
4041

4142
menu_optioons = self._define_menu_options()
4243
self._item_group = MenuItemGroup(menu_optioons, sort_items=False, checkmarks=True)
@@ -51,7 +52,7 @@ def _define_menu_options(self) -> list[MenuItem]:
5152
return [
5253
MenuItem(
5354
text=tr('Encryption type'),
54-
action=lambda x: select_encryption_type(self._disk_config, x),
55+
action=lambda x: select_encryption_type(self._device_modifications, self._lvm_config, x),
5556
value=self._enc_config.encryption_type,
5657
preview_action=self._preview,
5758
key='encryption_type',
@@ -66,7 +67,7 @@ def _define_menu_options(self) -> list[MenuItem]:
6667
),
6768
MenuItem(
6869
text=tr('Partitions'),
69-
action=lambda x: select_partitions_to_encrypt(self._disk_config.device_modifications, x),
70+
action=lambda x: select_partitions_to_encrypt(self._device_modifications, x),
7071
value=self._enc_config.partitions,
7172
dependencies=[self._check_dep_partitions],
7273
preview_action=self._preview,
@@ -91,8 +92,8 @@ def _define_menu_options(self) -> list[MenuItem]:
9192
]
9293

9394
def _select_lvm_vols(self, preset: list[LvmVolume]) -> list[LvmVolume]:
94-
if self._disk_config.lvm_config:
95-
return select_lvm_vols_to_encrypt(self._disk_config.lvm_config, preset=preset)
95+
if self._lvm_config:
96+
return select_lvm_vols_to_encrypt(self._lvm_config, preset=preset)
9697
return []
9798

9899
def _check_dep_enc_type(self) -> bool:
@@ -214,15 +215,23 @@ def _prev_hsm(self) -> str | None:
214215
return f'{tr("HSM device")}: {output}'
215216

216217

217-
def select_encryption_type(disk_config: DiskLayoutConfiguration, preset: EncryptionType) -> EncryptionType | None:
218+
def select_encryption_type(
219+
device_modifications: list[DeviceModification],
220+
lvm_config: LvmConfiguration | None = None,
221+
preset: EncryptionType | None = None,
222+
) -> EncryptionType | None:
218223
options: list[EncryptionType] = []
219-
preset_value = EncryptionType.type_to_text(preset)
220224

221-
if disk_config.lvm_config:
225+
if lvm_config:
222226
options = [EncryptionType.LvmOnLuks, EncryptionType.LuksOnLvm]
223227
else:
224228
options = [EncryptionType.Luks]
225229

230+
if not preset:
231+
preset = options[0]
232+
233+
preset_value = EncryptionType.type_to_text(preset)
234+
226235
items = [MenuItem(EncryptionType.type_to_text(o), value=o) for o in options]
227236
group = MenuItemGroup(items)
228237
group.set_focus_by_value(preset_value)

archinstall/lib/global_menu.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,15 +312,15 @@ def _prev_disk_config(self, item: MenuItem) -> str | None:
312312
output += tr('Mountpoint') + ': ' + str(disk_layout_conf.mountpoint)
313313

314314
if disk_layout_conf.lvm_config:
315-
output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg())
315+
output += '{}: {}'.format(tr('LVM configuration type'), disk_layout_conf.lvm_config.config_type.display_msg()) + '\n'
316316

317317
if disk_layout_conf.disk_encryption:
318-
output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type)
318+
output += tr('Disk encryption') + ': ' + EncryptionType.type_to_text(disk_layout_conf.disk_encryption.encryption_type) + '\n'
319319

320320
if disk_layout_conf.btrfs_options:
321321
btrfs_options = disk_layout_conf.btrfs_options
322322
if btrfs_options.snapshot_config:
323-
output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value)
323+
output += tr('Btrfs snapshot type: {}').format(btrfs_options.snapshot_config.snapshot_type.value) + '\n'
324324

325325
return output
326326

archinstall/lib/models/device_model.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,15 +1505,19 @@ def json(self) -> _DiskEncryptionSerialization:
15051505
return obj
15061506

15071507
@classmethod
1508-
def validate_enc(cls, disk_config: DiskLayoutConfiguration) -> bool:
1508+
def validate_enc(
1509+
cls,
1510+
modifications: list[DeviceModification],
1511+
lvm_config: LvmConfiguration | None = None,
1512+
) -> bool:
15091513
partitions = []
15101514

1511-
for mod in disk_config.device_modifications:
1515+
for mod in modifications:
15121516
for part in mod.partitions:
15131517
partitions.append(part)
15141518

15151519
if len(partitions) > 2: # assume one boot and at least 2 additional
1516-
if disk_config.lvm_config:
1520+
if lvm_config:
15171521
return False
15181522

15191523
return True
@@ -1525,7 +1529,7 @@ def parse_arg(
15251529
disk_encryption: _DiskEncryptionSerialization,
15261530
password: Password | None = None,
15271531
) -> 'DiskEncryption | None':
1528-
if not cls.validate_enc(disk_config):
1532+
if not cls.validate_enc(disk_config.device_modifications, disk_config.lvm_config):
15291533
return None
15301534

15311535
if not password:

0 commit comments

Comments
 (0)