blob: 8247379b8f32d9de7904e88f6aa094b460a0299c [file]
#!/bin/bash
rwdir="/run/initramfs/rw"
# If systemd bind-mounted a transient machine-id early on, we must unmount it
# BEFORE etc.mount happens, otherwise it will be hidden and cause confusion.
if grep -q " /etc/machine-id " /proc/self/mounts; then
echo "Unmounting early transient /etc/machine-id"
umount /etc/machine-id
fi
# We just ensure the machine-id is in the cow so that etc.mount picks it up.
if ! [[ -e "$rwdir"/cow/etc/machine-id ]]; then
echo "Populating /etc/machine-id in COW" >&2
mkdir -p "$rwdir"/cow/etc
# Try to read the current one
cp /run/machine-id "$rwdir"/cow/etc/ || exit
fi
# Opportunisticly set a sane BMC date based on a file that gets
# written right before rebooting or powercycling. If none exists,
# use the image build date.
for file in "$rwdir"/cow/{var/lib/systemd/random-seed,etc/os-release}; do
[ -e "$file" ] || continue
now_approx=$(stat -c %Y "$file") || continue
# Only update time if it's older than the file
if [ "$(date +%s)" -lt "$now_approx" ]; then
echo "Setting time from file $file: $now_approx" >&2
date -s @$((now_approx + 5)) || true
fi
done