Linux || smartctl

本文介绍了Smartmontools这款硬盘检测工具,它利用SMART技术监控硬盘健康状况,包括磁头、电机等组件,并展示了smartctl命令行的使用方法,以及如何检查和设置SMART支持和自检功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Smartmontools是什么

Smartmontools是一种硬盘检测工具,通过控制和管理硬盘的SMART(Self Monitoring Analysis and Reporting Technology,自动检测分析及报告技术)实现。

SMART 可以对硬盘的磁头单元、盘片电机驱动系统、硬盘内部电路以及盘片表面介质材料等进行监测。

SMART 必须在主板支持的前提下才能发生作用,而且SMART技术也不能保证能预报所有可能发生的硬盘故障。

smartctl是什么

smartctl是一个用于监测和分析硬盘健康状态的工具,可以用于检测是否存在坏的磁盘。

1.下载

yum install -y smartmontools

用法

[root@master ~]# smartctl -h
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-957.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

Usage: smartctl [options] device

============================================ SHOW INFORMATION OPTIONS =====

  -h, --help, --usage
         Display this help and exit

  -V, --version, --copyright, --license
         Print license, copyright, and version information and exit

  -i, --info
         Show identity information for device

  --identify[=[w][nvb]]
         Show words and bits from IDENTIFY DEVICE data                (ATA)

  -g NAME, --get=NAME
        Get device setting: all, aam, apm, dsn, lookahead, security,
        wcache, rcache, wcreorder, wcache-sct

  -a, --all
         Show all SMART information for device

  -x, --xall
         Show all information for device

  --scan
         Scan for devices

  --scan-open
         Scan for devices and try to open each device

================================== SMARTCTL RUN-TIME BEHAVIOR OPTIONS =====

  -j, --json[=[cgiosuv]]
         Print output in JSON format

  -q TYPE, --quietmode=TYPE                                           (ATA)
         Set smartctl quiet mode to one of: errorsonly, silent, noserial

  -d TYPE, --device=TYPE
         Specify device type to one of:
         ata, scsi[+TYPE], nvme[,NSID], sat[,auto][,N][+TYPE], usbcypress[,X], usbjmicron[,p][,x][,N], usbprolific, usbsunplus, sntjmicron[,NSID], intelliprop,N[+TYPE], marvell, areca,N/E, 3ware,N, hpt,L/M/N, megaraid,N, aacraid,H,L,ID, cciss,N, auto, test

  -T TYPE, --tolerance=TYPE                                           (ATA)
         Tolerance: normal, conservative, permissive, verypermissive

  -b TYPE, --badsum=TYPE                                              (ATA)
         Set action on bad checksum to one of: warn, exit, ignore

  -r TYPE, --report=TYPE
         Report transactions (see man page)

  -n MODE[,STATUS], --nocheck=MODE[,STATUS]                           (ATA)
         No check if: never, sleep, standby, idle (see man page)

============================== DEVICE FEATURE ENABLE/DISABLE COMMANDS =====

  -s VALUE, --smart=VALUE
        Enable/disable SMART on device (on/off)

  -o VALUE, --offlineauto=VALUE                                       (ATA)
        Enable/disable automatic offline testing on device (on/off)

  -S VALUE, --saveauto=VALUE                                          (ATA)
        Enable/disable Attribute autosave on device (on/off)

  -s NAME[,VALUE], --set=NAME[,VALUE]
        Enable/disable/change device setting: aam,[N|off], apm,[N|off],
        dsn,[on|off], lookahead,[on|off], security-freeze,
        standby,[N|off|now], wcache,[on|off], rcache,[on|off],
        wcreorder,[on|off[,p]], wcache-sct,[ata|on|off[,p]]

======================================= READ AND DISPLAY DATA OPTIONS =====

  -H, --health
        Show device SMART health status

  -c, --capabilities                                            (ATA, NVMe)
        Show device SMART capabilities

  -A, --attributes
        Show device SMART vendor-specific Attributes and values

  -f FORMAT, --format=FORMAT                                          (ATA)
        Set output format for attributes: old, brief, hex[,id|val]

  -l TYPE, --log=TYPE
        Show device log. TYPE: error, selftest, selective, directory[,g|s],
        xerror[,N][,error], xselftest[,N][,selftest], background,
        sasphy[,reset], sataphy[,reset], scttemp[sts,hist],
        scttempint,N[,p], scterc[,N,M], devstat[,N], defects[,N], ssd,
        gplog,N[,RANGE], smartlog,N[,RANGE], nvmelog,N,SIZE

  -v N,OPTION , --vendorattribute=N,OPTION                            (ATA)
        Set display OPTION for vendor Attribute N (see man page)

  -F TYPE, --firmwarebug=TYPE                                         (ATA)
        Use firmware bug workaround:
        none, nologdir, samsung, samsung2, samsung3, xerrorlba, swapid

  -P TYPE, --presets=TYPE                                             (ATA)
        Drive-specific presets: use, ignore, show, showall

  -B [+]FILE, --drivedb=[+]FILE                                       (ATA)
        Read and replace [add] drive database from FILE
        [default is +/etc/smartmontools/smart_drivedb.h
         and then    /usr/share/smartmontools/drivedb.h]

