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又没指定,唉!

相关推荐
feng_you_ying_li41 分钟前
linux之重定向原理与缓冲区基本介绍
linux
晚风_END3 小时前
Linux|操作系统|zfs文件系统的使用详解
linux·运维·服务器·数据库·postgresql·性能优化·宽度优先
暴力求解8 小时前
Linux---线程基础
linux·运维·服务器
JAVA面经实录9178 小时前
计算机基础(完整版·超详细可背诵)
java·linux·数据结构·算法
晚风_END8 小时前
Linux|操作系统|最新版openzfs编译记录
linux·运维·服务器·数据库·spring·中间件·个人开发
GanGanGanGan_9 小时前
Rocky Linux 9 + XFCE 编译安装 fcitx5 + Rime 教程
linux·centos
咖喱o9 小时前
QinQ/VLAN Stacking
linux·运维·服务器·网络
xiaoye-duck9 小时前
《Linux系统编程》Linux指令 (二):从零开始理解Linux基础指令
linux
月白风清江有声9 小时前
安装mingw 版 cmake
linux
呱呱巨基11 小时前
Linux 基础IO
linux·c++·笔记·学习