Skip to content

Commit

Permalink
overlay: 15coreos-copy-firstboot-network: handle race condition
Browse files Browse the repository at this point in the history
Add short while loop to handle a race condition where
After=dev-disk-by\x2dlabel-boot.device doesn't seem to be sufficient
always.
  • Loading branch information
dustymabe committed Apr 17, 2020
1 parent f9afb84 commit 1d881ac
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,48 @@ set -euo pipefail
# For a description of how this is used see coreos-copy-firstboot-network.service

bootmnt=/mnt/boot_partition
mkdir -p ${bootmnt}
bootdev=/dev/disk/by-label/boot
firstboot_network_dir_basename="coreos-firstboot-network"
initramfs_firstboot_network_dir="${bootmnt}/${firstboot_network_dir_basename}"
initramfs_network_dir="/run/NetworkManager/system-connections/"
realroot_firstboot_network_dir="/boot/${firstboot_network_dir_basename}"

# Mount /boot. Note that we mount /boot but we don't unmount boot because we
# are run in a systemd unit with MountFlags=slave so it is unmounted for us.
mkdir -p ${bootmnt}
# mount as read-only since we don't strictly need write access and we may be
# Mount as read-only since we don't strictly need write access and we may be
# running alongside other code that also has it mounted ro
mount -o ro /dev/disk/by-label/boot ${bootmnt}
mountboot() {
# Wait for up to 5 seconds for the boot device to be available
# The After=...*boot.device in the systemd unit should be enough
# but there appears to be some race in the kernel where the link under
# /dev/disk/by-label exists but mount is not able to use the device yet.
# We saw errors like this in CI:
#
# [ 4.045181] systemd[1]: Found device /dev/disk/by-label/boot.
# [ OK ] Found device /dev/disk/by-label/boot
# [ 4.051500] systemd[1]: Starting Copy CoreOS Firstboot Networking Config...
# Starting Copy CoreOS Firstboot Networking Config
# [ 4.060573] vda: vda1 vda2 vda3 vda4
# [ 4.063296] coreos-copy-firstboot-network[479]: mount: /mnt/boot_partition: special device /dev/disk/by-label/boot does not exist.
#
mounted=0
for x in {1..5}; do
if mount -o ro ${bootdev} ${bootmnt}; then
echo "info: ${bootdev} successfully mounted."
mounted=1
break
else
echo "info: retrying ${bootdev} mount in 1 second..."
fi
done
if [ "${mounted}" == "0" ]; then
echo "error: ${bootdev} mount did not succeed" 1>&2
return 1
fi
}

mountboot || exit 1

if [ -n "$(ls -A ${initramfs_firstboot_network_dir} 2>/dev/null)" ]; then
# Clear out any files that may have already been generated from
Expand Down

0 comments on commit 1d881ac

Please sign in to comment.