[vm-repair] Fix unlock failure on Ubuntu 24.04 ADE-encrypted VMs#9907
[vm-repair] Fix unlock failure on Ubuntu 24.04 ADE-encrypted VMs#9907msaenzbosupport wants to merge 1 commit into
Conversation
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Hi @msaenzbosupport, |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Linux encrypted disk mounting helper to more reliably detect the OS/root partition on distros where /boot may exceed the previous size threshold.
Changes:
- Replace a fixed size threshold partition selection with “largest partition wins”.
- Add clarifying comments explaining why the selection logic changed.
| # Select the largest partition on the data disk (root is always the largest). | ||
| # Using sort+head instead of a size threshold to avoid matching /boot partitions | ||
| # that exceed 600MB (e.g. Ubuntu 24.04 has a ~913MB /boot on partition 16). | ||
| export root_part=`lsblk ${data_disk} -l -n -p -b 2>&1 | grep -w -v ${data_disk} | sort -k4 -rn | awk 'NR==1{print $1}'` >> ${logpath}/${logfile} |
| # Select the largest partition on the data disk (root is always the largest). | ||
| # Using sort+head instead of a size threshold to avoid matching /boot partitions | ||
| # that exceed 600MB (e.g. Ubuntu 24.04 has a ~913MB /boot on partition 16). | ||
| export root_part=`lsblk ${data_disk} -l -n -p -b 2>&1 | grep -w -v ${data_disk} | sort -k4 -rn | awk 'NR==1{print $1}'` >> ${logpath}/${logfile} |
Re: Copilot review commentsThanks for the review. Both observations about # Original line (before this PR):
export root_part=lsblk ${data_disk} -l -n -p -b 2>&1 | grep -w -v ${data_disk} |awk '$4 > 600000000{print $1}'` >> ${logpath}/${logfile}The scope of this PR is intentionally limited to fixing the partition selection logic (threshold → largest partition) to unblock Ubuntu 24.04 ADE unlock. Refactoring the logging/quoting patterns across the entire script would be a separate effort. Re: HISTORY.rst / setup.pyThis change only affects a shell script that runs inside the repair VM via |
The root partition detection in data_os_lvm_check uses a 600MB size threshold to filter partitions. Ubuntu 24.04 has a ~913MB /boot partition (partition 16) that also exceeds this threshold, causing root_part to capture two partitions instead of one. This results in cryptsetup receiving an invalid device name argument: cryptsetup luksOpen ... /dev/sdb1 /dev/sdb16 osencrypt instead of: cryptsetup luksOpen ... /dev/sdb1 osencrypt The error manifests as: Device sdb16 not found Cannot use device /dev/sdb16, name is invalid or still in use. Fix: Replace the fixed-threshold filter with a sort-by-size approach that selects only the largest partition (which is always the root partition). This is future-proof against /boot partition size changes. Additional improvements per review feedback: - Use $() instead of backticks for command substitution - Redirect stderr to logfile instead of capturing into the variable - Quote variables to prevent word-splitting issues - Separate export from assignment for clarity Tested on Ubuntu 24.04 Gen 1 and Gen 2 with ADE encryption - unlock now succeeds. Also verified no regression on Ubuntu 20.04 and 22.04.
65b5286 to
6c8be38
Compare
|
vm-repair |
Description
Fix
az vm repair create --unlock-encrypted-vmfailing on Ubuntu 24.04 ADE-encrypted VMs.Problem
The
data_os_lvm_checkfunction inlinux-mount-encrypted-disk.shidentifies the root partition by filtering partitions larger than 600MB:Ubuntu 24.04 introduced a ~913MB /boot partition (partition 16, ext4, LABEL=BOOT). This partition exceeds the 600MB threshold, causing
root_partto capture two values instead of one:When
unlock_rootpasses this tocryptsetup, the command becomes:Where
/dev/sdb16is interpreted as the mapper name instead ofosencrypt, producing:Partition layout comparison
Fix
Replace the fixed-threshold filter with a sort-by-size approach that selects only the largest partition (always root):
This is future-proof against boot partition size changes in newer distro versions.
Testing
Affected file
src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh