自学内容网 自学内容网

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

背景

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


原文地址:https://blog.csdn.net/happen23/article/details/142926705

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!