Introduction: How to Make Raid-1 Storage
What is RAID1 in simple terms its
:Disk mirroring. Best optimized for Redundancy and requires a Minimum number of 2 drives
What is RAID1 in complex terms its
:It consists of an exact copy (or mirror)
of a set of data on two or more disks; a classic RAID 1 mirrored pair contains two disks. This configuration offers no parity, striping, or spanning of disk space across multiple disks, since the data is mirrored on all disks belonging to the array, and the array can only be as big as the smallest member disk. This layout is useful when read performance or reliability is more important than write performance or the resulting data storage capacity.
(Wikipedia explains this very well)
What is good at and what its terrible at.
Very high performance; Very high data protection; Very minimal penalty on write performance.
Weaknesses: High redundancy cost overhead; Because all data is duplicated, twice the storage capacity is required.
What you will need
Minimum at least 2 USB sticks or hard drives you can add more by using 4,6 and 8
All code is in Italic
Step 1: Installing Mdadm
First thing: You need to get the RAID software. You’ll need to download and install mdadm from your software repository. It’s pretty common, so open the terminal up and type the following command:
sudo apt-get install mdadm
Step 2: Examine Our Disk Drives
we need to examine our disk drives whether there is already any raid configured.
Using the following command:
mdadm -E /dev/sd[b-c]
Step 3: Drive Partitioning for RAID
we’re using minimum two partitions /dev/sdc1 and /dev/sdb1 for creating RAID1. Let’s create partitions on these two drives using ‘fdisk‘ command and change the type to raid during partition creation.
Use this command
fdisk /dev/sdc1
then follow these instructions
- Press ‘n‘ for creating new partition.
- Then choose ‘P‘ for Primary partition.Next select the partition number as 1.
- Give the default full size by just pressing two times Enter key.
- Next press ‘p‘ to print the defined partition.
- Press ‘L‘ to list all available types.
- Type ‘t‘to choose the partitions.
- Choose ‘fd‘ for Linux raid auto and press Enter to apply.
- Then again use ‘p‘ to print the changes what we have made.
- Use ‘w‘ to write the changes.
Now we are going to the exactly the same for sdb1
fdisk /dev/sdb1
So follow the same exact steps as sdc1
Step 4: Verify Changes
Once both the partitions are created successfully, verify the changes on both sdb & sdc usb drives using the same ‘mdadm‘ command and also it will confirm the RAID type
Using the command :
mdadm -E /dev/sd[b-c]
we can use the same command but add a one on the end
mdadm -E /dev/sd[b-c]1
Step 5: Creating RAID1 Devices
Next create RAID1 Device called ‘/dev/md0' or you could use '/dev/md127' using the following command and verity it.
mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
cat /proc/mdstat
or
mdadm --create /dev/md127 --level=mirror --raid-devices=2 /dev/sd[b-c]1
cat /proc/mdstat
--------------------------------------------------------------------------------------------------
Next check the raid devices type and raid array using following commands.
mdadm -E /dev/sd[b-c]1
-----------------------------------
mdadm --detail /dev/md0 OR mdadm --detail /dev/md127
From the above pictures, you should get the more or less understand that raid1 have been created and using /dev/sdb1 and /dev/sdc1 partitions and also you can see the status as re-syncing. Via the
mdadm --detail /dev/md0 or mdadm --detail /dev/md127 command
Step 6: Creating a File System on the RAID Device
Create file system using ext4 for md0 or md127 and mount under /mnt/raid1. This step is important.
Use the command
mkfs.ext4 /dev/md0 or mkfs.ext4 /dev/md127
-------------------------------------------------------------------------------------------------------
Next, mount the newly created filesystem under ‘/mnt/raid1‘ and create some files and verify the contents under mount point.
Use these commands
mkdir /mnt/raid1
mount /dev/md0 /mnt/raid1/
touch /mnt/raid1/tecmint.txt
echo "tecmint raid setups" > /mnt/raid1/tecmint.txt
cat /mnt/raid1/tecmint.txt
cat proc/mdstat
So in order to auto-mount RAID1 on system reboot, you need to make an entry in fstab file. Open ‘/etc/fstab‘ file and add the following
/dev/md0 /mnt/raid1 ext4 defaults 0 0
make sure to run
Run ‘mount -av‘ to see if there are any errors in the fstab file though if step are followed no erros will apear.
--------------------------------------
Now lets, save the raid configuration manually to ‘mdadm.conf‘ file using the below command.
mdadm --detail --scan --verbose >> /etc/mdadm.conf
Step 7: Verify Data After Disk Failure
The purpose of RAID is if any of the hard disks fail or crash our data will
need to be available. Let’s see what will happen when any of disk disk is unavailable in array.
----------------------------------------------------------------------
we can see there are 2 devices available in our RAID and Active Devices are 2. So now remove one of your hard drives
ls -l /dev | grep sd
mdadm --detail /dev/md0
We can see that one of our drivers is lost so now lets check on our data.
Use thease commands
cd /mnt/raid1/
cat tecmint.txt
.........................................
Are Data should still be there and available to us even if we have taken one of the drivers out this is the advantage of RAID 1 (mirror)
Step 8: Command Index
fdisk: is a command-line utility that provides disk partitioning functions.
cat: is a standard Unix utility that reads files sequentially, writing them to standard output.
mount: command mounts a storage device or filesystem, making it accessible and attaching it to an existing directory structure.
mkdir: is used to make a new directory.
touch: is a command used to update the access date and/or modification date of a computer file or directory.
echo is a command that outputs the strings it is being passed as arguments. It is a command typically used in shell scripts and batch files to output status text to the screen or a computer file, or as a source part of a pipeline.
Step 9: No More Steps
If you made it this far congratulations because this took me a whole afternoon to complete i had to do this twice has all of my screenshots where corrupt, Hope i could help with the struggles of RAID1