Skip to content

fix(#4182): detect pre-mounted encrypted root partitions - #4873

Open
devpryan7792 wants to merge 1 commit into
archlinux:masterfrom
devpryan7792:fix/pre-mounted-encrypted-root-detection
Open

devpryan7792 wants to merge 1 commit into
archlinux:masterfrom
devpryan7792:fix/pre-mounted-encrypted-root-detection

Conversation

@devpryan7792

Copy link
Copy Markdown

Problem

When performing an installation with an encrypted (LUKS) root partition using the pre-mounted configuration (DiskLayoutType.Pre_mount), archinstall aborts with:
Invalid configuration: root partition not found
even when the encrypted container has been opened, formatted, and mounted to /mnt (Closes #4182).

Root Cause

  1. In a pre-mounted LUKS configuration (e.g. /dev/nvme0n1p2 opened as /dev/mapper/encrypted_p2 and mounted at /mnt), lsblk outputs mountpoints: [] on the raw parent partition node /dev/nvme0n1p2, placing the active mountpoint ['/mnt'] on the decrypted child node (type="crypt").
  2. _PartitionInfo.from_partition() in archinstall/lib/models/device.py only copied mountpoints=lsblk_info.mountpoints, leaving part_info.mountpoints empty.
  3. _determine_fs_type() in archinstall/lib/disk/device_handler.py only checked lsblk_info.fstype, returning FilesystemType.CRYPTO_LUKS rather than the actual filesystem (e.g. ext4, btrfs) residing inside the mapped container.
  4. Consequently, detect_pre_mounted_mods(base_mountpoint=Path('/mnt')) skipped the partition because part_info.mountpoints was empty, excluding the root partition from device_modifications.
  5. In global_menu.py:487, if root_partition is None: failed configuration validation with "Root partition not found".
  6. Furthermore, during bootloader configuration (installer.py:_get_kernel_params_partition), if the root partition was encrypted via pre-mount, root_partition in self._disk_encryption.partitions evaluated to False (since disk_config.disk_encryption is not configured through the interactive partitioning menu), generating unbootable root=PARTUUID=... kernel arguments without cryptdevice= and omitting the encrypt hook in mkinitcpio.

Fix

  1. LsblkInfo (archinstall/lib/models/device.py):
    • Added all_mountpoints property to recursively collect mountpoints across child block devices.
    • Added find_child_by_type(device_type) to resolve child devices (e.g. type == 'crypt').
  2. _PartitionInfo & PartitionModification (archinstall/lib/models/device.py):
    • Added is_encrypted: bool = False and mapper_name: str | None = None.
    • In _PartitionInfo.from_partition(), detect is_encrypted and extract mapper_name from any crypt child. Fall back to lsblk_info.all_mountpoints when lsblk_info.mountpoints is empty.
    • Propagate is_encrypted and mapper_name into PartitionModification.from_existing_partition().
    • Allow setting/preserving explicit mapper names on PartitionModification (falling back to 'root', 'home', or ainst<name>).
  3. DeviceHandler (archinstall/lib/disk/device_handler.py):
    • In _determine_fs_type(), inspect the decrypted crypt child's fstype when present so filesystems inside opened LUKS containers are correctly identified.
    • In get_btrfs_info(), resolve the crypt child device when Btrfs resides on LUKS, reading subvolumes without attempting to mount raw encrypted partitions.
  4. Installer (archinstall/lib/installer.py):
    • In minimal_installation(), check if part in self._disk_encryption.partitions or part.is_encrypted: so the encrypt hook is added to mkinitcpio for pre-mounted encrypted setups.
    • In _get_kernel_params_partition(), include or root_partition.is_encrypted and use root_partition.mapper_name or 'root' to correctly format cryptdevice=PARTUUID=...:<mapper_name> and root=/dev/mapper/<mapper_name>.

Tests

Added tests/test_pre_mount.py:

  • test_lsblk_all_mountpoints_and_find_child: verifies recursive mountpoint aggregation and crypt child discovery.
  • test_determine_fs_type_crypto_luks: verifies ext4 detection on opened LUKS partitions.
  • test_determine_fs_type_crypto_luks_btrfs: verifies btrfs detection on opened LUKS partitions.
  • test_detect_pre_mounted_encrypted_root: end-to-end detection of pre-mounted /boot (FAT32) and / (LUKS + ext4) at /mnt, verifying is_root() == True, mountpoint == Path('/'), is_encrypted == True, and mapper_name == 'encrypted_p2'.
  • test_detect_pre_mounted_encrypted_btrfs_root: verifies subvolume detection and mountpoint mapping for pre-mounted Btrfs on LUKS.
  • test_kernel_params_pre_mounted_encrypted_root: verifies correct cryptdevice= and root=/dev/mapper/<mapper_name> kernel parameters.

All 40 unit tests pass locally with pytest tests. Formatting verified with ruff check and ruff format.

AI Usage Disclosure

Assisted with root cause analysis and test harness drafting using Google Antigravity. All changes, architecture paths, and test cases were thoroughly verified and reviewed by the author.

@devpryan7792
devpryan7792 requested a review from Torxed as a code owner November 10, 2026 11:38

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid configuration: root partition not found” with encrypted root, even when root is correctly mounted

1 participant