FEEDBACK
X

RAID-5 internals, data storage, performance and recovery

How does it work?

3 hard drives is the minimum requirement to setup a RAID 5 array, and what happens inside the array is that the RAID controller will strip the drives together like in RAID 0, but will also add something called “parity”. Parity is the end result of a comparison between sets of data written to different drives. I’m going to show an e.g which is hopefully going to be understandable.

Advantages:

You have an increased Read speed, and also Redundancy

Disadvantages:

Capacity yield.

Example here is you have 3 hard drives and all of them are 1TB each. With RAID 0 you would have a 3TB virtual hard drive. With RAID 5 you’ll lose the capacity of 1 drive. So in this case RAID controller presents them to the operating system as 2TB hard drive.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

         
         
     

RAID

 
         
         

When we take a close look at what happens when the operating system is trying to write some bits of to the disk drives. The RAID controller will take the first half of the 8bits and write it to the hard drive #1.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

     

10101010

         
     

RAID

 
         
         

It will take the second half of the 8bits and write it to hard drive #2. Keep in mind, this is simplified because it writes in much bigger junks of data but this is just simplified on how it works. As we see now there’s no difference from what it happened in RAID 0. We took half each from the data and wrote it to two hard drives and why still do we need the third hard drive. It’s because of the parity.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010 

   

10101010

         
     

RAID

 
         
         

When the RAID controller creates the parity bits it uses a table called Exclusive OR which will compare bits and will output a parity bit as a result of the bits it compares. We are going to see how it works.

   

XOR

   

0

 +

0

0

0

 +

1

1

1

 + 

0

=

1

1

 +

1

  =

0

In this case you see that hard drive #1 has half of the data we got from the operating system, and the first bit is the 1. And hard drive # 2 has the second half of the data and first bit is 1. According to the table marked in yellow here 1+1=0. So on hard drive #3 the first parity bit will be a 0.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

0 

 

10101010

     

XOR

   
           

0

0

 =

0

     

RAID

   

0

1

 =

1

           

1

0

  = 

1

           

1

1

 =

0

When it goes to the second bit we see that 0 is the second bit in hard drive#1 and 0 is the second bit in hard drive #2. So according to the table the second parity bit is done 0.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

00 

 

10101010

     

XOR

   
           

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

When we go to third bit, 1 is in hard drive #1 and 1 is in hard drive#2. And according to the table 0 is the parity bit of 1+1. So that’s what is written to hard drive #3.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

000 

 

10101010

     

XOR

   
           

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

And we have fourth bit 0 and 0, and according to the table it’s 0.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

0000 

 

10101010

     

XOR

   
           

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

So now the RAID controller has calculated the parity bits and written them to hard drive #3.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000 

 

10101010

         
     

RAID

 
         
         

This of course takes a little bit of time. So you’ll now have the Write performance as in RAID 0. We have second set of data here. Let’s go through that.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000 

 

10101010

       

01101111

     

RAID

 
         
         

First half gets written to disk #1 and second half get written to disk #3.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000 

 

10101010

0110

     

01101111

     

RAID

 
         
   

 

   

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000 

 

10101010

0110

 

1111

 

01101111

     

RAID

 
         
         

And why is it written to disk #3? That is because RAID 5 will spread the parity bits evenly between the drives, and why thus that is because when you have a hard drive failure that will increase your performance. We’ll take a look at that a little bit later.

Once again the RAID controller will calculate the parity bits. First half of the data is on hard drive #1 and second half on hard drive #3 regard from the operating system. 0 and 1 is the first bit on hard drives #1 and #3 by order. According to the table 0+1 equals a parity bit of 1.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

0000 

 

10101010

     

XOR

   

0110

1

1111

 

01101111

 

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

Second bit 1 on each drive which will create a parity bit of 0.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

0000 

 

10101010

     

XOR

   

0110

10

1111

 

01101111

 

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

Third parity bit is 0 calculated from 1 on each side.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

 0000

 

10101010

     

XOR

   

0110

100

1111

 

01101111

 

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

And the last bit of the data 0 on hard drive #1 and 1 on hard drive #3, and according to the table 0+1 =1.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

           

1010

1010

0000 

 

10101010

     

XOR

   

0110

1001

1111

 

01101111

 

0

 

0

 

0

     

RAID

   

0

 

1

 

1

           

1

 

0

 

1

           

1

 

1

 

0

Now we generated the parity bits for the second set of data.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000 

 

10101010

0110

1001

1111

 

01101111

     

RAID

 
         
         

This will just keep going and the RAID controller will do this all the time. It will move the data from the operating system memory to the disk drives and it will calculate the parity bits and distribute it evenly between the drives.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000

 

10101010

0110

1001

1111

 

01101111

0000

1100

1100

RAID

11001100

0011

1010

1001

 

00111010

0000

1111

1111

 

00001111

What happens if a drive fails?

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

0000

 

10101010

0110

1001

1111

 

01101111

0000

1100

1100

RAID

11001100

0011

1010

1001

 

00111010

0000

1111

1111

 

00001111

All the data on the drive that fails will be lost. Would that mean, operating system will see that the data is lost when the drive is found?

                                                                                                                                                ?

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

X

0110

1001

X

 

X

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

No it won’t.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

X

0110

1001

X

 

X

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

As we’ll see here, the operating system tries to access the first pieces of data here the RAID controller will take the first half and give it to the operating system and take the second half and give it to the operating system. So the data is intact.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

1010

0110

1001

X

 

X

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

10101010

0110

1001

X

 

X

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

On the second line here the first half of the data is intact but the second half is gone because hard drive #3 died. But we still have the parity bits.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

10101010

0110

1001

X

 

X

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

We see here the operating system gets the first 4 bits since they are intact, and the RAID controller will pull up its Exclusive OR table and it’ll compare the bits of the original data and the parity bits.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X

 

10101010

0110

1001

X

 

0110

0000

1100

X

RAID

X

0011

1010

X

 

X

0000

1111

X

 

X

As you see here the first bit on hard drive #1 is a 0, and the first parity bit on hard drive #2 is a one. And in the table you can see that it leaves us only with one option that the original data on hard drive #3 must have been 1.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

           

1010

1010

 X 

 

10101010

     

XOR

   

0110

1001

X

 

01101

 

0

 

0

 

0

0000

1100

X

RAID

X

 

0

 

1

 

1

0011

1010

X

 

X

 

1

 

0

 

1

0000

1111

X

 

X

 

1

 

1

 

0

Second bit 1 on hard drive #1 and the parity bit is zero which leaves us with only one option; the original data on hard drive #3 must have been 1.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

           

1010

1010

 X 

 

10101010

     

XOR

   

0110

1001

X

 

011011

 

0

 

0

 

0

0000

1100

X

RAID

X

 

0

 

1

 

1

0011

1010

X

 

X

 

1

 

0

 

1

0000

1111

X

 

X

 

1

 

1

 

0

And third bit 1, parity bit 0 which leaves us with one option, the original data must have been 1.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

           

1010

1010

 X 

 

10101010

     

XOR

   

0110

1001

X

 

0110111

 

0

 

0

 

0

0000

1100

X

RAID

X

 

0

 

1

 

1

0011

1010

X

 

X

 

1

 

0

 

1

0000

1111

X

 

X

 

1

 

1

 

0

And the forth bit 0 and the parity bit is 1 which leaves us with one option and that would mean that the original data on hard drive #3 was a 1.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

           

1010

1010

 X 

 

10101010

     

XOR

   

0110

1001

X

 

01101111

 

0

 

0

 

0

0000

1100

X

RAID

X

 

0

 

1

 

1

0011

1010

X

 

X

 

1

 

0

 

1

0000

1111

X

 

X

 

1

 

1

 

0

And when you read each set of data the RAID controller will calculate what the data in the original data on the defective drive was, and so you’ll be able to access & read all the files even if the drive fails.

HDD #1 (1TB)

HDD #2 (1TB)

X

 

Virtual HDD (2TB)

1010

1010

X 

 

10101010

0110

1001

X 

 

01101111

0000

1100

X 

RAID

11001100

0011

1010

X 

 

00111010

0000

1111

X 

 

00001111

And when you replace the drive the RAID controller will either automatically depending on its price, or you can start it manually if you have a cracked one, it’ll rebuild the third drive.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

X 

 

10101010

0110

1001

X 

 

01101111

0000

1100

X 

RAID

11001100

0011

1010

X 

 

00111010

0000

1111

X 

 

00001111

It’ll take the data from the hard drives that are still alive and write it to the new hard drive as you can see here. It won’t write data it will create parity bits in this first case here and when it compares with the table here you see that 1+1 first bit on hard drive #1 and the second bit on hard drive #2, 1 and 1 according to table will be a 0. And 0 and 0 will give zero, and 1 and 1 will give 0, and 0 and 0 will give a 0. It will rebuild the original data based on the first half and the parity bits, and as you can see it will rebuild entire content of hard drive #3 as if it was never gone. So we have rebuilt our RAID array.

HDD #1 (1TB)

HDD #2 (1TB)

HDD #3 (1TB)

 

Virtual HDD (2TB)

1010

1010

0000

 

10101010

0110

1001

1111

 

01101111

0000

1100

1100

RAID

11001100

0011

1010

1001

 

00111010

0000

1111

1111

 

00001111

Summary

RAID 5 needs minimum of 3 hard drives to implement. Set of N number of identical drives provides a capacity of N minus 1 Drives. RAID 5 basically spreads the data across multiple disks by using parity bits which can be used to regenerate data if one of the drives fail and thereby provides redundancy. Parity is the end result of a comparison between sets of data written to different drives. Parity blocks are determined by using a logical comparison called XOR (Exclusive OR) which basically will take two binary bits, compare them, and output a result of 0 or 1.

When one drive fail data can be rebuilt on a replaced new drive by finding the lost data block through XOR comparison on the remaining data blocks on other drives. The read performance of RAID 5 is almost as good as RAID 0 for the same number of disks. Except for the parity blocks, the distribution of data over the drives follows the same pattern as RAID 0. The reason RAID 5 is marginally slower is that the disks must skip over the parity blocks which is not the case as in RAID 0.

Conclusion

Increased read speed and redundancy is the advantage of RAID 5 storage array. Data can be rebuilt if any one of the total drives fails. But more than 1 drive failure will lead to data calamity since XOR checksum won’t work in such scenario!