Skip to content

Commit 6c8be38

Browse files
[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.
1 parent 52f11e4 commit 6c8be38

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/vm-repair/azext_vm_repair/scripts/linux-mount-encrypted-disk.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ data_os_lvm_check () {
9595
then
9696
#Updaing the below command to use lsblk instead of fdisk for accounting for different distros
9797
#export root_part=`fdisk -l ${data_disk} 2>&1 | grep ^/ |awk '$4 > 60000000{print $1}'` >> ${logpath}/${logfile}
98-
export root_part=`lsblk ${data_disk} -l -n -p -b 2>&1 | grep -w -v ${data_disk} |awk '$4 > 600000000{print $1}'` >> ${logpath}/${logfile}
98+
# Select the largest partition on the data disk (root is always the largest).
99+
# Using sort+head instead of a size threshold to avoid matching /boot partitions
100+
# that exceed 600MB (e.g. Ubuntu 24.04 has a ~913MB /boot on partition 16).
101+
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}')
102+
export root_part
99103
echo "`date` LVM not found on the data disk" >> ${logpath}/${logfile}
100104
echo "`date` The OS partition on the data drive is ${root_part}" >> ${logpath}/${logfile}
101105
else

0 commit comments

Comments
 (0)