============================================ DEVICE SELF-TEST OPTIONS =====

  -t TEST, --test=TEST
        Run test. TEST: offline, short, long, conveyance, force, vendor,N,
                        select,M-N, pending,N, afterselect,[on|off]

  -C, --captive
        Do test in captive mode (along with -t)

  -X, --abort
        Abort any non-captive test on device

=================================================== SMARTCTL EXAMPLES =====

  smartctl --all /dev/sda                    (Prints all SMART information)

  smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda
                                              (Enables SMART on first disk)

  smartctl --test=long /dev/sda          (Executes extended disk self-test)

  smartctl --attributes --log=selftest --quietmode=errorsonly /dev/sda
                                      (Prints Self-Test & Attribute errors)
  smartctl --all --device=3ware,2 /dev/sda
  smartctl --all --device=3ware,2 /dev/twe0
  smartctl --all --device=3ware,2 /dev/twa0
  smartctl --all --device=3ware,2 /dev/twl0
          (Prints all SMART info for 3rd ATA disk on 3ware RAID controller)
  smartctl --all --device=hpt,1/1/3 /dev/sda
          (Prints all SMART info for the SATA disk attached to the 3rd PMPort
           of the 1st channel on the 1st HighPoint RAID controller)
  smartctl --all --device=areca,3/1 /dev/sg2
          (Prints all SMART info for 3rd ATA disk of the 1st enclosure
           on Areca RAID controller)

2.查找磁盘设备名称

[root@master ~]# fdisk -l

磁盘 /dev/sda:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000b0f72

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xca408843

   设备 Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    12584959     6291456   83  Linux
/dev/sdb2        12584960    23070719     5242880   83  Linux
/dev/sdb3        23070720    29362175     3145728   83  Linux

磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节


磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节

查看磁盘是否支持smart

[root@master ~]# smartctl -i /dev/sda
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-957.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               VMware,
Product:              VMware Virtual S
Revision:             1.0
User Capacity:        21,474,836,480 bytes [21.4 GB]
Logical block size:   512 bytes
Device type:          disk
Local Time is:        Tue Aug  8 12:58:30 2023 CST
SMART support is:     Unavailable - device lacks SMART capability.

vmware虚拟机的硬盘不支持SMART。

运行smartctl检查磁盘

