Skip to content

Commit c92b979

Browse files
committed
00-check-rtc-and-wait-ntp.sh: change the file used to read the modification time from the script itself to user-data
Signed-off-by: Norio Nomura <[email protected]>
1 parent 0539eb6 commit c92b979

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/cidata/cidata.TEMPLATE.d/boot/00-check-rtc-and-wait-ntp.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ until ntp_synchronized=$(timedatectl show --property=NTPSynchronized --value) &&
2121
if [ "${retry}" -eq 0 ]; then
2222
# If /dev/rtc is not available, the system time set during the Linux kernel build is used.
2323
# The larger the difference between this system time and the NTP server time, the longer the NTP synchronization will take.
24-
# By setting the system time to the modification time of this script, which is likely to be closer to the actual time,
24+
# By setting the system time to the modification time of the reference file, which is likely to be closer to the actual time,
25+
reference_file="${LIMA_CIDATA_MNT:-/mnt/lima-cidata}/user-data"
26+
[ -f "${reference_file}" ] || reference_file="${0}"
27+
2528
# the NTP synchronization time can be shortened.
26-
echo_with_time_usec "Setting the system time to the modification time of ${0}."
29+
echo_with_time_usec "Setting the system time to the modification time of ${reference_file}."
2730

2831
# To set the time to a specified time, it is necessary to stop systemd-timesyncd.
2932
systemctl stop systemd-timesyncd
@@ -35,8 +38,8 @@ until ntp_synchronized=$(timedatectl show --property=NTPSynchronized --value) &&
3538
sleep 1
3639
done
3740

38-
# Set the system time to the modification time of this script.
39-
modification_time=$(stat -c %y "${0}")
41+
# Set the system time to the modification time of the reference file.
42+
modification_time=$(stat -c %y "${reference_file}")
4043
echo_with_time_usec "Setting the system time to ${modification_time}."
4144
timedatectl set-time "${modification_time}"
4245

0 commit comments

Comments
 (0)