Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I had created two 2TB HDD partitions (/dev/sdb1 and /dev/sdc1) in a RAID 1 array called /dev/md0 using mdadm on Ubuntu 12.04 LTS Precise Pangolin.

The command sudo mdadm --detail /dev/md0 used to indicate both drives as active sync.

Then, for testing, I failed /dev/sdb1, removed it, then added it again with the command sudo mdadm /dev/md0 --add /dev/sdb1

watch cat /proc/mdstat showed a progress bar of the array rebuilding, but I wouldn't spend hours watching it, so I assumed that the software knew what it was doing.

After the progress bar was no longer showing, cat /proc/mdstat displays:

md0 : active raid1 sdb1[2](S) sdc1[1]
      1953511288 blocks super 1.2 [2/1] [U_]

And sudo mdadm --detail /dev/md0 shows:

/dev/md0:
        Version : 1.2
  Creation Time : Sun May 27 11:26:05 2012
     Raid Level : raid1
     Array Size : 1953511288 (1863.01 GiB 2000.40 GB)
  Used Dev Size : 1953511288 (1863.01 GiB 2000.40 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Mon May 28 11:16:49 2012
          State : clean, degraded 
 Active Devices : 1
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 1

           Name : Deltique:0  (local to host Deltique)
           UUID : 49733c26:dd5f67b5:13741fb7:c568bd04
         Events : 32365

    Number   Major   Minor   RaidDevice State
       1       8       33        0      active sync   /dev/sdc1
       1       0        0        1      removed

       2       8       17        -      spare   /dev/sdb1

I've been told that mdadm automatically replaces removed drives with spares, but /dev/sdb1 isn't being moved into the expected position, RaidDevice 1.


UPDATE (30 May 2012): A badblocks destructive read-write test of the entire /dev/sdb yielded no errors as expected; both HDDs are new.

As of the latest edit, I assembled the array with this command:

sudo mdadm --assemble --force --no-degraded /dev/md0 /dev/sdb1 /dev/sdc1

The output was:

mdadm: /dev/md0 has been started with 1 drive (out of 2) and 1 rebuilding.

Rebuilding looks like it's progressing normally:

md0 : active raid1 sdc1[1] sdb1[2]
      1953511288 blocks super 1.2 [2/1] [U_]
      [>....................]  recovery =  0.6% (13261504/1953511288) finish=2299.7min speed=14060K/sec

unused devices: <none>

I'm now waiting on this rebuild, but I'm expecting /dev/sdb1 to become a spare just like the five or six times that I've tried rebuilding before.


UPDATE (31 May 2012): Yeah, it's still a spare. Ugh!


UPDATE (01 June 2012): I'm trying Adrian Kelly's suggested command:

sudo mdadm --assemble --update=resync /dev/md0 /dev/sdb1 /dev/sdc1

Waiting on the rebuild now...


UPDATE (02 June 2012): Nope, still a spare...


UPDATE (04 June 2012): P.B. brought up a concern that I overlooked: perhaps /dev/sdc1 is encountering I/O errors. I hadn't bothered to check /dev/sdc1 because it appeared to be working just fine and it was brand new, but I/O errors towards the end of the drive is a rational possibility.

I bought these HDDs on sale, so it would be no surprise that one of them is already failing. Plus, neither of them have support for S.M.A.R.T., so no wonder they were so cheap...

Here is the data recovery procedure I just made up and am following:

  1. sudo mdadm /dev/md0 --fail /dev/sdb1 so that I can take out /dev/sdb1.
  2. sudo mdadm /dev/md0 --remove /dev/sdb1 to remove /dev/sdb1 from the array.
  3. /dev/sdc1 is mounted at /media/DtkBk
  4. Format /dev/sdb1 as ext4.
  5. Mount /dev/sdb1 to /media/DtkBkTemp.
  6. cd /media to work in that area.
  7. sudo chown deltik DtkBkTemp to give me (username deltik) rights to the partition.
  8. Do copy of all files and directories: sudo rsync -avzHXShP DtkBk/* DtkBkTemp

UPDATE (06 June 2012): I did a badblocks destructive write-mode test of /dev/sdc, following the following procedures:

  1. sudo umount /media/DtkBk to allow tearing down of the array.
  2. sudo mdadm --stop /dev/md0 to stop the array.
  3. sudo badblocks -w -p 1 /dev/sdc -s -v to wipe the suspect hard drive, and in the process, check for I/O errors. If there are I/O errors, that is not a good sign. Hopefully, I can get a refund...

I have now confirmed that there are no input/output issues on either HDD.

From all this investigating, my two original questions still stand.


My questions are:

  1. Why isn't the spare drive becoming active sync?
  2. How can I make the spare drive become active?
share|improve this question

7 Answers 7

up vote 8 down vote accepted

Doing this simply chucks the drive into the array without actually doing anything with it, i.e. it is a member of the array but not active in it. By default, this turns it into a spare:

sudo mdadm /dev/md0 --add /dev/sdb1

If you have a spare, you can grow it by forcing the active drive count for the array to grow. With 3 drives and 2 expected to be active, you would need to increase the active count to 3.

mdadm --grow /dev/md0 --raid-devices=3

The raid array driver will notice that you are "short" a drive, and then look for a spare. Finding the spare, it will integrate it into the array as an active drive. Open a spare terminal and let this rather crude command line run in it, to keep tabs on the re-sync progress. Be sure to type it as one line or use the line break (\) character, and once the rebuild finishes, just type Ctrl-C in the terminal.

while true; do sleep 60; clear; sudo mdadm --detail /dev/md0; echo; cat /proc/mdstat; done

Your array will now have two active drives that are in sync, but because there are not 3 drives, it will not be 100% clean. Remove the failed drive, then resize the array. Note that the --grow flag is a bit of a misnomer - it can mean either grow or shrink:

sudo mdadm /dev/md0 --fail /dev/{failed drive}
sudo mdadm /dev/md0 --remove /dev/{failed drive}
sudo mdadm --grow /dev/md0 --raid-devices=2

With regard to errors, a link problem with the drive (i.e. the PATA/SATA port, cable, or drive connector) is not enough to trigger a failover of a hot spare, as the kernel typically will switch to using the other "good" drive while it resets the link to the "bad" drive. I know this because I run a 3-drive array, 2 hot, 1 spare, and one of the drives just recently decided to barf up a bit in the logs. When I tested all the drives in the array, all 3 passed the "long" version of the SMART test, so it isn't a problem with the platters, mechanical components, or the onboard controller - which leaves a flaky link cable or a bad SATA port. Perhaps this is what you are seeing. Try switching the drive to a different motherboard port, or using a different cable, and see if it improves.


A follow-up: I completed my expansion of the mirror to 3 drives, failed and removed the flaky drive from the md array, hot-swapped the cable for a new one (the motherboard supports this) and re-added the drive. Upon re-add, it immediately started a re-sync of the drive. So far, not a single error has appeared in the log despite the drive being heavily used. So, yes, drive cables can go flaky.

share|improve this answer
    
Flaky link cable? I buy that explanation, but I can't test it out anymore because I re-purposed both drives months ago. I accept this answer as the best answer for my particular problem, but another great answer is this one. –  Deltik Jan 13 '13 at 22:42

I've had exactly the same problem, and in my case I've found out that the active raid disk suffered from read-errors during synchronization. Therefore the new disk was newer successfully synchronized and therefore was kept marked as spare.

You might want to check your /var/log/messages and other system logs for errors. Additionally, it might also be a good idea to check your disk's SMART status:
1) Run the short test:

"smartctl -t short /dev/sda"

2) Display the test results:

"smartctl -l selftest /dev/sda"

In my case this returned something like this:

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
1 Extended offline Completed: read failure 90% 7564 27134728
2 Short offline Completed: read failure 90% 7467 1408449701

I had to boot a live distro and manually copy the data from the defective disk to the new (currently "spare") one.

share|improve this answer
    
Aha! I didn't think to suspect the active drive for I/O errors. For some reason, S.M.A.R.T. is not supported on these HDDs. This and possible I/O errors on two brand new HDDs? I think I made a bad buy... Anyway, I'm taking data recovery procedures right now onto the HDD that I know is good. I'll update soon. –  Deltik Jun 4 '12 at 19:58
    
+50 rep to you P.B.. Nobody was able to answer my questions correctly, but I figured that instead of wasting 50 reputation points to nothing, I'd give them to you as a welcome gift. Welcome to Stack Exchange! –  Deltik Jun 7 '12 at 5:41

I have had a similar issue and fixed it by growing the RAID array amount of disks from 1 to 2.

mdadm --grow --raid-devices=2 /dev/md1
share|improve this answer

I had exactly the same problem and always thought that my second disk, which I wanted to re-add to the array had errors. But it was my original disk had read errors.

You could check it with smartctl -t short /dev/sdX and see the results a few minutes later with smartctl -l selftest /dev/sdX. For me it looked like this:

=== START OF READ SMART DATA SECTION ===
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       20%     25151         734566647

I tried to fix them with this manual . That was fun :-). I know you have checked both disks for errors, but I think your problem is, that the disk which is still in the md array has read errors, so adding a second disk fails.

Update

You should additional run a smartctl -a /dev/sdX If you see Current_Pending_Sector > 0 something is wrong

197 Current_Pending_Sector 0x0012 098 098 000 Old_age Always - 69

For me it was definitely the problem that I removed a disk from raid just for testing and resyncing could not be done because of read failures. The sync aborted half the way. When I checked my disk which was still in the raid array smartctl reported problems.

I could fix them with the manual above and saw the number of pending sectors reduced. But there were to many and it is a long and boring procedure so I used my backup and restored the data on a different server.

As you didn't had the opportunity to use SMART, I guess your self test did not show up those broken sectors.

For me it is a lesson learned: Check your disks before you remove one from your array.

share|improve this answer
    
By the time you answered, the RAID 1 array ceased to exist and both drives were found to have no I/O errors. Can you verify that your answer is applicable? –  Deltik Jun 14 '12 at 17:44
    
Finally accepted. This answer is the most likely to help future visitors. Me, I gave up on RAID in general. It's not like I own a datacenter. –  Deltik Sep 9 '12 at 18:38

You could try

sudo mdadm --assemble --update=resync /dev/md0 /dev/sdb1 /dev/sdc1

to update the drives and resync them.

share|improve this answer
    
Trying this now... I'll report back when the rebuild supposedly completes. –  Deltik Jun 1 '12 at 15:18
    
Didn't work. /dev/sdb1 is still not becoming "active" after it rebuilt as a spare. –  Deltik Jun 3 '12 at 4:04

Not sure if it will work since you already --added the disk but --re-add appears to be the option you need.

Or perhaps you need to --grow the device to 2 active disks, mdadm --grow -n 2? Not tested so be careful.

share|improve this answer
    
sudo mdadm --grow -n 2 was one of the first things I did, hence that's why sudo mdadm --detail /dev/md0 shows two slots. Sorry, it doesn't work. –  Deltik Jun 4 '12 at 19:44

I would recommend removing sdc1, zeroing the super block on sdc1 and then re-adding it.

mdadm /dev/md0 -r /dev/sdc1
mdadm --zero-superblock /dev/sdc1
mdadm /dev/md0 -a /dev/sdc1
share|improve this answer
    
I've shifted my data onto each HDD while I zeroed the superblock on the other HDD. The issue I'm having recurs even with complete recreation of the RAID 1 array. –  Deltik Jun 5 '12 at 19:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.