7 min read

RAID1 drive failures on linux

I'm a real novice when it comes to hardware but I try to learn what I can. A few months ago I was reading about drive health monitoring and it wasn't something I'd really dealt with before. Given most of my experience is with cloud VPS's, that's usually opaque and handled for you. However, with my dedicated server this is definitely a concern I should have been looking at.

Monitoring drive health

After some research, I went ahead and installed smartmontools. This tool set does loads of things I don't really understand or know about. However, what I do know is that it runs frequent short and extended tests on all my drives.

I did some very light configuration changes to /etc/smartd.conf. The most important configuration was actually selecting tests and how to run them. I've got two disks, sda and sdb in RAID1. The following felt reasonable for me:

/dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03) -m username -M exec /usr/share/smartmontools/smartd-runner
/dev/sdb -a -o on -S on -s (S/../.././02|L/../../6/03) -m username -M exec /usr/share/smartmontools/smartd-runner

Where username is the system user you want any mail to go to. My understanding of these lines is that it'll monitor all attributes, enable online data collection, and autosave Attributes. It'll then run a short test every hour at the 2nd minute, and a long test once a day at 06:03. It'll do all of this using `smartd-runner`, which I don't really understand but I believe that is what will email me about failures.

By default it'll use the mail command to send any messages to the user defined in the -m flag. I have mail forwarding setup on my user to email to me via mailgun so this "just worked" for me. If you don't have mail forwarding setup, you may need to fiddle around here to get emails sent correctly.

The monitoring worked!

This weekend I received the following email from my server.

This message was generated by the smartd daemon running on:

   host name:  server01
   DNS domain: [Empty]

The following warning/error was logged by the smartd daemon:

Device: /dev/sdb [SAT], Self-Test Log error count increased from 0 to 1

Device info:
SAMSUNG MZ7LM480HMHQ-00005, S/N:S2UJNX0HB00354, WWN:5-002538-c404693d2, FW:GXT5104Q, 480 GB

For details see host's SYSLOG.

You can also use the smartctl utility for further investigation.
Another message will be sent in 24 hours if the problem persists.

I'll be honest, I had very little idea what it actually meant. Was this just a one-off or is this the near death of a drive? Thankfully the email gave me all the information I needed. When I got some time ssh'd into the box and started looking at the smartctl output. After figuring out the correct command incantation, I finally ended up with all of this detail.

$ smartctl --all /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-101-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

Model Family:     Samsung based SSDs
Device Model:     SAMSUNG MZ7LM480HCHP-00003
Serial Number:    S1YJNYAG700824
LU WWN Device Id: 5 002538 c00042297
Firmware Version: GXT3003Q
User Capacity:    480,103,981,056 bytes [480 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
TRIM Command:     Available, deterministic, zeroed
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4c
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon Apr  8 16:25:37 2024 UTC
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x82) Offline data collection activity
                                        was completed without error.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.
Total time to complete Offline
data collection:                ( 2100) seconds.
Offline data collection
capabilities:                    (0x53) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        No Offline surface scan supported.
                                        Self-test supported.
                                        No 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:        (  35) minutes.
SCT capabilities:              (0x003d) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   086   086   000    Old_age   Always       -       70368
 12 Power_Cycle_Count       0x0032   099   099   000    Old_age   Always       -       190
177 Wear_Leveling_Count     0x0013   089   089   005    Pre-fail  Always       -       810
179 Used_Rsvd_Blk_Cnt_Tot   0x0013   100   100   010    Pre-fail  Always       -       0
180 Unused_Rsvd_Blk_Cnt_Tot 0x0013   100   100   010    Pre-fail  Always       -       2459
181 Program_Fail_Cnt_Total  0x0032   100   100   010    Old_age   Always       -       0
182 Erase_Fail_Count_Total  0x0032   100   100   010    Old_age   Always       -       0
183 Runtime_Bad_Block       0x0013   100   100   010    Pre-fail  Always       -       0
184 End-to-End_Error        0x0033   100   100   097    Pre-fail  Always       -       0
187 Uncorrectable_Error_Cnt 0x0032   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0032   060   047   000    Old_age   Always       -       40
195 ECC_Error_Rate          0x001a   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   100   100   000    Old_age   Always       -       0
199 CRC_Error_Count         0x003e   100   100   000    Old_age   Always       -       0
202 Exception_Mode_Status   0x0033   100   100   010    Pre-fail  Always       -       0
235 POR_Recovery_Count      0x0012   099   099   000    Old_age   Always       -       177
241 Total_LBAs_Written      0x0032   099   099   000    Old_age   Always       -       413320316117
242 Total_LBAs_Read         0x0032   099   099   000    Old_age   Always       -       125592816548
243 SATA_Downshift_Ct       0x0032   100   100   000    Old_age   Always       -       0
244 Thermal_Throttle_St     0x0032   100   100   000    Old_age   Always       -       0
245 Timed_Workld_Media_Wear 0x0032   100   100   000    Old_age   Always       -       65535
246 Timed_Workld_RdWr_Ratio 0x0032   100   100   000    Old_age   Always       -       65535
247 Timed_Workld_Timer      0x0032   100   100   000    Old_age   Always       -       65535
251 NAND_Writes             0x0032   100   100   000    Old_age   Always       -       839601737312

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 without error       00%      4818         -
# 2  Short offline       Completed without error       00%      4790         -
# 3  Short offline       Completed without error       00%     29161         -
# 4  Extended offline    Completed without error       00%     27550         -
# 5  Extended offline    Completed without error       00%     27399         -
# 6  Extended offline    Completed without error       00%     27385         -

