跳转到内容
搜索 AlmaLinux 文档

    浏览当前文档目录

    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 主机上的输出示例未在本环境生成。

    Terminal window
    lsblk -d -o NAME,SIZE,ROTA,TYPE
    NAME SIZE ROTA TYPE
    sr0 4M 1 rom
    vda 40G 1 disk

    vda 是 virtio 虚拟盘。ROTA=1 只是默认标记,不代表物理转速;关键看名字(sd* 多为 SCSI/SATA,nvme* 为 NVMe,vd* 为 virtio)。

    Terminal window
    sudo smartctl --scan
    sudo smartctl -i /dev/vda
    (无输出)
    /dev/vda: Unable to detect device type
    Please specify device type with the -d option.

    --scan 没列出设备、-i 认不出类型,说明 smartmontools 拿不到这块盘的 SMART 通道。再试指定类型:

    Terminal window
    sudo smartctl -i -d sat /dev/vda
    sudo smartctl -i -d nvme /dev/vda
    Read Device Identity failed: Inappropriate ioctl for device
    Read NVMe Identify Controller failed: NVME_IOCTL_ADMIN_CMD: Inappropriate ioctl for device

    两种指定都失败——这不是配置问题,是虚拟盘没有透传 SMART。云厂商通常在宿主机层面监控磁盘,客户机看不到。

    读不到 SMART 时,看这些替代信号

    Section titled “读不到 SMART 时,看这些替代信号”
    Terminal window
    dmesg -T | grep -iE "i/o error|medium error|reset|ata" | tail -5
    sudo 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 时这是唯一可靠来源。
    Terminal window
    systemctl is-active smartd
    grep -vE "^#|^$" /etc/smartmontools/smartd.conf | head -3
    inactive
    DEVICESCAN -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”
    Terminal window
    sudo dnf install -y smartmontools
    sudo smartctl --scan
    sudo smartctl -i /dev/<盘>
    dmesg -T | grep -icE "i/o error|medium error"

    检查:

    1. --scan 是否列出了盘
    2. -i 是否返回设备型号与 SMART support 字段
    3. 读不到时,dmesg 是否有 I/O 错误
    4. 能明确说出「这块盘在本机能不能监控」

    常见问题

    为什么 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 配告警;虚拟盘环境装了也没有监控对象,重点是云平台或宿主机层面的监控。