Repository: archlinux/archinstall

Issue:
Investigate possible issue with BitLocker being detected as encrypted
There appears to be an issue with mainly `"encrypted": True` encrypting the drive despite the filesystem format being invalid.
In the below scenario, the filesystem `BitLocker` will bail because it's an alien filesystem type. But it will happily encrypt the drive wiping anything inside.

There also appear to be an issue with `"encrypted": true` being set despite never setting it in the manual tool. Which is another issue we need to investigate.

<details>
    <summary>A user_disk_layout.json example</summary>
    ```json
    {
        "/dev/nvme0n1": {
            "partitions": [
                {
                    "ESP": true,
                    "PARTUUID": "c3ddf24b-e29a-48eb-bdf2-5471d6c63982",
                    "boot": true,
                    "encrypted": false,
                    "filesystem": {
                        "format": "vfat"
                    },
                    "mountpoint": "/boot",
                    "size": 307200,
                    "start": 2048,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "20676392-a478-444b-a4ef-ccf481554d4d",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": ""
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 262144,
                    "start": 309248,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "7f40c607-ff78-406d-8208-011c0767637e",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": "BitLocker"
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 299753472,
                    "start": 571392,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "91cf08a2-a41a-4cdc-84fb-8cf9d1a8a1c5",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": "ext4"
                    },
                    "mountpoint": "/",
                    "size": 147671040,
                    "start": 300324864,
                    "type": "primary",
                    "wipe": true
                },
                {
                    "ESP": false,
                    "PARTUUID": "94972435-f8c1-42f3-bb55-09cd221202ff",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": ""
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 16777216,
                    "start": 447995904,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "b582d97e-d680-4e0f-89e1-fecc113a4043",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": "ntfs"
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 2027520,
                    "start": 464775168,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "c86e4277-7708-4f8d-886a-b61925ef8046",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": "ntfs"
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 30468096,
                    "start": 466802688,
                    "type": "primary",
                    "wipe": false
                },
                {
                    "ESP": false,
                    "PARTUUID": "01914a4a-566a-4d1d-8e6d-4b42ced48dda",
                    "boot": false,
                    "encrypted": true,
                    "filesystem": {
                        "format": "ntfs"
                    },
                    "generate-encryption-key-file": true,
                    "mountpoint": null,
                    "size": 2844672,
                    "start": 497272832,
                    "type": "primary",
                    "wipe": false
                }
            ]
        }
    }
    ```
</details>

![PXL_20220516_231000015](https://user-images.githubusercontent.com/861439/168655299-1ebc92f5-9420-497d-bbdd-32bf7349eeaf.jpg)



Discussion:
After some investigation and debugging by a patient discord user, it's the `mark as encrypted` that marks all partitions as encrypted.

So this is where the menu system exits and initiate a checks: https://github.com/archlinux/archinstall/blob/bdf11913d4bbfa84a6008b3a0b707edb78a1c210/archinstall/lib/menu/global_menu.py#L192-L197

And that calls this buggy function: https://github.com/archlinux/archinstall/blob/bdf11913d4bbfa84a6008b3a0b707edb78a1c210/archinstall/lib/user_interaction/partitioning_conf.py#L364-L375

I thought we corrected this way way way back..

Resolving patch:
diff --git a/archinstall/lib/menu/global_menu.py b/archinstall/lib/menu/global_menu.py
--- a/archinstall/lib/menu/global_menu.py
+++ b/archinstall/lib/menu/global_menu.py
@@ -193,8 +193,15 @@ def exit_callback(self):
 			# If no partitions was marked as encrypted, but a password was supplied and we have some disks to format..
 			# Then we need to identify which partitions to encrypt. This will default to / (root).
 			if len(list(encrypted_partitions(storage['arguments'].get('disk_layouts', [])))) == 0:
-				storage['arguments']['disk_layouts'] = select_encrypted_partitions(
-					storage['arguments']['disk_layouts'], storage['arguments']['!encryption-password'])
+				for blockdevice in storage['arguments']['disk_layouts']:
+					for partition_index in select_encrypted_partitions(
+							title="Select which partitions to encrypt:",
+							partitions=storage['arguments']['disk_layouts'][blockdevice]['partitions']
+						):
+
+						partition = storage['arguments']['disk_layouts'][blockdevice]['partitions'][partition_index]
+						partition['encrypted'] = True
+						partition['!password'] = storage['arguments']['!encryption-password']
 
 	def _install_text(self):
 		missing = len(self._missing_configs())
diff --git a/archinstall/lib/user_interaction/partitioning_conf.py b/archinstall/lib/user_interaction/partitioning_conf.py
--- a/archinstall/lib/user_interaction/partitioning_conf.py
+++ b/archinstall/lib/user_interaction/partitioning_conf.py
@@ -8,7 +8,6 @@
 from ..output import log
 
 from ..disk.validators import fs_types
-from ..disk.helpers import has_mountpoint
 
 if TYPE_CHECKING:
 	from ..disk import BlockDevice
@@ -271,6 +270,7 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
 						block_device_struct["partitions"][partition]["filesystem"]["mount_options"].append("compress=zstd")
 			elif task == delete_all_partitions:
 				block_device_struct["partitions"] = []
+				block_device_struct["wipe"] = True
 			elif task == assign_mount_point:
 				title = _('{}\n\nSelect by index which partition to mount where').format(current_layout)
 				partition = select_partition(title, block_device_struct["partitions"])
@@ -360,19 +360,30 @@ def manage_new_and_existing_partitions(block_device: 'BlockDevice') -> Dict[str,
 
 	return block_device_struct
 
+def select_encrypted_partitions(
+	title :str,
+	partitions :List[Partition],
+	multiple :bool = True,
+	filter_ :Callable = None
+) -> Optional[int, List[int]]:
+	partition_indexes = _get_partitions(partitions, filter_)
 
-def select_encrypted_partitions(block_devices: dict, password: str) -> dict:
-	for device in block_devices:
-		for partition in block_devices[device]['partitions']:
-			if partition.get('mountpoint', None) != '/boot':
-				partition['encrypted'] = True
-				partition['!password'] = password
+	if len(partition_indexes) == 0:
+		return None
 
-				if not has_mountpoint(partition,'/'):
-					# Tell the upcoming steps to generate a key-file for non root mounts.
-					partition['generate-encryption-key-file'] = True
+	title = _('Select which partitions to mark for formatting:')
 
-	return block_devices
+	# show current partition layout:
+	if len(partitions):
+		title += _current_partition_layout(partitions) + '\n'
 
-	# TODO: Next version perhaps we can support mixed multiple encrypted partitions
-	# Users might want to single out a partition for non-encryption to share between dualboot etc.
+	choice = Menu(title, partition_indexes, multi=multiple).run()
+
+	if choice.type_ == MenuSelectionType.Esc:
+		return None
+
+	if isinstance(choice.value, list):
+		for partition_index in choice.value:
+			yield int(partition_index)
+	else:
+		yield (partition_index)
\ No newline at end of file


Test patch: