Repository: archlinux/archinstall

Issue:
[master] Issue if a secondary drive is zeroed out when setting up a secondary partition on it, like /home
![screenshot](https://user-images.githubusercontent.com/861439/170750467-a9d2acff-206f-4b57-8492-ac10b7f3218d.png)

Sample layout:
```json
{
    "/dev/sda": {
        "partitions": [
            {
                "ESP": true,
                "PARTUUID": "88C9-7FE6",
                "boot": true,
                "encrypted": false,
                "filesystem": {
                    "format": "vfat"
                },
                "mountpoint": "/boot",
                "size": 204800,
                "start": 2048,
                "type": "primary",
                "wipe": false
            },
            {
                "ESP": false,
                "PARTUUID": "",
                "boot": false,
                "encrypted": false,
                "filesystem": {
                    "format": ""
                },
                "mountpoint": null,
                "size": 32768,
                "start": 206848,
                "type": "primary",
                "wipe": false
            },
            {
                "ESP": false,
                "PARTUUID": "541CD69F1CD67B84",
                "boot": false,
                "encrypted": false,
                "filesystem": {
                    "format": "ntfs"
                },
                "mountpoint": null,
                "size": 297249496,
                "start": 239616,
                "type": "primary",
                "wipe": false
            },
            {
                "ESP": false,
                "PARTUUID": "FC92E3C192E37F10",
                "boot": false,
                "encrypted": false,
                "filesystem": {
                    "format": "ntfs"
                },
                "mountpoint": null,
                "size": 1021952,
                "start": 297490432,
                "type": "primary",
                "wipe": false
            },
            {
                "ESP": false,
                "PARTUUID": "fbc405de-278f-47fe-ae73-dd9647dfe7da",
                "boot": false,
                "encrypted": true,
                "filesystem": {
                    "format": "ext4",
                    "mount_options": [
                        "compress=zstd"
                    ]
                },
                "mountpoint": "/",
                "size": 202532864,
                "start": 300781568,
                "type": "primary",
                "wipe": false
            }
        ]
    },
    "/dev/sdb": {
        "partitions": [
            {
                "encrypted": true,
                "filesystem": {
                    "format": "ext4"
                },
                "mountpoint": "/home",
                "size": "100%",
                "start": "512MB",
                "type": "primary",
                "wipe": true
            }
        ]
    }
}
```


Discussion:

Resolving patch:
diff --git a/archinstall/lib/disk/blockdevice.py b/archinstall/lib/disk/blockdevice.py
--- a/archinstall/lib/disk/blockdevice.py
+++ b/archinstall/lib/disk/blockdevice.py
@@ -312,4 +312,4 @@ def get_partition(self, uuid :Optional[str] = None, partuuid :Optional[str] = No
 		log(f"Could not find {uuid}/{partuuid} in disk after 5 retries", level=logging.INFO)
 		log(f"Cache: {self.part_cache}")
 		log(f"Partitions: {self.partitions.items()}")
-		raise DiskError(f"New partition {uuid}/{partuuid} never showed up after adding new partition on {self}")
+		raise DiskError(f"Partition {uuid}/{partuuid} was never found on {self} despite several attempts.")
diff --git a/archinstall/lib/disk/filesystem.py b/archinstall/lib/disk/filesystem.py
--- a/archinstall/lib/disk/filesystem.py
+++ b/archinstall/lib/disk/filesystem.py
@@ -77,6 +77,7 @@ def load_layout(self, layout :Dict[str, Any]) -> None:
 					raise KeyError(f"Could not create a MSDOS label on {self}")
 
 			self.blockdevice.flush_cache()
+			time.sleep(3)
 
 		prev_partition = None
 		# We then iterate the partitions in order
@@ -93,9 +94,16 @@ def load_layout(self, layout :Dict[str, Any]) -> None:
 				# TODO: device_instance some times become None
 				# print('Device instance:', partition['device_instance'])
 
-			elif (partition_uuid := partition.get('PARTUUID')) and (partition_instance := self.blockdevice.get_partition(uuid=partition_uuid)):
-				print(_("Re-using partition instance: {}").format(partition_instance))
-				partition['device_instance'] = partition_instance
+			elif (partition_uuid := partition.get('PARTUUID')):
+				# We try to deal with both UUID and PARTUUID of a partition when it's being re-used.
+				# We should re-name or separate this logi based on partition.get('PARTUUID') and partition.get('UUID')
+				# but for now, lets just attempt to deal with both.
+				try:
+					partition['device_instance'] = self.blockdevice.get_partition(uuid=partition_uuid)
+				except DiskError:
+					partition['device_instance'] = self.blockdevice.get_partition(partuuid=partition_uuid)
+				
+				log(_("Re-using partition instance: {}").format(partition['device_instance']), level=logging.DEBUG, fg="gray")
 			else:
 				log(f"{self}.load_layout() doesn't know how to work without 'wipe' being set or UUID ({partition.get('PARTUUID')}) was given and found.", fg="yellow", level=logging.WARNING)
 				continue
@@ -208,6 +216,18 @@ def use_entire_disk(self, root_filesystem_type :str = 'ext4') -> Partition:
 	def add_partition(self, partition_type :str, start :str, end :str, partition_format :Optional[str] = None) -> Partition:
 		log(f'Adding partition to {self.blockdevice}, {start}->{end}', level=logging.INFO)
 
+		if len(self.blockdevice.partitions) == 0:
+			# If it's a completely empty drive, and we're about to add partitions to it
+			# we need to make sure there's a filesystem label.
+			if self.mode == GPT:
+				if not self.parted_mklabel(self.blockdevice.device, "gpt"):
+					raise KeyError(f"Could not create a GPT label on {self}")
+			elif self.mode == MBR:
+				if not self.parted_mklabel(self.blockdevice.device, "msdos"):
+					raise KeyError(f"Could not create a MSDOS label on {self}")
+
+			self.blockdevice.flush_cache()
+
 		previous_partuuids = []
 		for partition in self.blockdevice.partitions.values():
 			try:
@@ -254,9 +274,6 @@ def add_partition(self, partition_type :str, start :str, end :str, partition_for
 				else:
 					log(f"Could not get UUID for partition. Waiting {storage.get('DISK_TIMEOUTS', 1) * count}s before retrying.",level=logging.DEBUG)
 					time.sleep(storage.get('DISK_TIMEOUTS', 1) * count)
-			else:
-				log("Add partition is exiting due to excessive wait time", level=logging.ERROR, fg="red")
-				raise DiskError(f"New partition never showed up after adding new partition on {self}.")
 
 		# TODO: This should never be able to happen
 		log(f"Could not find the new PARTUUID after adding the partition.", level=logging.ERROR, fg="red")


Test patch: