You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 22.04从suspend唤醒后系统时间偏差5½小时的问题求助

Ubuntu 22.04从suspend唤醒后系统时间偏差5½小时的问题求助

Hey Neeraj,我看到你遇到了Ubuntu 22.04从休眠唤醒后时间不准的问题,偏差刚好5个半小时,而且错误时间比GMT快11小时,先别着急,我给你几个可行的解决方案试试:

  • 先检查NTP时间同步服务状态:休眠唤醒后,系统自带的时间同步服务可能没有自动恢复工作。你可以先运行sudo systemctl status systemd-timesyncd查看服务状态,如果显示未运行,就用sudo systemctl enable --now systemd-timesyncd启动并设置开机自启,之后再执行sudo timedatectl set-ntp true强制同步一次时间,看看唤醒后是否能自动纠正。

  • 检查硬件时钟(RTC)的时区设置:有时候系统时钟和硬件时钟的时区不一致会导致这类问题。运行timedatectl查看输出里的RTC相关信息,确认硬件时钟是使用UTC还是本地时间。Ubuntu通常推荐使用UTC,你可以用sudo timedatectl set-local-rtc 0把硬件时钟设置为UTC;如果你的场景需要本地时间,就改成sudo timedatectl set-local-rtc 1,设置后重启再测试休眠唤醒的情况。

  • 给休眠唤醒添加自动时间同步脚本:如果上面的方法没效果,我们可以做一个自动触发的同步机制。具体步骤如下:

    1. 创建同步脚本:sudo nano /usr/local/bin/wakeup-time-sync.sh,写入内容:
      #!/bin/bash
      timedatectl set-ntp true
      sleep 2
      timedatectl status
      
    2. 给脚本加执行权限:sudo chmod +x /usr/local/bin/wakeup-time-sync.sh
    3. 创建systemd服务文件:sudo nano /etc/systemd/system/wakeup-time-sync.service,写入内容:
      [Unit]
      Description=Sync time on system wakeup
      After=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
      
      [Service]
      Type=oneshot
      ExecStart=/usr/local/bin/wakeup-time-sync.sh
      
      [Install]
      WantedBy=suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
      
    4. 启用服务:sudo systemctl enable wakeup-time-sync.service,这样每次从休眠唤醒时,系统就会自动执行时间同步了。
  • 更新系统内核和电源管理组件:有些时候这类问题是内核或电源管理包的bug导致的,你可以运行sudo apt update && sudo apt upgrade -y把系统所有包更新到最新版本,重启后再测试休眠唤醒的时间情况。

你可以先从第一个方法开始尝试,逐步排查,应该能解决这个问题的。

备注:内容来源于stack exchange,提问作者Neeraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 11:33:12