I received an alert yesterday on my home NAS unit. It indicated that there was an increase in the number of "pending sectors." Looking into the issue, it's really an error writing to the drive which hasn't been addressed and relocated. So the sector might be bad or might be good. If the sector is written to again and fails, it will be relocated. If it's written to without error, the sector will be marked good again.
The way to look at the error counts and other statistics that indicate the health of the drive is by using smart tools. In this case it was the drive at /dev/ada3 which had the problem so I did:Â
# smartctl -a /dev/ada3
Â
smartctl 6.6 2017-11-05 r4594 [FreeBSD 11.2-STABLE amd64] (local build)
Â
=== START OF INFORMATION SECTION ===
Model Family: Â Â Western Digital Red
Device Model: Â Â WDC WD40EFRX-68WT0N0
LU WWN Device Id: 5 0014ee 2631ae2f2
Firmware Version: 82.00A82
User Capacity: Â Â 4,000,787,030,016 bytes [4.00 TB]
Sector Sizes: Â Â 512 bytes logical, 4096 bytes physical
Rotation Rate: Â Â 5400 rpm
Device is: Â Â Â Â In smartctl database [for details use: -P show]
ATA Version is: Â ACS-2 (minor revision not indicated)
SATA Version is: Â SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is: Â Â Fri Jan 17 11:31:03 2020 EST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
Â
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
Â
General SMART Values:
Offline data collection status: Â (0x00) Offline data collection activity
was never started.
Auto Offline Data Collection: Disabled.
Self-test execution status: Â Â Â ( 121) The previous self-test completed having
the read element of the test failed.
Total time to complete Offline
data collection: (50880) seconds.
Offline data collection
capabilities: (0x7b) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
Offline surface scan supported.
Self-test supported.
Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: Â Â Â Â Â Â (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: Â Â Â Â (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( Â 2) minutes.
Extended self-test routine
recommended polling time: ( 509) minutes.
Conveyance self-test routine
recommended polling time: ( Â 5) minutes.
SCT capabilities: Â Â Â (0x703d) SCT Status supported.
SCT Error Recovery Control supported.
SCT Feature Control supported.
SCT Data Table supported.
Â
SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME Â Â Â Â Â FLAG Â Â VALUE WORST THRESH TYPE Â Â Â UPDATED Â WHEN_FAILED RAW_VALUE
 1 Raw_Read_Error_Rate   0x002f  200  200  051   Pre-fail  Always    -    44
 3 Spin_Up_Time       0x0027  190  177  021   Pre-fail  Always    -    7475
 4 Start_Stop_Count     0x0032  100  100  000   Old_age  Always    -    35
 5 Reallocated_Sector_Ct  0x0033  200  200  140   Pre-fail  Always    -    0
 7 Seek_Error_Rate     0x002e  200  200  000   Old_age  Always    -    0
 9 Power_On_Hours      0x0032  064  064  000   Old_age  Always    -    26304
 10 Spin_Retry_Count     0x0032  100  253  000   Old_age  Always    -    0
 11 Calibration_Retry_Count 0x0032  100  253  000   Old_age  Always    -    0
 12 Power_Cycle_Count    0x0032  100  100  000   Old_age  Always    -    35
192 Power-Off_Retract_Count 0x0032  200  200  000   Old_age  Always    -    17
193 Load_Cycle_Count     0x0032  200  200  000   Old_age  Always    -    502
194 Temperature_Celsius   0x0022  119  110  000   Old_age  Always    -    33
196 Reallocated_Event_Count 0x0032  200  200  000   Old_age  Always    -    0
197 Current_Pending_Sector  0x0032  200  200  000   Old_age  Always    -    0
198 Offline_Uncorrectable  0x0030  100  253  000   Old_age  Offline    -    0
199 UDMA_CRC_Error_Count   0x0032  200  200  000   Old_age  Always    -    0
200 Multi_Zone_Error_Rate  0x0008  100  253  000   Old_age  Offline    -    0
Â
SMART Error Log Version: 1
No Errors Logged
Â
SMART Self-test log structure revision number 1
Num  Test_Description   Status          Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline    Completed: read failure    90%   26301     48458008
# 2  Short offline    Completed: read failure    90%   26301     48458008
# 3  Short offline    Completed without error    00%   24742     -
Â
SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
  1     0     0  Not_testing
  2     0     0  Not_testing
  3     0     0  Not_testing
  4     0     0  Not_testing
  5     0     0  Not_testing
Selective self-test flags (0x0):
Â
 After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.
Â
The significant lines in this case are:Â
Â
196 Reallocated_Event_Count 0x0032  200  200  000   Old_age  Always    -    0
197 Current_Pending_Sector  0x0032  200  200  000   Old_age  Always    -    1
Â
Â
That shows a possible bad sector (only one) and that no relocations have ever taken place. You can also see that I ran a few short smartctl tests and they failed:
Â
Â
Num  Test_Description   Status          Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline    Completed: read failure    90%   26301     48458008
# 2  Short offline    Completed: read failure    90%   26301     48458008
Â
Â
I tried to think of the best way to clear this error by forcing the drive to relocate that sector or tell me that the drive is going bad and I should replace it.
The first thing I did was to read the sector and put the contents in a file. Now the logical block size is 512 bytes for the physical sector size is 4096 bytes (4k). You can't write anything smaller than one block. So we need to calculate how we will read that entire physical sector. Since the error logical block is given to us we can divide by 8 (4096 / 512 and remove any remainder). This will tell us where to start reading. In this case 48458008 / 8 yields a whole number 6057251. So that's the physical sector we want to deal with.
Â
We use the dd command to do the raw disk read:
Â
dd if=/dev/ada3 of=/tmp/output iseek=6057251 bs=4096 count=1
Â
The read completed successfully and produced a file /tmp/output. Is that the correct data that should be in that sector? I don't know. But at least we read what was there and saved it. Now we'll reverse the process and write that data back to the same disk sector.
Â
dd if=/tmp/output of=/dev/ada3 oseek=6057251 bs=4096 count=1
Â
The write was successful. Now we look at our smartctl statistics again.
Â
Â
196 Reallocated_Event_Count 0x0032 200 200 000 Old_age Always - 0
197 Current_Pending_Sector 0x0032 200 200 000 Old_age Always - 0
Â
Â
So it was able to write the sector back okay and relocation was not needed. Now we can do a smartctl test and it should pass.
Â
# smartctl -t short /dev/ada3
Â
Let it go for at least 2 minutes and then look at the test log again with smartctl -a /dev/ada3
Â
SMART Self-test log structure revision number 1
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
# 1 Short offline Completed without error 00% 26304 -
# 2 Short offline Completed: read failure 90% 26301 48458008
# 3 Short offline Completed: read failure 90% 26301 48458008
# 4 Short offline Completed without error 00% 24742 -
Â
We had a successful test. So that will get rid of the FreeNAS alert. Just to make sure we are completely okay I'll schedule a scrub of that drive pool and look at the results. If there's any data corruption it should hopefully fix that up.
Â