Q:

Waiting for /dev/disk/by-label to be populated after SD insertion

I have a bash script doing some initialization on a removable SD card (problem would be the same for any removable storage, I think). Specific behavior depends on card formatting, specifically on fs labels available.
In order to do so I need to request SD insertion and then wait for udev to pick up and populate /dev/*
I can try to speed-up things by explicitly calling partprobe, but I still have to wait (sometime up to 10s!) to get /dev/by-label/ subdir to be populated.
How can I speed up this?
Is there some way to explicitly trigger udev and wait for completion?

A:

A very crude bash script mat be as follows:
sudo partprobe
count=0
while [ ! -L /dev/disk/by-label/root ]
do
    if ((count > 10))
    then
        echo "ERROR: unable to find root's label!"
        exit 1
    fi
    sleep 1
    count=$((count++))
done

Feel free to improve.

