AlmaLinux 9:SMART 不可用时怎么判断磁盘健康
在一台 AlmaLinux 9.8 真机(kernel 5.14.0-687.54.1.el9_8,系统盘为 virtio 的 /dev/vda)上实际执行:lsblk -d、smartctl --scan、smartctl -i /dev/vda、smartctl -i -d sat、smartctl -i -d nvme、systemctl is-active smartd、查看 smartd.conf。日志:plans/content-expansion/evidence/logs/alma-disk-health.log。
这台机器的盘读不到 SMART,所以本页重点是「读不到时怎么办」;能读到 SMART 的 SATA/NVMe 主机上的输出示例未在本环境生成。
先确认盘是什么类型
Section titled “先确认盘是什么类型”lsblk -d -o NAME,SIZE,ROTA,TYPENAME SIZE ROTA TYPEsr0 4M 1 romvda 40G 1 diskvda 是 virtio 虚拟盘。ROTA=1 只是默认标记,不代表物理转速;关键看名字(sd* 多为 SCSI/SATA,nvme* 为 NVMe,vd* 为 virtio)。
尝试读取 SMART
Section titled “尝试读取 SMART”sudo smartctl --scansudo smartctl -i /dev/vda(无输出)
/dev/vda: Unable to detect device typePlease specify device type with the -d option.--scan 没列出设备、-i 认不出类型,说明 smartmontools 拿不到这块盘的 SMART 通道。再试指定类型:
sudo smartctl -i -d sat /dev/vdasudo smartctl -i -d nvme /dev/vdaRead Device Identity failed: Inappropriate ioctl for deviceRead NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Inappropriate ioctl for device两种指定都失败——这不是配置问题,是虚拟盘没有透传 SMART。云厂商通常在宿主机层面监控磁盘,客户机看不到。
读不到 SMART 时,看这些替代信号
Section titled “读不到 SMART 时,看这些替代信号”dmesg -T | grep -iE "i/o error|medium error|reset|ata" | tail -5sudo dnf install -y mdadm && sudo mdadm --detail /dev/md0 2>/dev/null | tail -5- 内核日志:
I/O error、medium error、link reset是盘或链路出问题的直接证据; - 软 RAID:
mdadm --detail的State、Faulty Devices; - 硬件 RAID:用厂商工具(
storcli、perccli、ssacli)看阵列与物理盘状态; - 云主机:看云平台控制台的磁盘健康/事件,客户机内读不到 SMART 时这是唯一可靠来源。
smartd 该不该配
Section titled “smartd 该不该配”systemctl is-active smartdgrep -vE "^#|^$" /etc/smartmontools/smartd.conf | head -3inactiveDEVICESCAN -H -m root -M exec /usr/libexec/smartmontools/smartdnotify -n standby,10,q默认配置是 DEVICESCAN(自动扫描所有支持的盘、健康检查失败时发邮件给 root)。盘不支持 SMART 时 smartd 没有可监控对象,起了也不会报盘的问题;这种环境应把监控放到云平台或硬件层。
- 以为装了 smartmontools 就能看盘:虚拟盘/RAID 卡后面的盘需要透传或厂商工具;
-d sat乱指定:类型不对只会得到 ioctl 错误,不会变出数据;- smartd 起来了就以为有监控:没有设备被扫描到时它什么都不会报。
练习:判断一台机器能否读 SMART
Section titled “练习:判断一台机器能否读 SMART”sudo dnf install -y smartmontoolssudo smartctl --scansudo smartctl -i /dev/<盘>dmesg -T | grep -icE "i/o error|medium error"检查:
--scan是否列出了盘-i是否返回设备型号与 SMART support 字段- 读不到时,
dmesg是否有 I/O 错误 - 能明确说出「这块盘在本机能不能监控」
常见问题
为什么 smartctl 说 Unable to detect device type?
大多是虚拟盘(virtio)或 RAID 卡后的盘没有把 SMART 透传给客户机。指定 -d sat/-d nvme 也无效时,只能依赖云平台或阵列工具监控。
读不到 SMART,怎么提前发现盘要坏?
看 dmesg 的 I/O error/medium error、软 RAID 的 state、文件系统 remount-ro 事件,以及云平台磁盘事件;这些都是间接但有效的信号。
smartd 需要装吗?
能读 SMART 的物理机建议装,并用 -m 配告警;虚拟盘环境装了也没有监控对象,重点是云平台或宿主机层面的监控。
- XFS 修复:XFS 损坏的修复流程
- LVM 扩容:LVM 扩容与 XFS 增长
- 网络排查:网络不通的五层排查