Ubuntu – Udevadm settle not working

18.04encryptionlvmmount

I just upgraded to 18.04 on my NAS. I have a script that prompts my user for a luks password and then mounts the drive after it's decrypted. This used to work:

cryptsetup luksOpen /dev/md0 md0_crypt
udevadm settle --exit-if-exists=/dev/mapper/files--vg-main
mount /dev/mapper/files--vg-main /main

However after updating to 18.04 this stopped working and I get: mount: /main: special device /dev/mapper/files--vg-main does not exist.

I have not found a solution just googling. My LUKS container is my pv. I have it in a Vol group called files-vg. I then have one logical volume with a path /dev/files-vg/main. Hence why I'm looking for /dev/mapper/files–vg-main

Edit: To clarify, the udevadm settle line does not wait long enough for the LV to become available so the mount fails. I can manually call mount and it will work afterward.

Best Answer

Here's an ugly workaround that I don't have a LUKS container to test on:

udevadm info /dev/mapper/files--vg-main

Where /dev/mapper/files--vg-main is the device you are checking for. if [ $? -eq 0 ] then the command was successful meaning the device exists and you can mount it.

else you'd have to loop and check again.

As a side note you can find some useful udev debugging ideas on this page.

Related Question