github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/build/disable-hyperv-timesync.sh (about) 1 #!/usr/bin/env bash 2 3 set -euxo pipefail 4 5 # Disabling hyper-v time synchronization means unbinding the device. 6 # To find the device, one can use: 7 # $ curl -O https://raw.githubusercontent.com/torvalds/linux/master/tools/hv/lsvmbus 8 # $ python lsvmbus -vv | grep -w "Time Synchronization" -A 3 9 # VMBUS ID 11: Class_ID = {9527e630-d0ae-497b-adce-e80ab0175caf} - [Time Synchronization] 10 # Device_ID = {2dd1ce17-079e-403c-b352-a1921ee207ee} 11 # Sysfs path: /sys/bus/vmbus/devices/2dd1ce17-079e-403c-b352-a1921ee207ee 12 # Rel_ID=11, target_cpu=0 13 # echo 2dd1ce17-079e-403c-b352-a1921ee207ee | sudo tee /sys/bus/vmbus/drivers/hv_util/unbind 14 15 # According to lsvmbus, the time sync class ID is: 16 TIME_SYNC_CLASS_ID='{9527e630-d0ae-497b-adce-e80ab0175caf}' 17 18 # hv bus devices are all listed under: 19 VMBUS_DIR=/sys/bus/vmbus/devices 20 21 # Each device folder contains many plaintext files, including: 22 CLASS_ID_FILE=class_id 23 24 # The device can be unbound by writing its ID to: 25 UNBIND_PATH=/sys/bus/vmbus/drivers/hv_util/unbind 26 27 if ! full_path=$(grep ${TIME_SYNC_CLASS_ID} ${VMBUS_DIR}/*/${CLASS_ID_FILE}); then 28 echo 'Time sync device not found' 29 exit 1 30 fi 31 dev_id=$(echo "${full_path}" | cut -d/ -f6) 32 33 if ! echo -n "${dev_id}" | sudo tee ${UNBIND_PATH} > /dev/null; then 34 echo 'Time sync device already unbound, or error encountered.' 35 fi 36 37 # Force an NTP time sync. 38 sudo apt-get -qqy update 39 sudo apt-get -qqy install ntpdate 40 # Disable systemd-timesyncd 41 sudo timedatectl set-ntp false 42 if systemctl is-active -q ntp.service; then 43 sudo service ntp stop 44 sudo ntpdate -b ntp.ubuntu.com 45 sudo service ntp start 46 else 47 sudo ntpdate -b ntp.ubuntu.com 48 # Reenable systemd-timesyncd. 49 sudo timedatectl set-ntp true 50 fi