Repository: archlinux/archinstall

Issue:
archinstall sets wrong uuid in /etc/default/grub (current arch iso, latest stable archinstall) 2023-08-01
Encrypted install with automatic btrfs partitioning layout. 
Archinstall sets wrong uuid in the "GRUB_CMDLINE_LINUX" in /etc/default/grub
Have to manually set the correct uuid for the system to boot after installation.


Discussion:
Same thing here.
A shell open up after choising Arch Linux in Grub and say that i'm now in a emergency shell. Because the device was not found.

Can you help me too? How did you change de UUID with the correct one?

The output in question:

![20230811_211058.jpg](https://github.com/archlinux/archinstall/assets/82945541/caf11599-ef94-47a2-b696-978ae847b8de)

I installed a ext4 for root with luks encryption too. The partition layout was automatically made also.

I had this issue too during a manual installation using systemd-boot and was not able to resolve it. 
I suggest looking in the arch forums for information and help. 
I was able to boot just by puting the real name of the disk (/dev/<you_luks_disk>) and not with the UUID 

Try this way.
Specifically it's the wrong `cryptdevice` value. I had to change the cryptdevice UUID value to the value from `blkid` in my grub.cfg then grub prompts for a password and mounts the encrypted volume
I believe we've recently reworked the grub installer dealing with this thing: https://github.com/archlinux/archinstall/blob/b1e00687953de168bbc31ea435b2c5bdc7c61e39/archinstall/lib/installer.py#L870-L874

But it's looked the same way for quite a whilte: https://github.com/archlinux/archinstall/blob/57ebc42ffd64babb121c940caa3c5ff415062162/archinstall/lib/installer.py#L907

@svartkanin Perhaps we changed the behavior of `root_partition.uuid`?
This is the last major change to this part of the code https://github.com/archlinux/archinstall/pull/1962/files
Can't say though if it introduced the bug or not
Nah, it still uses the `root_partition.uuid` variable. Doubt it's the logic there.
Is it a case of https://github.com/archlinux/archinstall/blob/b1e00687953de168bbc31ea435b2c5bdc7c61e39/archinstall/lib/disk/device_model.py#L631 not being updated? Once we format a new filesystem on it, the UUID will most likely change.
But it did remove the `rootfstype={root_partition.safe_fs_type.value}` part, not sure if that will have an impact
Ah yea, but it gets added a bit later: https://github.com/codefiles/archinstall/blob/6f3ceea9eea2ce2baaeca1a5ec91d73272e890e5/archinstall/lib/installer.py#L870 *(edited wrong link before)*

The rework was to separate the logic of appending options a bit.
Ahh right, missed that. 
For the UUID, we run a `partprobe` just after the creation https://github.com/svartkanin/archinstall/blob/47cde37edc1caf601225ae1ffdc6ac326039c9dd/archinstall/lib/disk/device_handler.py#L358-L358 which "should" update it? 
I got this figured out and am working on a fix. About to update this comment with more information.

An attempt to acquire the UUID is made during partitioning but a UUID will not be available until after formatting, so it will be `None` here.

https://github.com/archlinux/archinstall/blob/b1e00687953de168bbc31ea435b2c5bdc7c61e39/archinstall/lib/disk/device_handler.py#L358-L361

This just needs to be done after formatting and it should work.
Well spotted @codefiles! I'm rounding up for a release in the next couple of days and this is probably one of the last few that really needs to go in :D

Resolving patch:
diff --git a/archinstall/lib/disk/device_handler.py b/archinstall/lib/disk/device_handler.py
--- a/archinstall/lib/disk/device_handler.py
+++ b/archinstall/lib/disk/device_handler.py
@@ -291,6 +291,11 @@ def format(
 			else:
 				self._perform_formatting(part_mod.safe_fs_type, part_mod.safe_dev_path)
 
+			lsblk_info = self._fetch_part_info(part_mod.safe_dev_path)
+
+			part_mod.partuuid = lsblk_info.partuuid
+			part_mod.uuid = lsblk_info.uuid
+
 	def _perform_partitioning(
 		self,
 		part_mod: PartitionModification,
@@ -354,15 +359,10 @@ def _perform_partitioning(
 
 			# the partition has a real path now as it was created
 			part_mod.dev_path = Path(partition.path)
-
-			lsblk_info = self._fetch_partuuid(part_mod.dev_path)
-
-			part_mod.partuuid = lsblk_info.partuuid
-			part_mod.uuid = lsblk_info.uuid
 		except PartitionException as ex:
 			raise DiskError(f'Unable to add partition, most likely due to overlapping sectors: {ex}') from ex
 
-	def _fetch_partuuid(self, path: Path) -> LsblkInfo:
+	def _fetch_part_info(self, path: Path) -> LsblkInfo:
 		attempts = 3
 		lsblk_info: Optional[LsblkInfo] = None
 
@@ -371,16 +371,24 @@ def _fetch_partuuid(self, path: Path) -> LsblkInfo:
 			time.sleep(attempt_nr + 1)
 			lsblk_info = get_lsblk_info(path)
 
-			if lsblk_info.partuuid:
+			if lsblk_info.partuuid and lsblk_info.uuid:
 				break
 
 			self.partprobe(path)
 
-		if not lsblk_info or not lsblk_info.partuuid:
+		if not lsblk_info:
+			debug(f'Unable to get partition information: {path}')
+			raise DiskError(f'Unable to get partition information: {path}')
+
+		if not lsblk_info.partuuid:
 			debug(f'Unable to determine new partition uuid: {path}\n{lsblk_info}')
 			raise DiskError(f'Unable to determine new partition uuid: {path}')
 
-		debug(f'partuuid found: {lsblk_info.json()}')
+		if not lsblk_info.uuid:
+			debug(f'Unable to determine new uuid: {path}\n{lsblk_info}')
+			raise DiskError(f'Unable to determine new uuid: {path}')
+
+		debug(f'partition information found: {lsblk_info.json()}')
 
 		return lsblk_info
 
diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py
--- a/archinstall/lib/installer.py
+++ b/archinstall/lib/installer.py
@@ -8,8 +8,6 @@
 from pathlib import Path
 from typing import Any, List, Optional, TYPE_CHECKING, Union, Dict, Callable
 
-from ..lib.disk.device_model import get_lsblk_info
-
 from . import disk
 from .exceptions import DiskError, ServiceException, RequirementError, HardwareIncompatibilityError, SysCallError
 from .general import SysCommand
@@ -937,9 +935,7 @@ def _add_limine_bootloader(
 		self.pacman.strap('limine')
 		info(f"Limine boot partition: {boot_partition.dev_path}")
 
-		# XXX: We cannot use `root_partition.uuid` since corresponds to the UUID of the root
-		#      partition before the format.
-		root_uuid = get_lsblk_info(root_partition.safe_dev_path).uuid
+		root_uuid = root_partition.uuid
 
 		def create_pacman_hook(contents: str):
 			HOOK_DIR = "/etc/pacman.d/hooks"


Test patch: