Overview of hard disk monitoring
The daily relative probability of abnormal damage of hard disk is high, and different file systems (xfs,reiserfs,ext3) have different detection methods. It is recommended to use dmesag to check whether there is a log of hardware I/O failure, or fsck to confirm whether the file system is abnormal.
SMART test hard disk
SMART is a disk self analysis and detection technology. During the operation of the hard disk, the main parameters will be recorded, mainly including: model, capacity, temperature, density, sector, seek time, transmission, bit error rate, etc. After the hard disk runs for a period of time, the above parameters will change accordingly, and some parameters will alarm when they exceed the threshold. Depending on the corresponding alarm, we can preliminarily judge whether the hard disk is close to (damaged).
Smart is matched with the corresponding functions on the motherboard BIOS. Before using smart, you must start the relevant features in the BIOS settings. When smart is enabled for hardware features, for Linux, there is a corresponding smartd service stationed and running. This process can monitor, analyze and aggregate relevant hard disk conditions.
Simple usage of smartctl
smartctl can be used to detect disks. Its main usage is as follows: smartctl -a: check whether the device has SMART technology turned on. smartctl -s on: if SMART technology is not turned on, use this command to turn on SMART technology. smartctl -t short: detect the hard disk in the background, and the consumption time is short. smartctl -t long: it takes a long time to detect the hard disk in the background. smartctl -C -t short: the foreground detects the hard disk, and the consumption time is short. smartctl -C -t long: the foreground detects the hard disk, which takes a long time. smartctl -X: interrupt background detection of hard disk. smartctl -l selftest: displays the hard disk detection log. smartctl -l error: displays the hard disk error summary.
Tip: first, use the dmesg tool to confirm the device symbol of the hard disk.
smartctl usage example
# smartctl -i /dev/sda ...... SMART support is: Available - device has SMART capability. SMART support is: Enabled #Indicates that smart support is enabled # smartctl --smart=on --offlineauto=on --saveauto=on /dev/sda # smartctl -H /dev/sda ...... SMART overall-health self-assessment test result: PASSED
Command interpretation: PASSED: This indicates that the hard disk is in good health; FAILED: the hard disk is unhealthy. It is recommended to replace the hard disk.
Tip: SMART only reports that the disk is no longer healthy, but it is uncertain how long it can last after the alarm.
#smartctl -A /dev/sda #View the details of the hard disk, test the use time of the hard disk and the number of bytes written #smartctl -s on /dev/sda #If SMART technology is not turned on, use this command to turn on SMART technology. #smartctl -t short /dev/sda #Background detection of hard disk, short consumption time; #smartctl -t long /dev/sda #Background detection of hard disk takes a long time; #smartctl -C -t short /dev/sda #The front desk detects the hard disk, and the consumption time is short; #smartctl -C -t long /dev/sda #The front desk detects the hard disk, which takes a long time. #smartctl -X /dev/sda #Interrupt background detection of hard disk. #smartctl -l selftest /dev/sda #Displays the hard disk detection log. #smartctl -l error /dev/sda #Displays a summary of hard disk errors.
smart resident configuration
Generally, executing smartctl needs to be executed on the server terminal. sarmt also supports running on the server as a service, and the process deamon is startd, so as to judge the hard disk status regularly and specify alarms, logs, etc.
In the following example, start the process after smartd.conf is configured.
# vi /etc/smartd.conf /dev/sda -H -m firstname.lastname@example.org #Configure and monitor the health status of the disk. When PASSED and Failure are reported in SMART, email notification will be sent /dev/sda -a -m email@example.com,root@localhost #Monitor all properties of the disk. When PASSED and Failure are reported in SMART, an email notification will be sent
Start the startd service.
# /etc/init.d/smartd restart #Load profile startup
Tip: for more smart usage and configuration References: https://www.smartmontools.org/wiki/TocDoc
badblocks detect hard disk
The badblocks command can check for damaged blocks in a disk device. This command needs to specify the disk device to be checked and the number of disk blocks. Syntax: Badblocks [- SVW] [- b] [- O] [disk device] [number of disk blocks] [start block]
- -b specifies the block size of the disk, in bytes.
- -o write the inspection results to the specified output file.
- -s displays progress during inspection.
- -v displays detailed information when executing.
- -w perform a write test while checking.
- [disk device] specifies the disk device to check.
- [number of disk extents] specifies the total number of extents for the disk device.
- [start block] specifies which block to start checking from.
badblocks usage example
Bad disk blocks detected by badblocks:
badblocks -s -v /dev/sda1 #Displays the progress and details of the checks performed # badblocks -s -v /dev/sda # badblocks -s -w -v /dev/sda2 #The progress is displayed and detected by writing, and the details are displayed at the same time
Note: the attached hard disk cannot be detected by writing