git.iko.soy/typeable/nixpkgs
on master help sign in
nixos stage-1: factor device waiting into a function
commit59aa3bb5c84a8d2cfe8d27170bd826499710036e authorNikolay Amiantov <ab@fmap.me> dateMon 8 Aug 2016, 01:32 (10 years ago) parent9cc70b4
1 file changed+32−23
nixos/modules/system/boot/stage-1-init.sh+32−23
nixos/modules/system/boot/stage-1-init.sh+32−23
@@ -352,6 +352,33 @@ mountFS() {
352352}
353353
354354
355+# Function for waiting a device to appear.
356+waitDevice() {
357+ local device="$1"
358+
359+ # USB storage devices tend to appear with some delay. It would be
360+ # great if we had a way to synchronously wait for them, but
361+ # alas... So just wait for a few seconds for the device to
362+ # appear.
363+ if test ! -e $device; then
364+ echo -n "waiting for device $device to appear..."
365+ try=20
366+ while [ $try -gt 0 ]; do
367+ sleep 1
368+ # also re-try lvm activation now that new block devices might have appeared
369+ lvm vgchange -ay
370+ # and tell udev to create nodes for the new LVs
371+ udevadm trigger --action=add
372+ if test -e $device; then break; fi
373+ echo -n "."
374+ try=$((try - 1))
375+ done
376+ echo
377+ [ $try -ne 0 ]
378+ fi
379+}
380+
381+
355382# Try to find and mount the root device.
356383mkdir -p $targetRoot
357384
@@ -384,29 +411,11 @@ while read -u 3 mountPoint; do
384411 ;;
385412 esac
386413
387− # USB storage devices tend to appear with some delay. It would be
388− # great if we had a way to synchronously wait for them, but
389− # alas... So just wait for a few seconds for the device to
390− # appear. If it doesn't appear, try to mount it anyway (and
391− # probably fail). This is a fallback for non-device "devices"
392− # that we don't properly recognise.
393− if test -z "$pseudoDevice" -a ! -e $device; then
394− echo -n "waiting for device $device to appear..."
395− try=20
396− while [ $try -gt 0 ]; do
397− sleep 1
398− # also re-try lvm activation now that new block devices might have appeared
399− lvm vgchange -ay
400− # and tell udev to create nodes for the new LVs
401− udevadm trigger --action=add
402− if test -e $device; then break; fi
403− echo -n "."
404− try=$((try - 1))
405− done
406− echo
407− if [ $try -eq 0 ]; then
408− echo "Timed out waiting for device $device, trying to mount anyway."
409− fi
414+ if test -z "$pseudoDevice" && ! waitDevice "$device"; then
415+ # If it doesn't appear, try to mount it anyway (and
416+ # probably fail). This is a fallback for non-device "devices"
417+ # that we don't properly recognise.
418+ echo "Timed out waiting for device $device, trying to mount anyway."
410419 fi
411420
412421 # Wait once more for the udev queue to empty, just in case it's