Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-03-09 00:12:03 +0100
committerAnton Hvornum <anton@hvornum.se>2021-03-09 00:12:03 +0100
commit7ee48156486101a43e90f834825dfeb0742247bd (patch)
tree3beb97042da4829183f1656216b5d135b1659d16 /archinstall/lib/disk.py
parentf1cb3209ad9deb609d9fff35c52ec76027ceffb4 (diff)
Adding encryption helpers to the Partition() class, that sets up and utilizes luks2.encrypt() in extension.
Diffstat (limited to 'archinstall/lib/disk.py')
-rw-r--r--archinstall/lib/disk.py36
1 files changed, 30 insertions, 6 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index 01a736a3..3397d7cb 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -197,6 +197,21 @@ class Partition():
return True
+ def encrypt(self, *args, **kwargs):
+ """
+ A wrapper function for luks2() instances and the .encrypt() method of that instance.
+ """
+ from .luks import luks2
+
+ if not self.encrypted:
+ raise DiskError(f"Attempting to encrypt a partition that was not marked for encryption: {self}")
+
+ if not self.safe_to_format():
+ return False
+
+ handle = luks2(self, None, None)
+ return handle.encrypt(self, *args, **kwargs)
+
def format(self, filesystem=None, path=None, allow_formatting=None, log_formating=True):
"""
Format can be given an overriding path, for instance /dev/null to test
@@ -204,6 +219,7 @@ class Partition():
"""
if filesystem is None:
filesystem = self.filesystem
+
if path is None:
path = self.path
if allow_formatting is None:
@@ -349,15 +365,23 @@ class Filesystem():
"""
return self.raw_parted(string).exit_code
- def use_entire_disk(self, prep_mode=None):
+ def use_entire_disk(self, root_filesystem_type='ext4', encrypt_root_partition=True):
self.add_partition('primary', start='1MiB', end='513MiB', format='vfat')
self.set_name(0, 'EFI')
self.set(0, 'boot on')
- self.set(0, 'esp on') # TODO: Redundant, as in GPT mode it's an alias for "boot on"? https://www.gnu.org/software/parted/manual/html_node/set.html
- if prep_mode == 'luks2':
- self.add_partition('primary', start='513MiB', end='100%')
- else:
- self.add_partition('primary', start='513MiB', end='100%', format=prep_mode)
+ # TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"?
+ # https://www.gnu.org/software/parted/manual/html_node/set.html
+ self.set(0, 'esp on')
+ self.add_partition('primary', start='513MiB', end='100%')
+
+ self.blockdevice.partition[0].filesystem = 'vfat'
+ self.blockdevice.partition[1].filesystem = root_filesystem_type
+
+ self.blockdevice.partition[0].target_mountpoint = '/boot'
+ self.blockdevice.partition[1].target_mountpoint = '/'
+
+ if encrypt_root_partition:
+ self.blockdevice.partition[1].encrypted = True
def add_partition(self, type, start, end, format=None):
log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info)