SMART Selective self-test log data structure revision number 1
    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
  255        0    65535  Read_scanning was completed without error
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 above is actually from the new drive, I didn't save a full version of it on the old drive, but this gives the gist. The value of the Reallocated_Sector_Ct attribute on the new drive is 0, which is good. On the old drive it was up to 4. I can't say with authority what is really happening there, but I can say it's bad. My understanding is that it means that 4 sectors on the SSD have been found bad and it's had to reallocate them. This number should always be 0 and the fact that it was not was a sign the drive was likely to totally fail soon.

As a side note, yes the new drive has several years of run time already. I'll talk about that more in a bit.

Drive replacement

So the alert triggered, and I was able to confirm that the drive was in near failure. Obviously the next move is to get that drive replaced.

The steps I probably should have gone through were:

  • Remove the drive from the linux RAID array
  • Open a request with Hetzner to have the drive replaced
  • Add the new drive to the array and wait for it to replicate across

In reality I wasn't aware of the first step until after I'd raised the replacement request. While I imagine the linux RAID can handle this scenario fine (and it did), I suspect properly removing it would probably be slightly safer.

So, I raised the replacement request with Hetzner. Being the cheapskate I am, I chose to get effectively whatever drive they had going. This was free, but does mean my new drive is several years old. This is perfectly fine for me, I'm happy with my backup process and don't mind if I have to go through this process again relatively soon. If I did want a newer drive, I could have paid 40EUR for one which was brand new or near new, maybe I'll do this next time - we'll see.

I also selected the option to power down the server rather than do a hotswap. This was entirely my choice and just felt a bit easier for me. Downtime isn't a problem for me, and given this was my first RAID recovery I wanted to keep things really simple.

Given I'd submitted the request on a Sunday evening, I expected it to get done sometime on Monday. I was pleasantly surprised to see it happened in about 10 minutes! I suppose this makes sense given their standard customer will be a business, but for a novice self-hoster this was much faster than I was expecting. I'm a big fan of that!

RAID array recovery

With the drive replaced, I ran a quick test to double check it was good. It was so it was time to add it back into the array. This isn't something I've done before, but I found [a great guide on HowtoForge](https://www.howtoforge.com/replacing_hard_disks_in_a_raid1_array).

The commands I ended up running were as follows.

# Partition the new drive to match the other one in the array
sfdisk -d /dev/sda | sfdisk /dev/sdb

# Double check the partitions...
fdisk -l

# Add each disk partition to the various array devices
mdadm --manage /dev/md0 --add /dev/sdb1
mdadm --manage /dev/md1 --add /dev/sdb2
mdadm --manage /dev/md2 --add /dev/sdb3

I had 3 array devices, and 3 partitions per drive so this deviated from the guide slightly.

After adding those devices into the arrays, the arrays started to rebuild automatically. I used cat /proc/mdstat to monitor the progress every so often, md1 was by far the biggest device data wise, but it still only took about 20 minutes.


I have a couple of learning points for myself from all of this.

  1. Monitoring disks is a really good idea. I'll probably set some of this up on my workstation. I keep everything backed up so drive loss wouldn't be much but an inconvenience but it's so easy to do I may as well.
  2. RAID1 seemed really easy to replace and recover from, before I go ahead with any other RAID configurations, I'll be sure to explore this whole process up front. This is definitely an area I'm pretty ignorant of, having lived most of my career in the managed VPS world.
  3. I need to improve my infra docs a little. I had a few bits about monitoring, but now I have the knowledge needed to write a run-book for replacing the disk on this sever. This definitely needs writing down and then I can probably get the whole thing sorted in an hour!