云梦编程网

当前位置:首页 > Liunx教程 >

linux smartctl命令详解

作者:佚名 时间:2024-02-09 12:45:34 阅读:(9)

smartctl命令是一个用于控制和监控支持smart技术的硬盘的命令。通过控制和管理硬盘的SMART(Self Monitoring Analysis and Reporting Technology),自动检测分析及报告技术)技术来实现的,接下来云梦编程为大家详细的介绍一下smartctl命令详细使用方法,有需要的小伙伴可以参考一下:

linux smartctl命令详解

1、smartctl介绍

smartctl命令用于监控和诊断S.M.A.R.T(Self-Monitoring, Analysis and Reporting Technology)硬盘状态。我们可以通过smartctl命令来获取硬盘的健康状态、运行时间以及各项S.M.A.R.T指标等信息。其中SMART技术可以对硬盘的磁头单元、盘片电机驱动系统、硬盘内部电路以及盘片表面介质材料等进行监测,当SMART监测并分析出硬盘可能出现问题时会及时向用户报警以避免计算机数据受损失。

2、安装smartmontools工具包:

smartctl命令默认在系统中不存在,需要安装smartmontools工具包之后才能使用。

[root@localhost ~]# yum install smartmontools
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package smartmontools.x86_64 1:7.0-2.el7 will be installed
--> Processing Dependency: mailx for package: 1:smartmontools-7.0-2.el7.x86_64
--> Running transaction check
---> Package mailx.x86_64 0:12.5-19.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================================================================================================================================================
 Package                                                Arch                                            Version                                              Repository                                     Size
=================================================================================================================================================================================================================
Installing:
 smartmontools                                          x86_64                                          1:7.0-2.el7                                          base                                          546 k
Installing for dependencies:
 mailx                                                  x86_64                                          12.5-19.el7                                          base                                          245 k

Transaction Summary
=================================================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 791 k
Installed size: 2.4 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mailx-12.5-19.el7.x86_64.rpm                                                                                                                                                       | 245 kB  00:00:00     
(2/2): smartmontools-7.0-2.el7.x86_64.rpm                                                                                                                                                 | 546 kB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                            4.3 MB/s | 791 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mailx-12.5-19.el7.x86_64                                                                                                                                                                      1/2 
  Installing : 1:smartmontools-7.0-2.el7.x86_64                                                                                                                                                              2/2 
  Verifying  : mailx-12.5-19.el7.x86_64                                                                                                                                                                      1/2 
  Verifying  : 1:smartmontools-7.0-2.el7.x86_64                                                                                                                                                              2/2 

Installed:
  smartmontools.x86_64 1:7.0-2.el7                                                                                                                                                                               

Dependency Installed:
  mailx.x86_64 0:12.5-19.el7                                                                                                                                                                                     

Complete!

3、相关语法:

smartctl [options] device

4、相关参数法:

============================================ 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)

5、相关实例:

    (1)、显示设备的身份信息,支持检查硬盘是否打开了SMART支持

smartctl -i /dev/sda

如果显示:SMART support is: Enabled,说明硬盘支持SMART。

    (2)、开启硬盘支持SMART

smartctl --smart=on --offlineauto=on --saveauto=on 

    (3)、查看硬盘的健康状况:

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

=== START OF READ SMART DATA SECTION ===
SMART Health Status: OK

    (4)、显示设备SMART厂商属性和值

smartctl -A /dev/sda

    (5)、显示硬盘历史错误信息。

smartctl -l error /dev/sda

    (6)、硬盘自测:

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

=======> INVALID ARGUMENT TO -t: TEST
=======> VALID ARGUMENTS ARE: offline, short, long, conveyance, force, vendor,N, select,M-N, pending,N, afterselect,[on|off] <=======

Use smartctl -h to get a usage summary

    (7)、显示硬盘测试信息

smartctl -l selftest /dev/sda 

    (8)、显示硬盘SMART的全部信息

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

=== START OF INFORMATION SECTION ===
Vendor:               VMware
Product:              Virtual disk
Revision:             2.0
Compliance:           SPC-4
User Capacity:        107,374,182,400 bytes [107 GB]
Logical block size:   512 bytes
LU is thin provisioned, LBPRZ=1
Device type:          disk
Local Time is:        Tue May  4 10:11:07 2021 EDT
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

以上就是云梦编程为大家介绍的关于smartctl命令查看硬盘详细信息的全部内容了,希望对大家有所帮助,了解更多相关文章请关注云梦编程网!

最新文章

热门文章