Using RAID in Linux (III): using two disks to create RAID 1 (image)
A raid image is a complete clone (or image) of the same data, which is written to two disks respectively. Creating a RAID 1 requires at least two disks and is only used when reading performance or reliability is more important than data storage capacity.
Set RAID 1 in Linux
The image is created to prevent data loss caused by hard disk failure. Each disk in the image contains a complete copy of the data. When a disk fails, the same data can be read from other normal disks. Then, you can replace the faulty disk from a running computer without any interruption.
Features of RAID 1
The image has good performance.
Disk utilization is 50%. That is to say, if we have two disks, each of which is 500 GB, the total size is 1 TB, but only 500 GB is displayed in the image.
If an image disk fails, no data is lost because the content of the two disks is the same.
The read performance is better than the write performance.
Requirements
Creating RAID 1 requires at least two disks. You can also add more disks. The number of disks must be an even number, such as, or 8. To add more disks, your system must have a RAID physical adapter (hardware card ).
Here, we use software RAID instead of hardware RAID. If your system has a built-in physical hardware RAID card, you can access it from its functional interface or press Ctrl + I.
Read: Introduction to RAID levels and concepts
Install On my server
Operating System: CentOS6.5Final
IP Address: 192.168.0.226
Host Name: rd1.tecmintlocal.com
Disk 1 [20 GB]:/dev/sdb
Disk 2 [20 GB]:/dev/sdc
This article will guide you to build a software RAID 1 (image) Step by Step Using mdadm (used to create and manage RAID) on the Linux platform ). The same practice applies to Linux distributions such as RedHat, CentOS, and Fedora.
Step 2: install the required software and check the disk
1. in Linux, we need to use mdadm to create and manage RAID. Therefore, let's use the yum or apt-get software package management tool to install the mdadm package on Linux.
# Yum install mdadm [in RedHat system]
# Apt-get install mdadm [IN Debain system]
2. Once installedmdadmPackage, we need to use the following command to check whether the disk is configured.
# mdadm -E /dev/sd[b-c]
Check the RAID Disk
As you can see from the above picture, no super block is detected, which means no RAID has been created.
Step 1: Create a partition for RAID
3. As I mentioned, we use the least two shards/dev/sdb and/dev/sdc to create RAID 1. We usefdiskCommand to create the two partitions and change their type to raid.
# fdisk /dev/sdb
Follow the instructions below
- Press
nCreate a new partition.
- Then press
PSelect the primary partition.
- Next, select Partition Number 1.
- Press the Enter key twice to allocate the entire capacity to it by default.
- Then, press
PTo print the created partition.
- Press
LTo list all available types.
- Press
tModify the partition type.
- Type
fdSet it to the RAID type of Linux, and then press Enter to confirm.
- Then use
pView our changes.
- Use
wSave the changes.
Create a disk partition
After creating the "/dev/sdb" partition, create the partition/dev/sdc in the same way.
# fdisk /dev/sdc
Create the second partition
4. Once the two partitions are successfully created, use the same command to check the sdb and sdc partitions and confirm the RAID partition type, as shown in.
# mdadm -E /dev/sd[b-c]
Verify partition changes
Check RAID type
Note: As you can see, sdb1 and sdc1 do not have any definition of RAID, Which is why Super blocks are not detected.
Step 2: Create a RAID 1 Device
5. Run the following command to create a RAID 1 device named/dev/md0 and verify it.
# mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
# cat /proc/mdstat
Create a RAID device
6. Run the following command to check the RAID device type and RAID array.
# mdadm -E /dev/sd[b-c]1
# mdadm --detail /dev/md0
Check the RAID device type
Check the RAID device array
It is easy to understand that RAID 1 has been created and the/dev/sdb1 and/dev/sdc1 partitions are used. You can also see that the status is resyncing ).
Step 2: create a file system on a RAID Device
7. Create an ext4 File System for md0
# mkfs.ext4 /dev/md0
Create a file system for a RAID Device
8. Next, mount the newly created File System to "/mnt/raid1" and create some files to verify the data at the Mount point.
# mkdir /mnt/raid1
# mount /dev/md0 /mnt/raid1/
# touch /mnt/raid1/tecmint.txt
# echo "tecmint raid setups" > /mnt/raid1/tecmint.txt
Attach a RAID device
9. To automatically mount RAID 1 after the system restarts, you must add entries to the fstab file. Open/etc/fstabFile and add the following lines:
/dev/md0 /mnt/raid1 ext4 defaults 00
Automatically mount Raid Devices
10. Runmount -avTo check whether entries in fstab are incorrect.
# mount -av
Check for errors in fstab
11. Next, run the following command to save the RAID configuration to the "mdadm. conf" file.
# mdadm --detail --scan --verbose >> /etc/mdadm.conf
Save Raid configurations
The preceding configuration file reads and loads the RAID device when the system restarts.
Step 2: check data after disk failure
12. Our primary goal is to ensure that data is available even when any disk fails or crashes. Let's take a look at what will happen when any disk is unavailable.
# mdadm --detail /dev/md0
Verify the RAID device
In the above figure, we can see that two Devices in RAID are available and Active Devices is 2. Now let's take a look at what will happen when a disk is pulled out (removed from the sdc disk) or damaged.
# ls -l /dev | grep sd
# mdadm --detail /dev/md0
Test a RAID device
Now, you can see in the picture above that a disk is missing. I deleted a disk from the VM. Now let's check our valuable data.
# cd /mnt/raid1/
# cat tecmint.txt
Verify RAID data
You can see that our data is still available. Therefore, we can understand the advantages of RAID 1 (image. In the following article, we will see how to set up a RAID 5 strip distributed parity. I hope this will help you understand how RAID 1 (image) works.
How to build a RAID 10 array on Linux
Debian soft RAID Installation notes-use mdadm to install RAID1
Common RAID technology introduction and demo (Multi-chart)
The most common disk array in Linux-RAID 5
RAID0 + 1 and RAID5 Performance Test Results
Getting started with Linux: disk array (RAID)
Via: http://www.tecmint.com/create-raid1-in-linux/
Author: Babin Lonston Translator: strugglingyouth Proofreader: wxy
This article was originally translated by LCTT and launched with the Linux honor in China
This article permanently updates the link address: