NVME盘未格式化导致Ubuntu20.04启动慢

背景

最近公司一款产品转产,工厂组装好后,用我提供的系统镜像烧录,系统起来后发现Ubuntu20.04转圈了90秒才进入图形界面,这是不可接受的,公司老总要求当天必须解决。

定位

分析syslog

看不到系统启动时的日志,而且大量日志是集中在1秒内写入的,说明启动阶段的日志有丢失

查看串口打印

考虑到串口不会丢日志,接上串口,再次复现故障,发现启动10秒后打印突然就没有了,然后过了90秒才开始有打印,说明系统确实在这90秒里什么都没做,就干等。

分析systemd

与同事一起分析systemd,特别是跟研发这边的旧机器(没有启动慢问题)的systemd做比对,发现新机器少了个target,这个target负责执行/etc/fstab里指定的挂载,而systemd.mount挂载NVME超时,systemd的配置又决定了图形界面的初始化必须在NVME挂载之后进行,于是系统转圈了90秒。

systemd.mount手册截取

复制代码
Options¶

TimeoutSec=
Configures the time to wait for the mount command to finish. If a command does not exit within the configured time, the mount will be considered failed and be shut down again. All commands still running will be terminated forcibly via SIGTERM, and after another delay of this time with SIGKILL. (See KillMode= in systemd.kill(5).) Takes a unit-less value in seconds, or a time span value such as "5min 20s". Pass 0 to disable the timeout logic. The default value is set from DefaultTimeoutStartSec= option in systemd-system.conf(5).

systemd-system.conf手册截取

复制代码
Options¶

DefaultTimeoutStartSec=, DefaultTimeoutStopSec=, DefaultTimeoutAbortSec=, DefaultRestartSec=
Configures the default timeouts for starting, stopping and aborting of units, as well as the default time to sleep between automatic restarts of units, as configured per-unit in TimeoutStartSec=, TimeoutStopSec=, TimeoutAbortSec= and RestartSec= (for services, see systemd.service(5) for details on the per-unit settings). For non-service units, DefaultTimeoutStartSec= sets the default TimeoutSec= value.

DefaultTimeoutStartSec= and DefaultTimeoutStopSec= default to 90 s in the system manager and 90 s in the user manager. DefaultTimeoutAbortSec= is not set by default so that all units fall back to TimeoutStopSec=. DefaultRestartSec= defaults to 100 ms.

Added in version 209.

可以看到,systemd默认挂载超时时间恰好是90秒!

解决NVME挂载问题

经定位,是NVME出厂时并未格式化,导致/etc/fstab里配置的分区不存在,进而导致systemd根据/etc/fstab动态创建的mount单元执行超时

复制代码
# UNCONFIGURED FSTAB FOR BASE SYSTEM
/dev/nvme0n1p1 /home/root               ext4    defaults        0 2

验证问题

用fdisk命令创建Linux分区,再用mkfs.ext4命令给Linux分区创建ext4文件系统后,重启,启动慢的问题解决。

解决方案

研发解决

  1. 创建NVME检查脚本,检查是否有ext4分区,没有就创建分区并格式化
  2. 添加适当的systemd单元,使其在/etc/fstab被systemd解析前调用NVME检查脚本

工厂解决

要求工厂装配前必须将NVME格式化,且格式化成ext4分区。

  1. 买一个USB转NVME的硬盘盒
  2. 将NVME盘接到PC机上
  3. 使用傲梅分区助手这个第三方软件将NVME盘格式化成ext4分区。

后记

为什么systemd要给mount设置超时参数?本地挂载设置超时没有意义,网络挂载/etc/fstab又没指定,唉!

相关推荐
流浪00118 分钟前
Linux系统篇(一):从零入门操作系统:冯诺依曼体系到进程的完整理解
linux·运维·服务器
mounter6251 小时前
破局与守正:eBPF 在 Linux 内存管理中的应用、演进与重构构想
linux·服务器·网络·mmu·ebpf·linux kernel
STDD1 小时前
Linux Namespace:容器隔离的底层原理,PID、网络、挂载隔离实战
linux·运维·网络
Demon1_Coder1 小时前
智能体的自定义工具
java·linux·前端
gf13211111 小时前
【精确查找python脚本是否在运行】
linux·前端·python
Sunny Boy 0011 小时前
linux环境编译Pro*C 源文件(.pc文件)
linux·c语言·oracle
用户937855808702 小时前
Linux 基础教程(二)】系统目录结构、用户与用户组管理(useradd/usermod/passwd/sudo)
linux
着迷不白2 小时前
实战一:用户、权限、组 案例
linux·运维
TheSumSt2 小时前
日常教程丨远程串流打游戏方法介绍(Parsec/Tailscale+Headscale+DERP+Sunshine&Moonlight)
linux·网络·经验分享·nginx·开源·玩游戏
暂未成功人士!2 小时前
ROS 核心知识点和常用的命令行详细总结
linux·操作系统·ros