RAID 1 (GNU/Linux)

Rate this post

 

RAID (Redudant array of independent disks) is used to make the loss of data happen less often when one or more disks of the array fail, which is done by having several copies of data ;  to get more storage space by having many smaller disks ; to get more flexibility (disks can be changed or added while the system keeps running); and to get the data more quickly.

If you would like to secure your data and keep it safe from failures, you can configure RAID 1, which is also referred to as Mirroring. The only requirement is to have two identical hard drives that will be put together; both will contain the same data, one is “mirroring” the other. This is easy, you only need to follow the steps down below:

1- Preparation of disks:

The easiest method, is to replicate partitions on two disks:

# fdisk -l /dev/sda
Disk /dev/sda (Sun disk label): 64 heads, 32 sectors, 17272 cylinders Units = cylinders of 2048 * 512 bytes
Device Flag Start End Blocks Id System
/dev/sda1 0 122 124928 fd Linux raid autodetect
/dev/sda2 122 1099 1000448 fd Linux raid autodetect
/dev/sda3 1099 8912 8000512 fd Linux raid autodetect
/dev/sda4 8912 17272 8560640 fd Linux raid autodetect
# fdisk -l /dev/sdb
Device Flag Start End Blocks Id System
/dev/sdb1 0 122 124928 fd Linux raid autodetect
/dev/sdb2 122 1099 1000448 fd Linux raid autodetect
/dev/sdb3 1099 8912 8000512 fd Linux raid autodetect
/dev/sdb4 8912 17272 8560640 fd Linux raid autodetect

The type of the partitions that we want to make redundant has to be the type “fd”.

To change a partition type you can use “fdisk”, as follows:

#fdisk /dev/sda
Command (m for help): t
Partition number (1-8): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): w

2- Creation of disk arrays:

Now that our disks are ready, we will have to create our RAID 1 volumes using “mdadm”:

#mdadm –create /dev/md0 –level=1 –raid-devices=2 /dev/sda1 /dev/sdb

From here, the RAID should be built on its own, but you can always check its progress, using :

#mdadm –detail /dev/md0

Or using :

#watch cat /proc/mdstat

After doing this, we should save our configuration using this command:

#mdadm –detail –scan >> /etc/mdadm.conf

3- Using RAID 1:

After finishing all the previous steps, we can now format our new volume:

#mkfs.ext4 /dev/md0

Then add these entrees in the fstab:

#echo “/dev/md0 /data ext4 noatime 0 1” >> /etc/fstab

And then we display our position:

#mkdir /data; mount /data

And it’s done, we now have deployed RAID 1 on a GNU/Linux distribution.