Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/luks.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-03-14 12:13:08 +0100
committerAnton Hvornum <anton@hvornum.se>2021-03-14 12:13:08 +0100
commit577428f1b20da6f7f583c9c3c276ee1d38abb01d (patch)
tree1fda7e0df12edd9e6f54bff057bb62ad7920c435 /archinstall/lib/luks.py
parent5483b218fd62fcea8648525eb8aa6b7af4cc200b (diff)
Added a partition.umount() and a check when running cryptsetup if the disk is in use.
Diffstat (limited to 'archinstall/lib/luks.py')
-rw-r--r--archinstall/lib/luks.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py
index e54641b8..de53c05e 100644
--- a/archinstall/lib/luks.py
+++ b/archinstall/lib/luks.py
@@ -64,8 +64,14 @@ class luks2():
with open(key_file, 'wb') as fh:
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}'))
- if b'Command successful.' not in o:
+ 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 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}')
return key_file