In my previous article, I explained how to add an USB HDD (in my case, it is 314GB WD PiDrive) to Raspberry Pi. Today, I am going to go over the steps to create a software RAID to make the file system more reliable. Ideally, there should be at least two HDD in the system to prevent data loss in the event of drive failure. However, I only have one HDD in my Raspberry Pi, so, I created two partitions /dev/sda2 and /dev/sda3 to mirror each other using RAID1.
Installing RAID software
The software that I am going to use is ‘mdadm’. It is widely used in Linux for software RAID. To install it, run the following command.
sudo apt-get install mdadm
Create RAID1 Drive
There are many different RAID levels. In my case, I am using RAID1 to mirror two partitions on the same drive. By running the following command, it creates a RAID1 drive /dev/md0.
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sda2 /dev/sda3
Once the RAID drive is created, mdadm automatically synchronize the two partitions in a background process. To check the status, view the file /proc/mdstat
It shows that the sync process is 5% done and will finish in 162.6 minutes.
Format and mount the RAID disk
The raid disk needs to be formated before mounting. Run the following commands to format and create a directory /home/disks/raid for mounting:
sudo mkfs.ext4 /dev/md0 cd /home/disks mkdir raid chmod 777 raid
Add the following line to /etc/fstab to mount the disk
/dev/md0 /home/disks/raid ext4 defaults 1 2
mount the disk
sudo mount -a
Below is a screenshot showing the file system statistics after the RAID disk is mounted
The RAID disk will be the place for me to store critical data and programs. In the future, I will install GIT server to store the code the I develop. I will post an article on how to do so.