[root@master ~]# smartctl -a  /dev/sda
smartctl 7.0 2018-12-30 r4883 [x86_64-linux-3.10.0-957.el7.x86_64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               VMware,
Product:              VMware Virtual S
Revision:             1.0
User Capacity:        21,474,836,480 bytes [21.4 GB]
Logical block size:   512 bytes
Device type:          disk
Local Time is:        Tue Aug  8 13:00:10 2023 CST
SMART support is:     Unavailable - device lacks SMART capability.

=== START OF READ SMART DATA SECTION ===
Current Drive Temperature:     0 C
Drive Trip Temperature:        0 C

Error Counter logging not supported

Device does not support Self Test logging

<think>好的,用户现在询问关于smartctl的信息。首先,我需要回顾之前的对话历史。用户之前问过如何在Windows 7下获取主机唯一标识,我详细介绍了使用WMI、命令行工具等方法,提到了硬盘序列号等硬件信息。现在用户的问题转向smartctl,这是一个用于监控和分析硬盘健康状态的工具,尤其在Linux系统中常用,但在Windows下也有相关支持。 用户可能的需求是什么?他们可能在寻找硬盘健康监测的方法,或者需要获取更详细的硬盘信息,比如序列号、SMART数据等。之前回答中提到了通过WMI和命令行获取硬盘序列号,但smartctl提供了更深入的诊断功能,用户可能需要更专业的工具来预防硬盘故障或进行故障排查。 接下来,我需要确定用户的使用环境。之前的提问是关于Windows 7,但smartctl主要是在Linux下使用,不过Windows用户可以通过第三方工具如Cygwin或第三方软件包来使用。因此,在回答中需要涵盖Windows下的使用方法,同时也要介绍其在Linux中的常见用法,因为用户可能对跨平台工具有兴趣。 用户可能对如何安装smartctl、基本命令、如何解读SMART属性以及注意事项感兴趣。需要详细说明安装步骤,特别是针对Windows用户的解决方案,比如使用gsmartcontrol或通过WSL。此外,用户可能关心权限问题,比如是否需要管理员权限运行,这在之前的回答中也提到过权限要求,这里需要再次强调。 还需要注意用户的技术水平。之前的回答中使用了C#代码和命令行示例,用户可能具备一定的技术背景,但smartctl是命令行工具,可能需要解释基本命令的结构和常见参数。同时,解读SMART数据中的关键指标,如Reallocated_Sector_Ct、Temperature_Celsius等,对用户来说可能不太直观,需要举例说明哪些值需要注意。 另外,用户可能希望了解如何自动化监控或集成到现有系统中,可以提到cron作业或第三方工具如smartd。同时,注意事项部分需要涵盖虚拟化环境中的限制、不同厂商的SMART定义差异以及定期监控的重要性,这些都与之前回答中提到的虚拟化问题和硬件更换影响相呼应。 最后,确保回答结构清晰,分点说明,符合用户之前接受的格式,比如使用章节和小标题,代码示例用适当的格式区分。同时,遵循系统级指令,使用正确的LaTeX格式,不过在这个问题中可能数学公式较少,但如果有数值范围或参数说明,可能需要使用行内公式,例如温度阈值$40^\circ$C。 总结,回答需要覆盖smartctl的功能、安装方法、基本使用命令、数据解读、高级用法、注意事项,并针对Windows用户提供可行的解决方案,同时保持与之前回答一致的详细和结构化风格。</think>以下是对`smartctl`工具的详细介绍,涵盖其功能、使用方法及典型应用场景: --- ### 一、工具定位 `smartctl`是**S.M.A.R.T(Self-Monitoring, Analysis and Reporting Technology)**技术的命令行交互工具,主要用于: 1. 监控硬盘健康状态 2. 预测机械硬盘/SSD故障 3. 获取存储设备的详细技术参数 4. 执行离线诊断测试 支持设备类型包括: $ \text{HDD/SSD/NVMe/USB存储设备/RAID阵列} $ --- ### 二、环境部署 #### Linux系统安装 ```bash # Debian/Ubuntu sudo apt-get install smartmontools # RHEL/CentOS sudo yum install smartmontools # 验证安装 smartctl --version ``` #### Windows支持方案 1. **Cygwin环境**:通过包管理器安装`smartmontools` 2. **独立软件包**:使用预编译版本如[smartmontools-win](https://www.smartmontools.org/wiki/Download) 3. **图形化工具**:配合[gsmartcontrol](https://gsmartcontrol.sourceforge.io) --- ### 三、基础使用命令 | 命令示例 | 功能说明 | |----------------------------------|------------------------------| | `smartctl -a /dev/sda` | 显示设备全部SMART信息 | | `smartctl -i /dev/nvme0` | 查看设备基本信息 | | `smartctl -H /dev/sdb` | 执行健康状态检查 | | `smartctl -t short /dev/sdc` | 启动快速自检(2分钟) | | `smartctl -t long /dev/sdd` | 启动完整自检(数小时) | | `smartctl -l error /dev/sde` | 查看错误日志 | | `smartctl -l selftest /dev/sdf` | 显示历史自检记录 | --- ### 四、关键SMART属性解读 ```bash ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE 5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0 197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0 194 Temperature_Celsius 0x0022 062 052 000 Old_age Always - 38 (Min/Max 22/48) ``` - **致命指标**: $ \text{Reallocated_Sector\_Ct > 0} $(已重映射坏道) $ \text{Current_Pending\_Sector > 0} $(待处理坏道) - **预警指标**: $ \text{Temperature\_Celsius > 60^\circ C} $(高温警告) $ \text{Power\_On\_Hours > 20,000} $(机械硬盘寿命衰减) --- ### 五、高级应用场景 #### 1. RAID阵列监控 ```bash # 适配LSI MegaRAID控制器 smartctl -d megaraid,0 -a /dev/sda ``` #### 2. 自动化监控脚本 ```bash #!/bin/bash DEVICE="/dev/sda" HEALTH=$(smartctl -H $DEVICE | grep "SMART overall-health") if [[ $HEALTH != *"PASSED"* ]]; then echo "[警报] $DEVICE 故障风险!" | mail -s "存储设备告警" admin@example.com fi ``` #### 3. NVMe专项检测 ```bash smartctl -x /dev/nvme0n1 # 显示扩展元数据 smartctl -g tempcrit /dev/nvme0n1 # 获取温度阈值 ``` --- ### 六、注意事项 1. **权限要求**:需以`root`或管理员身份运行 2. **虚拟化限制**: - VMware虚拟磁盘无法直接获取物理盘SMART数据 - 需通过ESXi主机执行`esxcli storage core device smart get -d naa.xxx` 3. **SSD特殊处理**: - 关注`Percentage_Used`(闪存磨损度) - 需定期执行`TRIM`指令优化性能 4. **厂商差异**: - 希捷/西数/三星等厂商的SMART属性定义存在差异 --- ### 七、诊断流程图解 ``` 开始 │ ├─ 执行健康检查 → 异常 → 查看错误日志 → 备份数据 → 更换硬盘 │ ├─ 正常 → 检查温度/通电时间 → 临界值 → 增强散热/监控 │ └─ 长期稳定 → 设置cron定时任务(建议每周检测) ``` 通过合理使用`smartctl`,可有效降低因存储设备故障导致的数据丢失风险。建议将关键指标监控集成到运维系统中实现自动化预警。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

韩未零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值