Using RAID in Linux (III): using two disks to create RAID 1 (image)

Source: Internet
Author: User

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
  1. Operating System: CentOS6.5Final
  2. IP Address: 192.168.0.226
  3. Host Name: rd1.tecmintlocal.com
  4. Disk 1 [20 GB]:/dev/sdb
  5. 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.

  1. # Yum install mdadm [in RedHat system]
  2. # Apt-get install mdadm [IN Debain system]

2. Once installedmdadmPackage, we need to use the following command to check whether the disk is configured.

  1. # 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.

  1. # fdisk /dev/sdb

Follow the instructions below

  • PressnCreate a new partition.
  • Then pressPSelect the primary partition.
  • Next, select Partition Number 1.
  • Press the Enter key twice to allocate the entire capacity to it by default.
  • Then, pressPTo print the created partition.
  • PressLTo list all available types.
  • PresstModify the partition type.
  • TypefdSet it to the RAID type of Linux, and then press Enter to confirm.
  • Then usepView our changes.
  • UsewSave the changes.

Create a disk partition

After creating the "/dev/sdb" partition, create the partition/dev/sdc in the same way.

  1. # 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.

  1. # 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.

  1. # mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
  2. # cat /proc/mdstat

Create a RAID device

6. Run the following command to check the RAID device type and RAID array.

  1. # mdadm -E /dev/sd[b-c]1
  2. # 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

  1. # 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.

  1. # mkdir /mnt/raid1
  2. # mount /dev/md0 /mnt/raid1/
  3. # touch /mnt/raid1/tecmint.txt
  4. # 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:

  1. /dev/md0 /mnt/raid1 ext4 defaults 00

Automatically mount Raid Devices

10. Runmount -avTo check whether entries in fstab are incorrect.

  1. # mount -av

Check for errors in fstab

11. Next, run the following command to save the RAID configuration to the "mdadm. conf" file.

  1. # 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.

  1. # 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.

  1. # ls -l /dev | grep sd
  2. # 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.

  1. # cd /mnt/raid1/
  2. # 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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.