From 6c8be38ca84ce816e9afd85820405480e4180b5b Mon Sep 17 00:00:00 2001 From: Mauricio Saenz Date: Fri, 29 May 2026 12:02:07 -0600 Subject: [PATCH] [vm-repair] Fix unlock failure on Ubuntu 24.04 ADE-encrypted VMs 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. --- .../azext_vm_repair/scripts/linux-mount-encrypted-disk.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh b/src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh index 9f6c90a0d53..68e5184a146 100644 --- a/src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh +++ b/src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh @@ -95,7 +95,11 @@ data_os_lvm_check () { then #Updaing the below command to use lsblk instead of fdisk for accounting for different distros #export root_part=`fdisk -l ${data_disk} 2>&1 | grep ^/ |awk '$4 > 60000000{print $1}'` >> ${logpath}/${logfile} - export root_part=`lsblk ${data_disk} -l -n -p -b 2>&1 | grep -w -v ${data_disk} |awk '$4 > 600000000{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). + root_part=$(lsblk "${data_disk}" -l -n -p -b 2>>"${logpath}/${logfile}" | grep -w -v "${data_disk}" | sort -k4 -rn | awk 'NR==1{print $1}') + export root_part echo "`date` LVM not found on the data disk" >> ${logpath}/${logfile} echo "`date` The OS partition on the data drive is ${root_part}" >> ${logpath}/${logfile} else