菜鸟笔记--linux系统移植之[FAILED] Failed to start Network Time Synchronization. 问题解决

在进行debian根文件系统移植时遇到启动报错,主要问题集中在'Failed to start Network Time Synchronization.'和'Failed to start Hostname Service.'。错误原因是因为'/var/'目录下缺少'tmp'文件夹。解决方案包括重新完整复制根文件系统或手动创建'/var/tmp'目录。执行后,问题得到解决,系统启动正常。

最近在进行debian根文件系统移植时,参考网上的例子使用debootstrap抽取了一个debian stretch根文件系统,之后得到了一个文件夹。
在这里插入图片描述
但是当我使用指令,将根文件系统下的所有内容复制到SD卡分区时,开机启动开发板,出现如下报警。

[FAILED] Failed to start Network Time Synchronization.
See 'systemctl status systemd-timesyncd.service' for details.
[  OK  ] Reached target System Time Synchronized.
[  OK  ] Stopped Network Time Synchronization.
[FAILED] Failed to start Network Time Synchronization.
See 'systemctl status systemd-timesyncd.service' for details.
[  OK  ] Started Update UTMP about System Boot/Shutdown.
[  OK  ] Stopped Network Time Synchronization.
[FAILED] Failed to start Network Time Synchronization.
See 'systemctl status systemd-timesyncd.service' for details.
[  OK  
<think>我们正在解决Ubuntu系统中由于时间同步导致的仓库更新失败问题,具体错误是"Failed to set time: Automatic time synchronization is enabled"。这个错误通常发生在尝试手动设置时间但系统已启用自动时间同步时。以下是系统化的解决方案: ### 问题原因 1. **自动时间同步已启用**:当`systemd-timesyncd`或`ntpd`等服务正在运行时,手动使用`timedatectl set-time`命令会被阻止[^1]。 2. **时间服务冲突**:多个时间同步服务同时运行(如`ntp`和`systemd-timesyncd`)可能导致冲突。 3. **系统时间保护**:某些系统配置(如只读文件系统)可能阻止时间修改。 ### 解决方案 #### 步骤1:检查时间同步服务状态 ```bash timedatectl status ``` 查看输出中的`System clock synchronized`和`NTP service`状态。如果显示`yes`和`active`,说明自动同步已启用。 #### 步骤2:临时禁用自动时间同步 若要手动设置时间,需先禁用自动同步: ```bash sudo timedatectl set-ntp false ``` #### 步骤3:手动设置时间(可选) 如果需要立即修正时间(例如偏差很大): ```bash sudo timedatectl set-time "2024-07-12 15:30:00" ``` #### 步骤4:重新启用自动同步 手动设置后恢复自动同步: ```bash sudo timedatectl set-ntp true ``` #### 步骤5:强制同步网络时间(推荐) 使用`ntpdate`强制同步(安装后使用): ```bash sudo apt install ntpdate -y sudo ntpdate ntp.aliyun.com ``` #### 步骤6:验证时间状态 ```bash timedatectl ``` 确认输出中: - 时间正确 - `NTP enabled: yes` - `System clock synchronized: yes` ### 特殊场景处理 - **如果步骤2报错**:可能是其他时间服务(如`chrony`)在运行。停止相关服务: ```bash sudo systemctl stop chrony.service sudo timedatectl set-ntp false # 再试一次 ``` - **只读文件系统(如嵌入式设备)**:需重新挂载为可写: ```bash sudo mount -o remount,rw / ``` ### 修复验证 重新运行更新命令应成功: ```bash sudo apt update ``` ### 长期解决方案 1. **配置可靠NTP服务器**: ```bash # 编辑systemd-timesyncd配置 sudo nano /etc/systemd/timesyncd.conf ``` 修改为: ```ini [Time] NTP=ntp.aliyun.com ``` 重启服务: ```bash sudo systemctl restart systemd-timesyncd ``` 2. **检查时区设置**: ```bash timedatectl list-timezones | grep Shanghai # 查找正确时区 sudo timedatectl set-timezone Asia/Shanghai ``` > **注意**:在Docker容器中,时间通常继承自主机。若需独立设置,启动时添加`-v /etc/localtime:/etc/localtime:ro`[^2]。 --- ### 相关问题 1. 如何查看Ubuntu中正在运行的NTP服务? 2. `systemd-timesyncd`和`chrony`有什么区别? 3. 如何在Ubuntu服务器上配置多个NTP服务器? 4. Docker容器时间与宿主机不一致如何解决? 5. 嵌入式Linux设备时间同步的最佳实践是什么? [^1]: 参考`timedatectl`手册页:手动设置时间需禁用NTP [^2]: Docker时间同步方案参考容器启动命令</think>### 解决 Ubuntu 时间同步错误:"Failed to set time Automatic time synchronization is enabled" 当系统提示**"Failed to set time: Automatic time synchronization is enabled"**时,表明您尝试手动修改时间但系统已启用自动时间同步服务。以下是系统解决方案: --- #### 错误原因分析 1. **自动时间同步服务冲突** `systemd-timesyncd`或`chrony`等NTP服务正在运行,阻止手动修改时间[^1]。 2. **权限限制** 普通用户尝试修改系统时间(需root权限)。 3. **服务配置冲突** 多个时间同步服务同时运行(如`systemd-timesyncd`和`ntpd`)。 --- #### 解决方案步骤 ##### 1. 检查时间同步服务状态 ```bash timedatectl status ``` 查看关键字段: ```text System clock synchronized: yes # 表示时间同步正常 NTP service: active # 表示自动同步已启用 ``` ##### 2. 临时禁用自动同步(如需手动设置时间) ```bash sudo timedatectl set-ntp false # 禁用自动同步 sudo timedatectl set-time "2024-07-12 15:30:00" # 设置指定时间 sudo timedatectl set-ntp true # 操作后重新启用 ``` ##### 3. 强制同步网络时间 ```bash # 安装时间同步工具 sudo apt install ntpdate -y # 使用阿里云NTP服务器强制同步 sudo ntpdate ntp.aliyun.com # 将系统时间写入硬件时钟 sudo hwclock --systohc ``` ##### 4. 处理服务冲突 ```bash # 停止所有时间服务 sudo systemctl stop systemd-timesyncd chrony ntp # 启动标准时间同步服务 sudo systemctl start systemd-timesyncd sudo systemctl enable systemd-timesyncd # 检查服务状态 systemctl status systemd-timesyncd ``` ##### 5. 配置NTP服务器(可选) 编辑配置文件: ```bash sudo nano /etc/systemd/timesyncd.conf ``` 修改为: ```ini [Time] NTP=ntp.aliyun.com FallbackNTP=ntp.ubuntu.com ``` ##### 6. 验证修复 ```bash timedatectl # 检查状态 sudo apt update # 测试仓库更新 ``` --- #### 特殊场景处理 **在 Docker 容器中**: ```bash # 启动容器时同步宿主机时间 docker run -v /etc/localtime:/etc/localtime:ro ... ``` **嵌入式设备(如 RK3399)**: ```bash # 确保硬件时钟正确 sudo hwclock --hctosys ``` --- #### 验证结果 成功修复后: 1. `timedatectl status` 显示时间正确且同步正常 2. `sudo apt update` 不再报时间错误 3. 系统日志无时间相关报错: ```bash journalctl -u systemd-timesyncd --since "5 min ago" ``` > **注意**:若问题持续,检查BIOS电池或更换NTP服务器(如`ntp.aliyun.com` → `ntp.tuna.tsinghua.edu.cn`) --- ### 相关问题 1. 如何查看Ubuntu中正在运行的NTP服务? 2. `systemd-timesyncd`和`chrony`有什么区别? 3. 如何在Ubuntu服务器上配置多个NTP服务器? 4. Docker容器时间与宿主机不一致如何解决? 5. 嵌入式Linux设备时间同步的最佳实践是什么?
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值