From bb1c2559fbe441d8dbb755f841d74f7fa999f1bf Mon Sep 17 00:00:00 2001 From: Michael Marineau Date: Wed, 8 Oct 2014 12:05:45 -0700 Subject: [PATCH] grub_install: work around intermittent missing loopback partitions I am unsure exactly what situation is causing the loopback partition device node to not exist when it is being mounted but this should help work around the situation and log loudly about it so we can hopefully figure out where to dig further. --- build_library/grub_install.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/build_library/grub_install.sh b/build_library/grub_install.sh index b43853fff0..4861369083 100755 --- a/build_library/grub_install.sh +++ b/build_library/grub_install.sh @@ -97,6 +97,25 @@ grub-mkimage \ info "Installing GRUB ${FLAGS_target} to ${FLAGS_disk_image##*/}" LOOP_DEV=$(sudo losetup --find --show --partscan "${FLAGS_disk_image}") ESP_DIR=$(mktemp --directory) + +# work around slow/buggy udev, make sure the node is there before mounting +if [[ ! -b "${LOOP_DEV}p1" ]]; then + # sleep a little just in case udev is ok but just not finished yet + warn "loopback device node ${LOOP_DEV}p1 missing, waiting on udev..." + sleep 0.5 + for (( i=0; i<5; i++ )); do + if [[ -b "${LOOP_DEV}p1" ]]; then + break + fi + warn "looback device node still ${LOOP_DEV}p1 missing, reprobing..." + blockdev --rereadpt ${LOOP_DEV} + sleep 0.5 + done + if [[ ! -b "${LOOP_DEV}p1" ]]; then + failboat "${LOOP_DEV}p1 where art thou? udev has forsaken us!" + fi +fi + sudo mount -t vfat "${LOOP_DEV}p1" "${ESP_DIR}" sudo cp -r "${STAGE_DIR}/." "${ESP_DIR}/."