Fix 2735 - Erase luks partition explicitly (#2745)

This commit is contained in:
Daniel Girtler 2024-11-04 22:42:12 +11:00 committed by GitHub
parent 7437668f1e
commit 918ac5c765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View File

@ -803,6 +803,10 @@ class DeviceHandler(object):
"""
info(f'Wiping partitions and metadata: {block_device.device_info.path}')
for partition in block_device.partition_infos:
luks = Luks2(partition.path)
if luks.isLuks():
luks.erase()
self._wipe(partition.path)
self._wipe(block_device.device_info.path)

View File

@ -30,6 +30,19 @@ class Luks2:
return Path(f'/dev/mapper/{self.mapper_name}')
return None
def isLuks(self) -> bool:
try:
SysCommand(f'cryptsetup isLuks {self.luks_dev_path}')
return True
except SysCallError:
return False
def erase(self) -> None:
debug(f'Erasing luks partition: {self.luks_dev_path}')
worker = SysCommandWorker(f'cryptsetup erase {self.luks_dev_path}')
worker.poll()
worker.write(b'YES\n', line_ending=False)
def __post_init__(self) -> None:
if self.luks_dev_path is None:
raise ValueError('Partition must have a path set')