44 Commits

Author SHA1 Message Date
Keith Nash
0675845f0c Merge pull request #24 from kyounger/allow-bc-args
Allow `-b` & `-c` args
2023-07-14 09:14:27 -05:00
kyounger
7ff8c08416 Allow -b arg override in badblocks run 2022-05-30 10:22:35 -05:00
kyounger
52a934b5f8 Allow -c arg override in badblocks run 2022-05-30 10:21:56 -05:00
Keith Nash
66c5bb6d52 Merge pull request #19 from hogenf/patch-1
Update notes on badblocks block size to 8192
2021-10-10 09:35:22 -05:00
hogenf
aede45b87d Update notes on badblocks block size to 8192 2021-10-09 17:48:28 +02:00
Keith Nash
43b4a05522 Update README.md 2021-02-19 15:22:44 -06:00
Keith Nash
a68e2ae834 Increased memory buffers from 4096 to 8192 2021-02-19 15:20:51 -06:00
Keith Nash
bc7d0e0e87 Update README.md 2021-02-19 15:17:57 -06:00
Keith Nash
2ef13143a5 Merge pull request #11 from justin-p/master
Additional tested drive model
2020-10-24 08:13:37 -05:00
Justin Perdok
ee67da83ab Update README.md 2020-10-24 14:55:14 +02:00
Keith Nash
203d8c21fb Update README.md 2020-10-06 21:55:01 -05:00
Keith Nash
4399957bac Update README.md 2020-10-06 00:00:54 -05:00
Keith Nash
8f89419fb1 Update README.md 2020-10-05 23:57:43 -05:00
Keith Nash
71de6db4ff Update README.md 2020-10-05 23:56:36 -05:00
Keith Nash
ad723c4980 Update README.md 2020-10-05 23:50:28 -05:00
Keith Nash
a899831ec9 Update README.md 2020-10-05 23:48:46 -05:00
Keith Nash
7f6792d6e3 Fixed problem identifying some mechanical drives as SSDs
Added -x option to control the badblocks -e option, allowing extended testing.
Added smartctl to the list of dependencies.
Changed disk type detection so that we assume all drives are mechanical drives
unless they explicitly return 'Solid State Drive' for Rotational Rate.
Removed datestamp from every line of log output, only emitting it in log headers.
Minor reformatting.
2020-10-05 23:41:41 -05:00
Keith Nash
84134fe241 Merge pull request #8 from schnerring/master
Add dry_run_wrapper(), update docs, improve option parsing, add detection for mechanical drives
2020-09-09 23:22:30 -05:00
Michael Schnerring
9a211d13e8 update help text 2020-09-10 00:41:54 +02:00
Michael Schnerring
5c2d3feb99 add up-to-date dry-run sample log 2020-09-09 22:02:47 +02:00
Michael Schnerring
f5b2fba114 fix dry_run_wrapper() 2020-09-09 19:53:18 +02:00
Michael Schnerring
bfa816c68b query "Model Number" when getting disk model 2020-09-09 19:14:31 +02:00
Michael Schnerring
31def99394 fix grep redirection
fix grep regexes
2020-09-09 19:14:16 +02:00
Michael Schnerring
a9ce30c92a skip badblocks for non-mechanical drives 2020-09-09 18:59:20 +02:00
Michael Schnerring
c5b193f76c add changes to VERSION history 2020-09-09 18:23:48 +02:00
Michael Schnerring
76fd4bd50d implement dry_run_wrapper() 2020-09-09 18:09:00 +02:00
Michael Schnerring
cd16bc6cd6 decouple by splitting code into smaller functions 2020-09-09 17:59:59 +02:00
Michael Schnerring
53c9d579a7 make <disk> option more resilient by also allowing /dev/ prefix 2020-09-09 17:58:55 +02:00
Michael Schnerring
aafc497863 add docs from file header to help text
add -e option for "extended" help text
move option parsing to the top to be able to always display help text
add Tiny Core Linux 11.1 to tested OS; add IronWolf HDD to tested HDDs
consolidate help text and README.md
2020-09-09 17:58:25 +02:00
Keith Nash
1499e729ec Merge pull request #7 from schnerring/master
Remove code duplication and dependencies; improve portability, readability and docs; add option parsing, dependency and sudo check
2020-09-09 00:39:03 -05:00
Michael Schnerring
d31b60bfcd remove --captive option from smart tests 2020-09-09 02:19:26 +02:00
Michael Schnerring
5d702df0a6 change constant names to uppercase
regroup constants logically together
2020-09-09 01:52:03 +02:00
Michael Schnerring
57f8dd5227 implement option parsing
* -h for help text
* -f for non-dry mode
* -o <directory> to specify log directory
2020-09-09 00:31:33 +02:00
Michael Schnerring
4a8d44e6a8 check if running as root 2020-09-08 23:00:35 +02:00
Michael Schnerring
0dc4614b3a adjust informational output for readability
remove duplicate output of drive information
add OS_FLAVOR and HOSTNAME constants
2020-09-08 22:52:01 +02:00
Michael Schnerring
0dcbdcf12c make constants readonly 2020-09-08 22:51:29 +02:00
Michael Schnerring
fb842ea127 use long smartctl options to improve readability
run smartctl --test in --captive mode
remove smart test code duplication
add function documentation
2020-09-08 22:50:45 +02:00
Michael Schnerring
3a21b21eca refactor logging
use printf instead of echo to improve portability
rename echo_str to log_info
create log_header function to reduce code duplication
2020-09-08 21:45:19 +02:00
Michael Schnerring
8b3c16cebf implement dependency check 2020-09-08 21:22:57 +02:00
Michael Schnerring
cfaedeac28 simplify and document poll_selftest_complete() 2020-09-08 21:18:11 +02:00
Michael Schnerring
40e114da98 rename duration parameters for expressiveness
add more detailed comments to duration parameters
2020-09-08 21:17:26 +02:00
Michael Schnerring
492e4ca429 remove dependency on pcregrep and tr
move SMART info querying to well documented functions for readability
2020-09-08 21:16:36 +02:00
Michael Schnerring
8744bbd5d0 fix markdownlint issues in README.md 2020-09-08 16:00:29 +02:00
Michael Schnerring
0b36a8658a add .editorconfig; remove trailing whitespace
add myself to license.txt
2020-09-08 16:00:05 +02:00
6 changed files with 729 additions and 411 deletions

12
.editorconfig Normal file
View File

@@ -0,0 +1,12 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false

100
README.md
View File

