This snippet seems to reproduce the issue for me sporadically, and much simpler than the attached script. It assumes there is a filesystem already on /dev/vdb1 and /dev/vdb is partitioned already.
sudo sh -c 'd=$1; p=${d}1; mp=/mnt; cleanup() { umount $mp >/dev/null 2>&1; } ; trap cleanup EXIT; umount $p >/dev/null 2>&1; while : ; do mount $p $mp && umount $mp && sfdisk --re-read $d|| exit 1; echo -n .; done' -- /dev/vdb
This snippet seems to reproduce the issue for me sporadically, and much simpler than the attached script. It assumes there is a filesystem already on /dev/vdb1 and /dev/vdb is partitioned already.
sudo sh -c 'd=$1; p=${d}1; mp=/mnt; cleanup() { umount $mp >/dev/null 2>&1; } ; trap cleanup EXIT; umount $p >/dev/null 2>&1; while : ; do mount $p $mp && umount $mp && sfdisk --re-read $d|| exit 1; echo -n .; done' -- /dev/vdb