Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

So, I'd like to know, is is possible to do the following with mdadm:

  1. I start with RAID0 configuration on 2 disks: sda and sdb.
  2. I would like to add one more disk to array, sdc and move all data from sdb to it.
  3. Disconnect sdb.

Right now I see only one option - I stop the array, copy sdb to sdc with dd or any other block-copy tool and start the array back.

Do I miss something? Is it possible to do this with mdadm?

share|improve this question
    
You can make sdb to a temporary mirror, and then sync sdc to it in the background - this reduced the needed downtime, although I didn't do this as a beginner in your place. –  Peter Horvath Jul 9 at 17:32
    
I'm not a beginner for sure :) Can you tell me more about temporary mirror? Is it mdadm feature? –  maniaque Jul 9 at 17:34
    
No, it is a simple raid feature. I thought a temporary raid1 array, which could be get the place of sdb in your raid1 array. While you are syncing sdb to sdc, you could also use it as a part of your raid0 array. –  Peter Horvath Jul 9 at 17:35
    
So, do I understand you right? 1. Stop array. 2. Create one more RAID1 array with sbd and sdc. 3. And how could I ask mdadm so start my RAID0 with md1 instead of sdb? –  maniaque Jul 9 at 17:38
    
Haven't researched much, but it certainly seems like you should be able to grow from a RAID0 -> RAID5. Then shrink back down to a RAID0. –  Zoredache Jul 9 at 18:40

3 Answers 3

up vote 5 down vote accepted

First of all: to those, who still believes in "RAID0 has no hot spare". It could have a manual spare, done by human, who understand RAID levels and mdadm. mdadm is software RAID, so it could do a lot of interesting things.

Credits to Zoredache for the idea!

So, the situation:

  • you have RAID0 array of two disks
  • you would like to replace one of them without array downtime

If the downtime is acceptable, you always can just make a block copy of disk with dd and reassemble the array, mdadm will do OK.

Solution: use RAID4 as intermediate solution

RAID0 -> RAID4 -> RAID0

So, if you don't remember RAID4, it is simple. It has a parity block, but unlike RAID5 it is not distributed across the array, but resides on ONE disk. That's the point, this is important and this is the reason RAID5 will not work.

What you'll need: two more disks of the same size, as the disk you would like to replace.

Environment:

  • Ubuntu 14.04 Thrusty Thar
  • mdadm - v3.2.5 - 18th May 2012
  • /dev/sdb - start with it, will replace it
  • /dev/sdc - start with it
  • /dev/sdd - will be used temporary
  • /dev/sde - will be used instead of sdb

The ultimate RAID0 hot-spare mdadm guide ;)

sudo mdadm -C /dev/md0 -l 0 -n 2 /dev/sd[bc]

md0 : active raid0 sdc[1] sdb[0]
      2096128 blocks super 1.2 512k chunks

We've created raid0 array, it looks sweet.

sudo md5sum /dev/md0

b422ba644a3c83cdf28adfa94cb658f3  /dev/md0

This is our check point - if even one bit will differ in resulting /dev/md0 - we've failed.

sudo mdadm /dev/md0 --grow --level=4

md0 : active raid4 sdc[1] sdb[0]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [UU_]

So, we've grown our array to be RAID4. We haven't added the parity disk yet, so let's do it. The grow will be instant - there is nothing to recompute or recalculate.

sudo mdadm /dev/md0 -a /dev/sdd

md0 : active raid4 sdd[3] sdc[1] sdb[0]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [UU_]
      [===>.................]  recovery = 19.7% (207784/1048064) finish=0.2min speed=51946K/sec

We've added sdd as parity disk. This is important to remember - the order of disks in the first row is not syncronized with the picture in second row! [UU_]

sdd is displayed first, but in fact it is last one, and holds not the data, but the parity.

sudo mdadm /dev/md0 -f /dev/sdb

md0 : active raid4 sdd[3] sdc[1] sdb[0](F)
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [_UU]

We've made our disk sdb faulty, to remove it in the next steps.

sudo mdadm --detail /dev/md0

State : clean, degraded

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       32        1      active sync   /dev/sdc
       3       8       48        2      active sync   /dev/sdd

       0       8       16        -      faulty spare   /dev/sdb

Details show us the removal of the first disk and here we can see the true order of the disks in the array. It's important to track the disk with parity, we should not leave it in the array when going back to RAID0.

sudo mdadm /dev/md0 -r /dev/sdb

md0 : active raid4 sdd[3] sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [_UU]

sdb is completely removed, could be taken away.

sudo mdadm /dev/md0 -a /dev/sde

md0 : active raid4 sde[4] sdd[3] sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [_UU]
      [==>..................]  recovery = 14.8% (156648/1048064) finish=0.2min speed=52216K/sec

We have added the replacement for our sdb disk. And here we go: now the data of sdb is being recovered using parity. Sweeeeet.

md0 : active raid4 sde[4] sdd[3] sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/3] [UUU]

Done. Right now we are completely safe - all data from sdb are recovered, and now we have to remove sdd (remember, it holds parity).

sudo mdadm /dev/md0 -f /dev/sdd

md0 : active raid4 sde[4] sdd[3](F) sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [UU_]

Made sdd faulty.

sudo mdadm /dev/md0 -r /dev/sdd

md0 : active raid4 sde[4] sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [UU_]

Removed sdd from our array. We are ready to become RAID0 again.

sudo mdadm /dev/md0 --grow --level=0 --backup-file=backup

md0 : active raid4 sde[4] sdc[1]
      2096128 blocks super 1.2 level 4, 512k chunk, algorithm 5 [3/2] [UU_]
      [=>...................]  reshape =  7.0% (73728/1048064) finish=1.5min speed=10532K/sec

Aaaaaaand bang!

md0 : active raid0 sde[4] sdc[1]
      2096128 blocks super 1.2 512k chunks

Done. Let's look at md5 checksum.

sudo md5sum /dev/md0

b422ba644a3c83cdf28adfa94cb658f3  /dev/md0

Any more questions? So RAID0 could have a hot spare. It's called "user" ;)

share|improve this answer

As far as I know once you set up a RAID0 you cannot change one of the disks. You can take a backup and switch the disks and restore the backup. I would just RAID5 those 3 disks you have. That way in the future you can drop a disk and still rebuild it.

share|improve this answer
    
Well, I know how to do the thing I talk about with RAID5 - I can add new disk to array (as spare), then mark the disk I like to move out as faulty and remove it from the array, wiping the superblock afterwards. But I'm interested in same operation with RAID0 :) –  maniaque Jul 9 at 17:31
    
@maniaque It's called RAID 0 because zero is how much RAID you get. Absolutely nothing of importance should ever be placed on a RAID 0. –  Michael Hampton Jul 10 at 13:37
    
@MichaelHampton I think you mean redundancy not RAID but your statement is 100% correct. –  joeg1ff Jul 10 at 14:02
    
@MichaelHampton Please see my answer below :) –  maniaque Jul 10 at 18:19

RAID 0 does not provide redundancy.

So it does not support hot drive replacement.

share|improve this answer
    
Just look below, please. There is nothing impossible, when you understand RAID levels ;) –  maniaque Jul 10 at 17:24

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.