How to get block device of a USB drive attached to a qube using Bash

I’m trying to script mounting/decrypting/dismounting of USB drives.

I’ve been able to get the sys-usb ID, and attach the drive to the qube.

I’m stuck at a reliable way to get the block device of the drive. Any way to do this reliably (this fails too often)?

# Get the drive sd* from last modified match in qube /dev/
# Note:  Potential race condition if /dev/ state change between attach and get last modified file.
drive_sd_=$(qvm-run --pass-io -u root "$target_qube" "ls -lt /dev/sd* | grep -o 'sd.*' | head -n 1")
echo "Drive sd_: $drive_sd_"

P.S. Also having problems getting the /dev/mapper name. If you have any reliable tricks to get that too…

If you attach USB drive in the same script then you can pass the USB PID/VID or drive ID / partition UUID in qvm-run to wait for this device to initialize.

Extracting from qube using ‘sudo blkid’ is what finally worked…

# Get the drive sd*
drive_sd_=$(qvm-run --pass-io -u root "$target_qube" "sudo blkid | grep \"$usb_drive_UUID\" | cut -d: -f1")