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 8d81ffa
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,39 @@ set -euo pipefail
# For a description of how this is used see coreos-copy-firstboot-network.service

bootmnt=/mnt/boot_partition
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}"

# 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 we saw races in CI where this didn't seem to always be true:
#
# [ 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.
#
for x in {1..5}; do
if [ -e ${bootdev} ]; then
echo "info: found ${bootdev}"
break
else
echo "info: waiting for ${bootdev} to show up..."
sleep 1
fi
done

# 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
# running alongside other code that also has it mounted ro
mount -o ro /dev/disk/by-label/boot ${bootmnt}
mount -o ro ${bootdev} ${bootmnt}

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 8d81ffa

Please sign in to comment.