@@ -1,20 +1,24 @@
# Shell script for burn-in and testing of drives
## Purpose
`disk-burnin.sh` is a POSIX-compliant shell script I wrote to simplify the process of burning-in disks. It is intended for use only on disks which do not contain data, such as new disks or disks which are being tested or re-purposed. I was inspired by the ["How To: Hard Drive Burn-In Testing"](https://forums.freenas.org/index.php?threads/how-to-hard-drive-burn-in-testing.21451/) thread on the FreeNAS forum and I want to give full props to the good folks who contributed to that thread.
## Warnings
Be warned that:
* This script runs the `badblocks` program in destructive mode, which erases any data on the disk. Therefore, please be careful! __Do not run this script on disks containing data you value!__
* Run times for large disks can take several days to a week or more to complete, so it is a good idea to use `tmux` sessions to prevent mishaps.
* Must be run as 'root', so either log on using the root account or use the `sudo` command, for example: `sudo ./disk_burnin.sh sda`
* This script runs `badblocks` in destructive mode, which erases any data on the disk. Therefore, please be careful! __Do not run this script on disks containing valuable data!__
* Run times for large disks can be several days. Use `tmux` or `screen` to test multiple disks in parallel.
* Must be run as 'root'.
## Tests
Performs these steps:
1. Run SMART short test
1. Run `badblocks`
1. Run SMART extended test
2. Run `badblocks`
3. Run SMART extended test
The script calls `sleep` after starting each SMART test, using a duration based on the polling interval reported by the disk, after which it polls for test completion.
@@ -34,62 +38,102 @@ These indicate possible problems with the drive. You therefore may wish to abort
The script extracts the drive model and serial number and creates a log filename of the form `burnin-[model]_[serial number].log`.
## `badblocks` Options
`badblocks` is invoked with the following options:
- `-b 4096` : Use a block size of 4096
- `-e 1` : Abort the test if an error is found (remove this option for full testing of drives)
- `-v` : Verbose mode
- `-o` : Write list of bad blocks found (if any) to a file named `burnin-[model]_[serial number].bb`
- `-s` : Show progress
- `-w` : Write-mode test, writes four patterns (0xaa, 0x55, 0x44, 0x00) on every disk block
The only required command-line argument is the device specifier, e.g.:
* `-b 8192` : Use a block size of 8192 (override this setting with the `-b` option below)
* `-e 1` : Abort the `badblocks` test immediately if an error is found (override this setting with the `-x` option below)
* `-c 64` : Number of concurrent blocks to check. (override this setting with the `-c` option below, but beware of memory use with high values)
* `-v` : Verbose mode
* `-o` : Write list of bad blocks found (if any) to a file named `burnin-[model]_[serial number].bb`
* `-s` : Show progress
* `-w` : Write-mode test, writes four patterns (0xaa, 0x55, 0xff, 0x00) on every disk block
`./disk-burnin.sh sda`
## Usage
...will run the burn-in test on device /dev/sda
`./disk-burnin.sh [-h] [-e] [-b <block_size>] [-c <num_blocks>] [-f] [-o <directory>] [-x] <disk>`
## Dry Run Mode
### Options
The script supports a 'dry run mode' which lets you check the sleep duration calculations and insure that the sequence of commands suits your needs without actually performing any operations on disks. In 'dry runs' the script does not perform any SMART tests or invoke the `sleep` or `badblocks` programs.
* `-h`: show help text
* `-e`: show extended help text
* `-b`: block size (default: 8192)
* `-c`: number of concurrent blocks to check (default: 64). Higher values will use more memory.
* `-f`: run a full, destructive test. Disables the default 'dry-run mode'. **ALL DATA ON THE DISK WILL BE LOST!**
* `-o <directory>`: write log files to `<directory>` (default: working directory `$(pwd)`)
* `-x`: perform a full pass of `badblocks`, using the `-e 0` option.
* `<disk>`: disk to burn-in (`/dev/` may be omitted)
The script was formerly distributed with 'dry run mode' enabled by default, but this is no longer the case. You will have to edit the script and set the `Dry_Run` variable to a non-zero value to enable 'dry runs'.
### Examples
* `./disk-burnin.sh sda`: run in dry-run mode on disk `/dev/sda`
* `./disk-burnin.sh -f /dev/sdb`: run full, destructive test on disk `/dev/sdb`
* `./disk-burnin.sh -f -o ~/burn-in-logs sdc`: run full, destructive test on disk `/dev/sdc` and write the log files to `~/burn-in-logs` directory
## Dry-Run Mode
The script runs in dry-run mode by default, so you can check the sleep durations and insure that the sequence of commands suits your needs. In dry-run mode the script does not actually perform any SMART tests or invoke the `sleep` or `badblocks` programs.
In order to perform tests on drives, you will need to provide the `-f` option.
## `smartctl` Device Type
Some users with atypical hardware environments may need to modify the script and specify the `smartctl` command device type explictly with the `-d` option. User __bcmryan__ reports success using `-d sat` with a Western Digital MyBook 8TB external drive enclosure.
## FreeBSD/FreeNAS Notes
## FreeBSD / FreeNAS Notes
Before using the script on FreeBSD systems (including FreeNAS) you should first execute the `sysctl` command below to alter the kernel's geometry debug flags. This allows `badblocks` to write to the entire disk:
Before using the script on FreeBSD systems (including FreeNAS) you must first execute this `sysctl` command to alter the kernel's geometry debug flags. This allows `badblocks` to write to the entire disk:
`sysctl kern.geom.debugflags=0x10`
Also note that `badblocks` may issue the following warning under FreeBSD/FreeNAS, which can safely be ignored as it has no effect on testing:
Also note that `badblocks` may issue the following warning under FreeBSD / FreeNAS, which can safely be ignored as it has no effect on testing:
`set_o_direct: Inappropiate ioctl for device`
## Operating System Compatibility
Tested under:
* FreeNAS 9.10.2-U1 (FreeBSD 10.3-STABLE)
* FreeNAS 11.1-U7 (FreeBSD 11.1-STABLE)
* FreeNAS 11.2-U8 (FreeBSD 11.2-STABLE)
* Ubuntu Server 16.04.2 LTS
* CentOS 7.0
* Tiny Core Linux 11.1
* Fedora 33 Workstation
## Drive Models Tested
The script should run successfully on any SATA disk with SMART capabilities, which includes just about all modern drives. It has been tested on these particular devices:
* HGST Deskstar NAS, UltraStar, UltraStar He10, and UltraStar He12 models
* Western Digital Gold, Black, and Re models
The script should run successfully on any SAS or SATA disk with SMART capabilities, which includes just about all modern drives. It has been tested on these particular devices:
* Intel
* DC S3700 SSD
* Model 320 Series SSD
* HGST
* Deskstar NAS (HDN724040ALE640)
* Ultrastar 7K4000 (HUS724020ALE640)
* Ultrastar He10
* Ultrastar He12
* Western Digital
* Black (WD6001FZWX)
* Gold
* Re (WD4000FYYZ)
* Green
* Red
* WD140EDFZ
* Seagate
* IronWolf NAS HDD 12TB (ST12000VN0008)
* IronWolf NAS HDD 8TB (ST8000NE001-2M7101)
## Prerequisites
Requires the smartmontools, available at https://www.smartmontools.org
Uses: `grep`, `pcregrep`, `awk`, `sed`, `tr`, `sleep`, `badblocks`
smartmontools, available at [www.smartmontools.org](https://www.smartmontools.org)
Tested with the static analysis tool at https://www.shellcheck.net to insure that the code is POSIX-compliant and free of issues.
Uses: `grep`, `awk`, `sed`, `sleep`, `badblocks`, `smartctl`
Tested with the static analysis tool at [www.shellcheck.net](https://www.shellcheck.net) to insure that the code is POSIX-compliant and free of issues.
## Author
Written by Keith Nash, March 2017.
Modified on 19 August 2020.
Original author: Keith Nash, March 2017.
Modified on 19 February 2021.

View File

@@ -1,39 +0,0 @@
+-----------------------------------------------------------------------------
+ Started burn-in of /dev/da8 on boomer : Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Drive Model: HGST_HUS724020ALE640
Serial Number: PKXXXXXXXXXXXX
Short test duration: 1 minutes
Short test sleep duration: 90 seconds (includes extra delay of 30 seconds)
Extended test duration: 332 minutes
Extended test sleep duration: 20220 seconds (includes extra delay of 300 seconds)
Log file: ./burnin-HGST_HUS724020ALE640_PKXXXXXXXXXXXX.log
Bad blocks file: ./burnin-HGST_HUS724020ALE640_PKXXXXXXXXXXXX.bb
+-----------------------------------------------------------------------------
+ Run SMART short test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Dry run: would start the SMART short test and sleep 90 seconds until the test finishes
Finished SMART short test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
+ Run SMART extended test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Dry run: would start the SMART extended test and sleep 20220 seconds until the test finishes
Finished SMART extended test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
+ Run badblocks test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Dry run: would run badblocks -b 4096 -wsv -o ./burnin-HGST_HUS724020ALE640_PKXXXXXXXXXXXX.bb /dev/da8
Finished badblocks test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
+ Run SMART short test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Dry run: would start the SMART short test and sleep 90 seconds until the test finishes
Finished SMART short test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
+ Run SMART extended test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
Dry run: would start the SMART extended test and sleep 20220 seconds until the test finishes
Finished SMART extended test on drive /dev/da8: Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------
+ Finished burn-in of /dev/da8 on boomer : Tue Mar 14 02:24:16 CDT 2017
+-----------------------------------------------------------------------------

View File

@@ -0,0 +1,45 @@
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + Started burn-in
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] Host: arch-desktop
[2020-09-09 21:58:23 CEST] OS Flavor: Linux
[2020-09-09 21:58:23 CEST] Drive: /dev/sdb
[2020-09-09 21:58:23 CEST] Disk Type: mechanical
[2020-09-09 21:58:23 CEST] Drive Model: SAMSUNG_HD204UI
[2020-09-09 21:58:23 CEST] Serial Number: XXXXXXXXXXXXXX
[2020-09-09 21:58:23 CEST] Short test duration: 2 minutes
[2020-09-09 21:58:23 CEST] 120 seconds
[2020-09-09 21:58:23 CEST] Extended test duration: 341 minutes
[2020-09-09 21:58:23 CEST] 20460 seconds
[2020-09-09 21:58:23 CEST] Log file: ./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.log
[2020-09-09 21:58:23 CEST] Bad blocks file: ./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.bb
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + Running SMART short test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] DRY RUN: smartctl --test="short" "/dev/sdb"
[2020-09-09 21:58:23 CEST] SMART short test started, awaiting completion for 120 seconds ...
[2020-09-09 21:58:23 CEST] DRY RUN: sleep "120"
[2020-09-09 21:58:23 CEST] DRY RUN: poll_selftest_complete
[2020-09-09 21:58:23 CEST] DRY RUN: smartctl --log=selftest "/dev/sdb" | tee -a "./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.log"
[2020-09-09 21:58:23 CEST] Finished SMART short test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + Running badblocks test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] DRY RUN: badblocks -b 4096 -wsv -e 1 -o "./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.bb" "/dev/sdb"
[2020-09-09 21:58:23 CEST] Finished badblocks test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + Running SMART long test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] DRY RUN: smartctl --test="long" "/dev/sdb"
[2020-09-09 21:58:23 CEST] SMART long test started, awaiting completion for 20460 seconds ...
[2020-09-09 21:58:23 CEST] DRY RUN: sleep "20460"
[2020-09-09 21:58:23 CEST] DRY RUN: poll_selftest_complete
[2020-09-09 21:58:23 CEST] DRY RUN: smartctl --log=selftest "/dev/sdb" | tee -a "./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.log"
[2020-09-09 21:58:23 CEST] Finished SMART long test
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + SMART and non-SMART information
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] DRY RUN: smartctl --xall --vendorattribute=7,hex48 "/dev/sdb" | tee -a "./burnin-SAMSUNG_HD204UI_XXXXXXXXXXXXXX.log"
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------
[2020-09-09 21:58:23 CEST] + Finished burn-in
[2020-09-09 21:58:23 CEST] +-----------------------------------------------------------------------------

