Added a partition.umount() and a check when running cryptsetup if the disk is in use.
This commit is contained in:
parent
5483b218fd
commit
577428f1b2
|
|
@ -312,6 +312,11 @@ class Partition():
|
||||||
self.mountpoint = target
|
self.mountpoint = target
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def unmount(self):
|
||||||
|
if sys_command(f'/usr/bin/umount {self.path}').exit_code == 0:
|
||||||
|
self.mountpoint = None
|
||||||
|
return True
|
||||||
|
|
||||||
def filesystem_supported(self):
|
def filesystem_supported(self):
|
||||||
"""
|
"""
|
||||||
The support for a filesystem (this partition) is tested by calling
|
The support for a filesystem (this partition) is tested by calling
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,14 @@ class luks2():
|
||||||
with open(key_file, 'wb') as fh:
|
with open(key_file, 'wb') as fh:
|
||||||
fh.write(password)
|
fh.write(password)
|
||||||
|
|
||||||
o = b''.join(sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}'))
|
cmd_handle = sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}')
|
||||||
if b'Command successful.' not in o:
|
if cmd_handle.exit_code == 256:
|
||||||
|
# Partition was in use, unmount it and
|
||||||
|
partition.unmount()
|
||||||
|
sys_command(f'cryptsetup close {partition.path}')
|
||||||
|
cmd_handle = sys_command(f'/usr/bin/cryptsetup -q -v --type luks2 --pbkdf argon2i --hash {hash_type} --key-size {key_size} --iter-time {iter_time} --key-file {os.path.abspath(key_file)} --use-urandom luksFormat {partition.path}')
|
||||||
|
|
||||||
|
if b'Command successful.' not in b''.join(cmd_handle):
|
||||||
raise DiskError(f'Could not encrypt volume "{partition.path}": {o}')
|
raise DiskError(f'Could not encrypt volume "{partition.path}": {o}')
|
||||||
|
|
||||||
return key_file
|
return key_file
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue