Replacing a disk in a Software Raid Array…

logo-linux01A disk recently died on my software raid array, and replacing the disk was a simple procedure. You will get some notification via your systems email regarding that a disk has failed. Usually you can periodically check the mdstat file and see if any disks have failed. You can check the mdstat file below.

The output should be similar to below.

You can see from up above that one of the disks has died. Going by the sequence of disks in the /proc/mdstat file. I can make out that /dev/sdg1 has failed ( I have gone a bit ahead on the sequence). I now need to remove /dev/sdg1 from the array. You do not need to stop the array to remove the disk. The command below to remove the disk is

Unless you have hot swappable disks, you need to shut down the system to swap the old disk out and replace it with a new disk. Once the system is rebooted. You can type the command to add the new disk the existing array.

This will take some while for the disk to resync with the existing array. To monitor the progress of the array, you just type in the following command.

You can ctrl-c to get out of this anytime. It wil update every ten seconds.

Creating a Software Raid Array in 600 seconds…

Recently I decided that I was going to build a array, after my disk failure on my previous server. This would allow my data to be redundant, even with a disk failure. I debated between hardware and software raid. Hardware raid would be faster, limited to one hardware controller. While with software raid or sometimes called fake raid. I can have the disks across multiple controllers. This again slows the performance of the software raid, but it is the tradeoff, I am willing to accept. I decided on software raid because, if a disk dies, and I cannot get a the same size. I can use a larger disk, and downsize the disk to the size of the other disks in the array.  Also with technology, larger disks do come down in price.


1. We need to first install the the raid software.

# apt-get install mdadm

2. Create the partitions on the hard disks.

# fdisk /dev/sda

Command (m for help): p

Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa3e937ed
Device Boot Start End Blocks Id System
/dev/sda1 1 60801 488384001 fd Linux raid autodetect

Next we need to change the partition type to “Linux raid auto”.

Command (m for help): t
Selected partition 1
fd  Linux raid auto
Hex code (type L to list codes): fd

3. Create the software raid array.

# mdadm –create /dev/md0 –chunk=4 –level=5 –raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1

–create creates the software array.
/dev/md0 is the name of the array, the array needs to be md[number]
–chunk the block size of the software array.
–raid-devices how many disks in the array.
/dev/sda1 is the disks that will be included in the array

4. Assemble the software raid array.

# mdadm –assemble /dev/md0 /dev/sda1 /dev/sdb1 /dev/sdc1

–assemble bundle the disks together.
/dev/md0 the name of the array.
/dev/sda1 the disks in the array.

5. To see the software raid sync you can use the following command.

# watch -n 10 cat /proc/mdstat

When the array is sync’ed it will have 100%. Time it takes depends on the size of the software array.

6. Create the file System upon the software array. You can partition the software array with fdisk.

# mkfs.ext3 /dev/md0

7. Now you can use the software disk array.