907
disk-burnin.sh Normal file → Executable file
View File

@@ -1,370 +1,625 @@
#!/bin/sh
########################################################################
################################################################################
#
# disk-burnin.sh
#
# A script to simplify the process of burning-in disks. Intended for use
# only on disks which do not contain valuable data, such as new disks or
# disks which are being tested or re-purposed.
#
# Be aware that:
#
# 1> This script runs the badblocks program in destructive mode, which
# erases any data on the disk.
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!!!! WILL DESTROY THE DISK CONTENTS! BE CAREFUL! !!!!!
# !!!!! DO NOT RUN THIS SCRIPT ON DISKS CONTAINING DATA YOU VALUE !!!!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# 2> Run times for large disks can take several days to complete, so it
# is a good idea to use tmux sessions to prevent mishaps.
#
# 3> Must be run as 'root'.
#
# 4> Tests of large drives can take days to complete: use tmux!
#
# Performs these steps:
#
# 1> Run SMART short test
# 2> Run badblocks
# 3> Run SMART extended test
#
# The script sleeps after starting each SMART test, using a duration
# based on the polling interval reported by the disk, after which the
# script will poll the disk to verify the self-test has completed.
#
# Full SMART information is pulled after each SMART test. All output
# except for the sleep command is echoed to both the screen and log file.
#
# You should monitor the burn-in progress and watch for errors, particularly
# any errors reported by badblocks, or these SMART errors:
#
# 5 Reallocated_Sector_Ct
# 196 Reallocated_Event_Count
# 197 Current_Pending_Sector
# 198 Offline_Uncorrectable
#
# These indicate possible problems with the drive. You therefore may
# wish to abort the remaining tests and proceed with an RMA exchange
# for new drives or discard old ones. Also please note that this list
# is not exhaustive.
#
# The script extracts the drive model and serial number and forms
# a log filename of the form 'burnin-[model]_[serial number].log'.
#
# badblocks is invoked with a block size of 4096, the -wsv options, and
# the -o option to instruct it to write the list of bad blocks found (if
# any) to a file named 'burnin-[model]_[serial number].bb'.
#
# The only required command-line argument is the device specifier, e.g.:
#
# ./disk-burnin.sh sda
#
# ...will run the burn-in test on device /dev/sda
#
# You can run the script in 'dry run mode' (see below) to check the sleep
# duration calculations and to insure that the sequence of commands suits
# your needs. In 'dry runs' the script does not actually perform any
# SMART tests or invoke the sleep or badblocks programs. The script is
# distributed with 'dry runs' enabled, so you will need to edit the
# Dry_Run variable below, setting it to 0, in order to actually perform
# tests on drives.
#
# Before using the script on FreeBSD systems (including FreeNAS) you must
# first execute this sysctl command to alter the kernel's geometry debug
# flags. This allows badblocks to write to the entire disk:
#
# sysctl kern.geom.debugflags=0x10
#
# Tested under:
# FreeNAS 9.10.2 (FreeBSD 10.3-STABLE)
# Ubuntu Server 16.04.2 LTS
#
# Tested on:
# Intel DC S3700 SSD
# Intel Model 320 Series SSD
# HGST Deskstar NAS (HDN724040ALE640)
# Hitachi/HGST Ultrastar 7K4000 (HUS724020ALE640)
# Western Digital Re (WD4000FYYZ)
# Western Digital Black (WD6001FZWX)
#
# Requires the smartmontools, available at https://www.smartmontools.org
#
# Uses: grep, pcregrep, awk, sed, tr, sleep, badblocks
#
# Written by Keith Nash, March 2017
#
# KN, 8 Apr 2017:
# Added minimum test durations because some devices don't return accurate values.
# Added code to clean up the log file, removing copyright notices, etc.
# No longer echo 'smartctl -t' output to log file as it imparts no useful information.
# Emit test results after tests instead of full 'smartctl -a' output.
# Emit full 'smartctl -x' output at the end of all testing.
# Minor changes to log output and formatting.
#
# KN, 12 May 2017:
# Added code to poll the disk and check for completed self-tests.
#
# As noted above, some disks don't report accurate values for the short and extended
# self-test intervals, sometimes by a significant amount. The original approach using
# 'fudge' factors wasn't reliable and the script would finish even though the SMART
# self-tests had not completed. The new polling code helps insure that this doesn't
# happen.
#
# Fixed code to work around annoying differences between sed's behavior on Linux and
# FreeBSD.
#
# KN, 8 Jun 2017
# Modified parsing of short and extended test durations to accommodate the values
# returned by larger drives; we needed to strip out the '(' and ')' characters
# surrounding the integer value in order to fetch it reliably.
#
# KN, 19 Aug 2020
# Changed Dry_Run value so that dry runs are no longer the default setting.
# Changed badblocks call to exit immediately on first error.
# Set logging directoryto current working directory using pwd command.
# Reduced default tests so that we run:
# 1> Short SMART test
# 2> badblocks
# 3> Extended SMART test
#
########################################################################
################################################################################
if [ $# -ne 1 ]; then
echo "Error: not enough arguments!"
echo "Usage is: $0 drive_device_specifier"
################################################################################
# PRE-EXECUTION VALIDATION
################################################################################
# Check if running as root
if [ "$(id -u)" -ne 0 ]; then
echo "ERROR: Must be run as root" >&2
exit 2
fi
Drive=$1
# Check required dependencies
readonly DEPENDENCIES="awk badblocks grep sed sleep smartctl"
for dependency in ${DEPENDENCIES}; do
if ! command -v "${dependency}" > /dev/null 2>&1; then
echo "ERROR: Command '${dependency}' not found" >&2
exit 2
fi
done
# Set Dry_Run to a non-zero value to test out the script without actually
# running any tests; leave it set to zero to burn-in disks.
readonly USAGE=\
"NAME
$(basename "$0") -- disk burn-in program
Dry_Run=0
SYNOPSIS
$(basename "$0") [-h] [-b <block_size>] [-c <num_blocks>] [-e] [-f] [-o <directory>] [-x] <disk>
# Directory specifiers for log and badblocks data files. Leave off the
# trailing slash if you specify a value. Default is the current working
# directory.
DESCRIPTION
A script to simplify the process of burning-in disks. Only intended for use
on disks which do not contain any data, such as new disks or disks which
are being tested or re-purposed.
Log_Dir=$(pwd)
BB_Dir=$(pwd)
The script runs in dry-run mode by default, so you can check the sleep
durations and to insure that the sequence of commands suits your needs. In
dry-run mode the script does not actually perform any SMART tests or invoke
the sleep or badblocks programs.
# Alternative:
#Log_Dir="."
#BB_Dir="."
In order to perform tests on drives, you will need to provide the -f option.
########################################################################
#
# Prologue
#
########################################################################
OPTIONS
-h Show help text
-e Show extended help text
-b <block_size> Override block size (defaults to 8192)
-c <num_blocks> Override concurrent number of blocks tested
-f Force script to run in destructive mode
ALL DATA ON THE DISK WILL BE LOST!
-o <directory> Write log files to <directory> (default: $(pwd))
-x Run full pass of badblocks instead of exiting on first error
<disk> Disk to burn-in (/dev/ may be omitted)
# Obtain the disk model and serial number:
EXAMPLES
$(basename "$0") sda
run in dry-run mode on disk /dev/sda
Disk_Model=$(smartctl -i /dev/"$Drive" | grep "Device Model" | awk '{print $3, $4, $5}' | sed -e 's/^[ \t]*//;s/[ \t]*$//' | sed -e 's/ /_/')
$(basename "$0") -f /dev/sdb
run in destructive, non-dry mode on disk /dev/sdb
if [ -z "$Disk_Model" ]; then
Disk_Model=$(smartctl -i /dev/"$Drive" | grep "Model Family" | awk '{print $3, $4, $5}' | sed -e 's/^[ \t]*//;s/[ \t]*$//' | sed -e 's/ /_/')
$(basename "$0") -f -o ~/burn-in-logs sdc
run in destructive, non-dry mode on disk /dev/sdc and
write the log files to ~/burn-in-logs directory
"
readonly USAGE_2=\
"EXIT STATUS
exit 0: script finishes successfully
exit 2: dependencies are missing
not running as 'root'
illegal options are provided
NOTES
Be warned that:
1> The script runs badblocks in destructive mode, which erases any data
on the disk.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!! ALL DATA ON THE DISK WILL BE LOST! BE CAREFUL! !!!!
!!!! DO NOT RUN THIS SCRIPT ON DISKS CONTAINING VALUABLE DATA !!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2> Run times for large disks can be several days. Use tmux or screen
to test multiple disks in parallel.
3> Must be run as 'root'.
4> The script has the following dependencies:
smartmontools, available at https://www.smartmontools.org
Uses: grep, awk, sed, sleep, badblocks
Performs this test sequence:
1> Run SMART short test
2> Run badblocks
3> Run SMART extended test
The script sleeps after starting each SMART test, using a duration based on
the polling interval reported by the disk, after which the script will poll
the disk to verify the self-test has completed.
Full SMART information is pulled after each SMART test. All output except
for the sleep command is written to both stdout and the log.
You should monitor the burn-in progress and watch for errors, particularly
any errors reported by badblocks, or these SMART errors:
5 Reallocated_Sector_Ct
196 Reallocated_Event_Count
197 Current_Pending_Sector
198 Offline_Uncorrectable
These indicate possible problems with the drive. You therefore may wish to
abort the remaining tests and proceed with an RMA exchange for new drives or
discard old ones. Please note that this list is not exhaustive.
The script extracts the drive model and serial number and forms a log file-
name of the form 'burnin-[model]_[serial number].log'.
badblocks is invoked with a block size of 8192, the -wsv options, and the
-o option to instruct it to write the list of bad blocks found (if any) to
a file named 'burnin-[model]_[serial number].bb'.
Before using the script on FreeBSD systems (including FreeNAS) you must
first execute this sysctl command to alter the kernel's geometry debug
flags. This allows badblocks to write to the entire disk:
sysctl kern.geom.debugflags=0x10
Also note that badblocks may issue the following warning under FreeBSD /
FreeNAS, which can safely be ignored as it has no effect on testing:
set_o_direct: Inappropiate ioctl for device
Tested operating systems:
FreeNAS 9.10.2 (FreeBSD 10.3-STABLE)
FreeNAS 11.1-U7 (FreeBSD 11.1-STABLE)
FreeNAS 11.2-U8 (FreeBSD 11.2-STABLE)
Ubuntu Server 16.04.2 LTS
CentOS 7.0
Tiny Core Linux 11.1
Tested disks:
Intel
DC S3700 SSD
Model 320 Series SSD
HGST
Deskstar NAS (HDN724040ALE640)
Ultrastar 7K4000 (HUS724020ALE640)
Ultrastar He10
Ultrastar He12
Western Digital
Black (WD6001FZWX)
Gold
Re (WD4000FYYZ)
Seagate
IronWolf NAS HDD 12TB (ST12000VN0008)
VERSIONS
Written by Keith Nash, March 2017
KN, 8 Apr 2017:
Added minimum test durations because some devices don't return accurate
values.
Added code to clean up the log file, removing copyright notices, etc.
No longer echo 'smartctl -t' output to log file as it imparts no useful
information.
Emit test results after tests instead of full 'smartctl -a' output.
Emit full 'smartctl -x' output at the end of all testing.
Minor changes to log output and formatting.
KN, 12 May 2017:
Added code to poll the disk and check for completed self-tests.
As noted above, some disks don't report accurate values for the short
and extended self-test intervals, sometimes by a significant amount.
The original approach using 'fudge' factors wasn't reliable and the
script would finish even though the SMART self-tests had not completed.
The new polling code helps insure that this doesn't happen.
Fixed code to work around annoying differences between sed's behavior
on Linux and FreeBSD.
KN, 8 Jun 2017
Modified parsing of short and extended test durations to accommodate the
values returned by larger drives; we needed to strip out the '(' and ')'
characters surrounding the integer value in order to fetch it reliably.
KN, 19 Aug 2020
Changed DRY_RUN value so that dry runs are no longer the default
setting.
Changed badblocks call to exit immediately on first error.
Set logging directory to current working directory using pwd command.
Reduced default tests so that we run:
1> Short SMART test
2> badblocks
3> Extended SMART test
MS, 9 Sep 2020
Add .editorconfig to streamlime editor behavior for developers.
Remove dependencies on pcregrep and tr.
Add documentation to functions and complex statements.
Reduce code duplication, simplify and decouple code where possible.
Improve portability and resiliency.
Check availability of dependencies during runtim.
Check for root privileges during runtime.
Add option parsing, most notably (-h)elp and -f for non-dry-run mode.
Add dry_run_wrapper() function.
Add disk type detection to skip badblocks for non-mechanical drives.
KN, 5 Oct 2020
Added -x option to control the badblocks -e option, allowing extended testing.
Added smartctl to the list of dependencies.
Changed disk type detection so that we assume all drives are mechanical drives
unless they explicitly return 'Solid State Drive' for Rotational Rate.
Removed datestamp from every line of log output, only emitting it in log headers.
Minor reformatting.
KY, 30 May 2022
Added -b & -c options to control respective badblocks options."
# badblocks default -e option is 1, stop testing if a single error occurs
BB_E_ARG=1
# badblocks default -b option is 1024, but we default to 8192. This allows overriding if desired.
BB_B_ARG=8192
# badblocks default -c option is 64, and this allows overriding
BB_C_ARG=64
# parse options
while getopts ':hefo:b:c:x' option; do
case "${option}" in
h) echo "${USAGE}"
exit
;;
e) echo "${USAGE}"
echo "${USAGE_2}"
exit
;;
f) readonly DRY_RUN=0
;;
o) LOG_DIR="${OPTARG}"
;;
b) BB_B_ARG="${OPTARG}"
;;
c) BB_C_ARG="${OPTARG}"
;;
x) BB_E_ARG=0
;;
:) printf 'Missing argument for -%s\n' "${OPTARG}" >&2
echo "${USAGE}" >&2
exit 2
;;
\?) printf 'Illegal option: -%s\n' "${OPTARG}" >&2
echo "${USAGE}" >&2
exit 2
;;
esac
done
shift $(( OPTIND - 1 ))
if [ -z "$1" ]; then
echo "ERROR: Missing disk argument" >&2
echo "${USAGE}" >&2
exit 2
fi
Serial_Number=$(smartctl -i /dev/"$Drive" | grep -i "Serial Number" | awk '{print $3}' | sed -e 's/ /_/')
################################################################################
# CONSTANTS
################################################################################
# Form the log and bad blocks data filenames:
readonly BB_E_ARG
readonly BB_B_ARG
readonly BB_C_ARG
Log_File="burnin-${Disk_Model}_${Serial_Number}.log"
Log_File=$Log_Dir/$Log_File
# Drive to burn-in
DRIVE="$1"
# prepend /dev/ if necessary
if ! printf '%s' "${DRIVE}" | grep "/dev/\w*" > /dev/null 2>&1; then
DRIVE="/dev/${DRIVE}"
fi
readonly DRIVE
BB_File="burnin-${Disk_Model}_${Serial_Number}.bb"
BB_File=$BB_Dir/$BB_File
if [ ! -e "$DRIVE" ]; then
echo "ERROR: Disk does not exist: $DRIVE" >&2
echo "${USAGE}" >&2
exit 2
fi
# Query the short and extended test duration, in minutes. Use the values to
# calculate how long we should sleep after starting the SMART tests:
# Set to working directory if -o <directory> wasn't provided
[ -z "${LOG_DIR}" ] && LOG_DIR="$(pwd)"
# Trim trailing slashes
LOG_DIR="$(printf '%s' "${LOG_DIR}" | awk '{gsub(/\/+$/, ""); printf $1}')"
readonly LOG_DIR
Short_Test_Minutes=$(smartctl -c /dev/"$Drive" | pcregrep -M "Short self-test routine.*\n.*recommended polling time:" | sed -e 's/)//;s/(//' | awk '{print $4}' | tr -d '\n')
#printf "Short_Test_Minutes=[%s]\n" ${Short_Test_Minutes}
# System information
readonly HOSTNAME="$(hostname)"
readonly OS_FLAVOR="$(uname)"
Extended_Test_Minutes=$(smartctl -c /dev/"$Drive" | pcregrep -M "Extended self-test routine.*\n.*recommended polling time:" | sed -e 's/)//;s/(//' | awk '{print $4}' | tr -d '\n')
#printf "Extended_Test_Minutes=[%s]\n" ${Extended_Test_Minutes}
# SMART static information
readonly SMART_INFO="$(smartctl --info "${DRIVE}")"
readonly SMART_CAPABILITIES="$(smartctl --capabilities "${DRIVE}")"
Short_Test_Sleep=$((Short_Test_Minutes*60))
Extended_Test_Sleep=$((Extended_Test_Minutes*60))
# Selftest polling timeout interval, in hours
Poll_Timeout_Hours=4
# Calculate the selftest polling timeout interval in seconds
Poll_Timeout=$((Poll_Timeout_Hours*60*60))
# Polling sleep interval, in seconds:
Poll_Interval=15
########################################################################
#
# Local functions
#
########################################################################
echo_str()
{
echo "$1" | tee -a "$Log_File"
##################################################
# Get SMART information value.
# Globals:
# SMART_INFO
# Arguments:
# value identifier:
# !!! Only TWO WORD indentifiers are supported !!!
# !!! Querying e.g. "ATA Version is" will fail !!!
# - Device Model
# - Model Family
# - Serial Number
# Outputs:
# Write value to stdout.
##################################################
get_smart_info_value() {
# $1=$2=""; select all but first two columns
# gsub(/^[ \t]+|[ \t]+$/, ""); replace leading and trailing whitespace
# gsub(/ /, "_"); replace remaining spaces with underscores
# printf $1 print result without newline at the end
printf '%s' "${SMART_INFO}" \
| grep "$1" \
| awk '{$1=$2=""; gsub(/^[ \t]+|[ \t]+$/, ""); gsub(/ /, "_"); printf $1}'
}
push_header()
{
echo_str "+-----------------------------------------------------------------------------"
##################################################
# Get SMART recommended test duration, in minutes.
# Globals:
# SMART_CAPABILITIES
# Arguments:
# test type:
# - Short
# - Extended
# - Conveyance
# Outputs:
# Write duration to stdout.
##################################################
get_smart_test_duration() {
# '/'"$1"' self-test routine/ match duration depending on test type arg
# getline; jump to next line
# gsub(/\(|\)/, ""); remove parantheses
# printf $4 print 4th column without newline at the end
printf '%s' "${SMART_CAPABILITIES}" \
| awk '/'"$1"' self-test routine/{getline; gsub(/\(|\)/, ""); printf $4}'
}
poll_selftest_complete()
{
l_rv=1
l_status=0
l_done=0
l_pollduration=0
# Get disk model
DISK_MODEL="$(get_smart_info_value "Device Model")"
[ -z "${DISK_MODEL}" ] && DISK_MODEL="$(get_smart_info_value "Model Family")"
[ -z "${DISK_MODEL}" ] && DISK_MODEL="$(get_smart_info_value "Model Number")"
readonly DISK_MODEL
# Check SMART results for "The previous self-test routine completed"
# Return 0 if the test has completed, 1 if we exceed our polling timeout interval
# Get disk type; unless we get 'Solid State Device' as return value, assume
# we have a mechanical drive.
DISK_TYPE="$(get_smart_info_value "Rotation Rate")"
if printf '%s' "${DISK_TYPE}" | grep -i "solid_state_device" > /dev/null 2>&1; then
DISK_TYPE="SSD"
fi
readonly DISK_TYPE
while [ $l_done -eq 0 ];
do
smartctl -a /dev/"$Drive" | grep -i "The previous self-test routine completed" > /dev/null 2<&1
l_status=$?
if [ $l_status -eq 0 ]; then
echo_str "SMART self-test complete"
l_rv=0
l_done=1
else
# Check for failure
smartctl -a /dev/"$Drive" | grep -i "of the test failed." > /dev/null 2<&1
l_status=$?
if [ $l_status -eq 0 ]; then
echo_str "SMART self-test failed"
l_rv=0
l_done=1
else
if [ $l_pollduration -ge "${Poll_Timeout}" ]; then
echo_str "Timeout polling for SMART self-test status"
l_done=1
else
sleep ${Poll_Interval}
l_pollduration=$((l_pollduration+Poll_Interval))
fi
fi
# Get disk serial number
readonly SERIAL_NUMBER="$(get_smart_info_value "Serial Number")"
# SMART short test duration
readonly SHORT_TEST_MINUTES="$(get_smart_test_duration "Short")"
readonly SHORT_TEST_SECONDS="$(( SHORT_TEST_MINUTES * 60))"
# SMART extended test duration
readonly EXTENDED_TEST_MINUTES="$(get_smart_test_duration "Extended")"
readonly EXTENDED_TEST_SECONDS="$(( EXTENDED_TEST_MINUTES * 60 ))"
# Maximum duration the completion status is polled
readonly POLL_TIMEOUT_HOURS=4
readonly POLL_TIMEOUT_SECONDS="$(( POLL_TIMEOUT_HOURS * 60 * 60))"
# Sleep interval between completion status polls
readonly POLL_INTERVAL_SECONDS=15
# Form log file names
readonly LOG_FILE="${LOG_DIR}/burnin-${DISK_MODEL}_${SERIAL_NUMBER}.log"
readonly BB_File="${LOG_DIR}/burnin-${DISK_MODEL}_${SERIAL_NUMBER}.bb"
################################################################################
# FUNCTIONS
################################################################################
##################################################
# Log informational message.
# Globals:
# LOG_FILE
# Arguments:
# Message to log.
# Outputs:
# Write message to stdout and log file.
##################################################
log_info() {
# now="$(date +"%F %T %Z")"
# printf "%s\n" "[${now}] $1" | tee -a "${LOG_FILE}"
printf "%s\n" "$1" | tee -a "${LOG_FILE}"
}
##################################################
# Log emphasized header message.
# Arguments:
# Message to log.
##################################################
log_header() {
log_info "+-----------------------------------------------------------------------------"
log_info "+ $1: $(date)"
log_info "+-----------------------------------------------------------------------------"
}
##################################################
# Ensure log directory exists and remove old logs.
# Globals:
# LOG_DIR
# LOG_FILE
# Arguments:
# None
##################################################
init_log() {
mkdir -p -- "${LOG_DIR}" || exit 2
[ -e "${LOG_FILE}" ] && rm -- "${LOG_FILE}"
}
##################################################
# Remove redundant messages from log.
# Globals:
# LOG_FILE
# OS_FLAVOR
# Arguments:
# None
##################################################
cleanup_log() {
if [ "${OS_FLAVOR}" = "Linux" ]; then
sed -i -e '/Copyright/d' "${LOG_FILE}"
sed -i -e '/=== START OF READ/d' "${LOG_FILE}"
sed -i -e '/SMART Attributes Data/d' "${LOG_FILE}"
sed -i -e '/Vendor Specific SMART/d' "${LOG_FILE}"
sed -i -e '/SMART Error Log Version/d' "${LOG_FILE}"
fi
if [ "${OS_FLAVOR}" = "FreeBSD" ]; then
sed -i '' -e '/Copyright/d' "${LOG_FILE}"
sed -i '' -e '/=== START OF READ/d' "${LOG_FILE}"
sed -i '' -e '/SMART Attributes Data/d' "${LOG_FILE}"
sed -i '' -e '/Vendor Specific SMART/d' "${LOG_FILE}"
sed -i '' -e '/SMART Error Log Version/d' "${LOG_FILE}"
fi
}
##################################################
# Log command in dry-run mode, run command otherwise.
# Globals:
# DRY_RUN
# Arguments:
# Command to run.
##################################################
dry_run_wrapper() {
if [ -z "$DRY_RUN" ]; then
log_info "DRY RUN: $*"
return 0
fi
eval "$@"
}
##################################################
# Log runtime information about current burn-in.
# Globals:
# HOSTNAME
# OS_FLAVOR
# DRIVE
# DISK_TYPE
# DISK_MODEL
# SERIAL_NUMBER
# SHORT_TEST_MINUTES
# SHORT_TEST_SECONDS
# EXTENDED_TEST_MINUTES
# EXTENDED_TEST_SECONDS
# LOG_FILE
# BB_File
# Arguments:
# None
##################################################
log_runtime_info() {
log_info "Host: ${HOSTNAME}"
log_info "OS: ${OS_FLAVOR}"
log_info "Drive: ${DRIVE}"
log_info "Disk Type: ${DISK_TYPE}"
log_info "Drive Model: ${DISK_MODEL}"
log_info "Serial Number: ${SERIAL_NUMBER}"
log_info "Short test duration: ${SHORT_TEST_MINUTES} minutes"
log_info " ${SHORT_TEST_SECONDS} seconds"
log_info "Extended test duration: ${EXTENDED_TEST_MINUTES} minutes"
log_info " ${EXTENDED_TEST_SECONDS} seconds"
log_info "Log file: ${LOG_FILE}"
log_info "Bad blocks file: ${BB_File}"
}
##################################################
# Poll repeatedly whether SMART self-test has completed.
# Globals:
# DRIVE
# POLL_INTERVAL_SECONDS
# POLL_TIMEOUT_SECONDS
# Arguments:
# None
# Returns:
# 0 if success or failure.
# 1 if timeout threshold exceeded.
##################################################
poll_selftest_complete() {
l_poll_duration_seconds=0
while [ "${l_poll_duration_seconds}" -lt "${POLL_TIMEOUT_SECONDS}" ]; do
smartctl --all "${DRIVE}" \
| grep -i "The previous self-test routine completed" > /dev/null 2>&1
l_status="$?"
if [ "${l_status}" -eq 0 ]; then
log_info "SMART self-test succeeded"
return 0
fi
smartctl --all "${DRIVE}" \
| grep -i "of the test failed\." > /dev/null 2>&1
l_status="$?"
if [ "${l_status}" -eq 0 ]; then
log_info "SMART self-test failed"
return 0
fi
sleep "${POLL_INTERVAL_SECONDS}"
l_poll_duration_seconds="$(( l_poll_duration_seconds + POLL_INTERVAL_SECONDS ))"
done
return $l_rv
log_info "SMART self-test timeout threshold exceeded"
return 1
}
run_short_test()
{
push_header
echo_str "+ Run SMART short test on drive /dev/${Drive}: $(date)"
push_header
if [ "${Dry_Run}" -eq 0 ]; then
smartctl -t short /dev/"$Drive"
echo_str "Short test started, sleeping ${Short_Test_Sleep} seconds until it finishes"
sleep ${Short_Test_Sleep}
poll_selftest_complete
smartctl -l selftest /dev/"$Drive" | tee -a "$Log_File"
##################################################
# Run SMART test and log results.
# Globals:
# DRIVE
# LOG_FILE
# Arguments:
# Test type:
# - short
# - long
# Test duration in seconds.
##################################################
run_smart_test() {
log_header "Running SMART $1 test"
dry_run_wrapper "smartctl --test=\"$1\" \"${DRIVE}\""
log_info "SMART $1 test started, awaiting completion for $2 seconds ..."
dry_run_wrapper "sleep \"$2\""
dry_run_wrapper "poll_selftest_complete"
dry_run_wrapper "smartctl --log=selftest \"${DRIVE}\" | tee -a \"${LOG_FILE}\""
log_info "Finished SMART $1 test"
}
##################################################
# Run badblocks test.
# !!! ALL DATA ON THE DISK WILL BE LOST !!!
# Globals:
# BB_File
# DISK_TYPE
# DRIVE
# Arguments:
# None
##################################################
run_badblocks_test() {
log_header "Running badblocks test"
if [ "${DISK_TYPE}" != "SSD" ]; then
dry_run_wrapper "badblocks -b ${BB_B_ARG} -wsv -c ${BB_C_ARG} -e ${BB_E_ARG} -o \"${BB_File}\" \"${DRIVE}\""
else
echo_str "Dry run: would start the SMART short test and sleep ${Short_Test_Sleep} seconds until the test finishes"
log_info "SKIPPED: badblocks for ${DISK_TYPE} device"
fi
echo_str "Finished SMART short test on drive /dev/${Drive}: $(date)"
log_info "Finished badblocks test"
}
run_extended_test()
{
push_header
echo_str "+ Run SMART extended test on drive /dev/${Drive}: $(date)"
push_header
if [ "${Dry_Run}" -eq 0 ]; then
smartctl -t long /dev/"$Drive"
echo_str "Extended test started, sleeping ${Extended_Test_Sleep} seconds until it finishes"
sleep ${Extended_Test_Sleep}
poll_selftest_complete
smartctl -l selftest /dev/"$Drive" | tee -a "$Log_File"
else
echo_str "Dry run: would start the SMART extended test and sleep ${Extended_Test_Sleep} seconds until the test finishes"
fi
echo_str "Finished SMART extended test on drive /dev/${Drive}: $(date)"
##################################################
# Log extensive SMART and non-SMART drive information.
# Globals:
# DRIVE
# LOG_FILE
# Arguments:
# None
##################################################
log_full_device_info() {
log_header "Drive information"
dry_run_wrapper "smartctl --xall --vendorattribute=7,hex48 \"${DRIVE}\" | tee -a \"${LOG_FILE}\""
}
run_badblocks_test()
{
push_header
echo_str "+ Run badblocks test on drive /dev/${Drive}: $(date)"
push_header
if [ "${Dry_Run}" -eq 0 ]; then
#
# This is the command which erases all data on the disk:
#
badblocks -b 4096 -wsv -e 1 -o "$BB_File" /dev/"$Drive"
else
echo_str "Dry run: would run badblocks -b 4096 -wsv -e 1 -o ${BB_File} /dev/${Drive}"
fi
echo_str "Finished badblocks test on drive /dev/${Drive}: $(date)"
##################################################
# Main function of script.
# Globals:
# SHORT_TEST_SECONDS
# EXTENDED_TEST_SECONDS
# Arguments:
# None
##################################################
main() {
init_log
log_header "Started burn-in"
log_runtime_info
# test sequence
run_smart_test "short" "${SHORT_TEST_SECONDS}"
run_badblocks_test
run_smart_test "long" "${EXTENDED_TEST_SECONDS}"
log_full_device_info
log_header "Finished burn-in"
cleanup_log
}
########################################################################
#
# Action begins here
#
########################################################################
if [ -e "$Log_File" ]; then
rm "$Log_File"
fi
push_header
echo_str "+ Started burn-in of /dev/${Drive} : $(date)"
push_header
echo_str "Host: $(hostname)"
echo_str "Drive Model: ${Disk_Model}"
echo_str "Serial Number: ${Serial_Number}"
echo_str "Short test duration: ${Short_Test_Minutes} minutes"
echo_str "Short test sleep duration: ${Short_Test_Sleep} seconds"
echo_str "Extended test duration: ${Extended_Test_Minutes} minutes"
echo_str "Extended test sleep duration: ${Extended_Test_Sleep} seconds"
echo_str "Log file: ${Log_File}"
echo_str "Bad blocks file: ${BB_File}"
# Run the test sequence:
run_short_test
#run_extended_test
run_badblocks_test
#run_short_test
run_extended_test
# Emit full device information to log:
push_header
echo_str "+ SMART information for drive /dev/${Drive}: $(date)"
push_header
smartctl -x -v 7,hex48 /dev/"$Drive" | tee -a "$Log_File"
push_header
echo_str "+ Finished burn-in of /dev/${Drive} : $(date)"
push_header
# Clean up the log file:
osflavor=$(uname)
if [ "${osflavor}" = "Linux" ]; then
sed -i -e '/Copyright/d' "${Log_File}"
sed -i -e '/=== START OF READ/d' "${Log_File}"
sed -i -e '/SMART Attributes Data/d' "${Log_File}"
sed -i -e '/Vendor Specific SMART/d' "${Log_File}"
sed -i -e '/SMART Error Log Version/d' "${Log_File}"
fi
if [ "${osflavor}" = "FreeBSD" ]; then
sed -i '' -e '/Copyright/d' "${Log_File}"
sed -i '' -e '/=== START OF READ/d' "${Log_File}"
sed -i '' -e '/SMART Attributes Data/d' "${Log_File}"
sed -i '' -e '/Vendor Specific SMART/d' "${Log_File}"
sed -i '' -e '/SMART Error Log Version/d' "${Log_File}"
fi
# Entrypoint
main

View File

@@ -1,6 +1,7 @@
MIT License
Copyright (c) 2017 by Keith Nash
Original work Copyright (c) 2017 by Keith Nash
Modified work Copyright (c) 2020 by Michael Schnerring
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal