Use software to implement RAID in Linux

Source: Internet
Author: User


Data security is one of the most important issues in the use of computers. Generally, Hard Disk Mirroring technology is used in the server environment to achieve dual data backup. We can also use this technology in Linux.

In Linux, Raidtools can be used to mirror not only two hard disks, but also soft RAID 0, RAID 1, and RAID 5. It is soft RAID because RAID disks are usually carried out through dedicated RAID cards. in Linux, RAID functions can be implemented using RAID tools, which is called Soft RAID. This article describes how to create and use RAID Disks Based on Different Linux versions.

I. Earlier Linux versions

Download and compile the Raidtools package by yourself. The earlier version of Raidtools package is named md and has now been officially renamed Raidtools. : China free software library.

If you have downloaded the raidtools-0.41.tar.gz package from the Internet, decompress the package and compile it by yourself. The steps are as follows:

$ Gunzip-d raidtools-0.41.tar.gz

$ Tar-xvf raidtools-0.4.1.tar

Before using Raidtools, you must first know whether the core currently in use supports md. If you are using 2.0.X and are not compiled by yourself, soft RAID is supported in most cases. If not, compile the core. Select md support during configuration. After determining the core supporting RAID in use, compile the Raidtools package as follows:

$ Raidtools-0.41 cd

$./Configure

$ Make

$ Make install # make install generate a total of 4 devices under the/dev md0-md3.

Click OK to complete the installation.

Determine the type of RAID to use before using Raidtools. Currently, Raidtools can be used as RAID0, RAID1, and raid5. RAID5 cannot be used because there are only two hard disks. In addition to RAID5, you can also choose Linear mode or RAID0. I chose RAID0. The following is the production process.

1. Create a RAID Disk

(1) shutdown, add the two hard disks to the Slave interface of the first IDE controller and the Slave interface of the second IDE controller respectively (the CD-ROM on this machine is connected to the Master of the second IDE Controller ).

(2) power up the system and Log On As Root. Run the following command to partition the hard disk:

# Fdisk/dev/hdb

Divide all hard disks into one primary partition and create one/dev/hdb1 partition.

# Fdisk/dev/hdd

Similarly, divide all hard disks into one primary partition and create one/dev/hdd1 partition.

(3:

#/Sbin/mdcreate raid0-c4k/dev/md0/dev/hdb1/dev/hdd1

Of course, in order to improve the access speed, you can divide the hard disk in a more detailed manner and try to reasonably distribute the partitions on different hard disks. Then, use Mdcreate to combine them into an mdx (x: 1, 2, 3 ).

2. Use RAID0 Disk

(1) Start the newly created RAID Disk:

#/Sbin/mdadd-ar

(2) view the content of the/proc/mdstats file to check the RAID0 status.

# Cat/proc/mdstats

System display:

Personalities: [1 linear] [2 raid0]

Read-ahead not 8092 sectors

Md0: active raid0 hdb1 hdd1 xxxx

Blocks 8 k chunks

Md1: inactive

Md2: inactive

Md3: inactive

This indicates that the newly created RAID 0 can run normally.

To use the new RAID disk, a new file system should also be created on the new disk. the creation process is as follows:

# Mke2fs/dev/md0 # Note: Create an Ext2 File System on the new storage device

Create a new file system and Mount it to a directory under the root directory. The installation method is as follows:

# Mount/dev/md0/opt # Note:/opt is a Mount point created by the author in the root partition.

If necessary, you can also use Raidtools to establish RAID5 to improve data reliability.

3. Set RAID0 automatically

Add RAID0 and file system mounting to the Init. sysinit file. In this way, as long as the system starts, RAID is executed first, and you do not have to install it manually.

The user should add the following two commands to the Init. sysinit file.

/Sbin/mdrun-ar

Mount/dev/md0/opt

Of course, if you are not in trouble, you can also manually run the above command to manually start the soft RAID disk.

Ii. Recent Linux versions

If you have installed a newer version of Linux with Raidtools, you do not have to download the software and compile it yourself. You can do this in use:

1. Create a file/etc/raidtab (taking RAID0 as an example). The file content is as follows:

Raiddev/dev/md0

Raid-level 0

Nr-raid-disks 2

Persistent-superblock 1

Chunk-size 4

Device/dev/hdb1

Raid-disk0

Device/dev/hdd1

Raid-disk1

2. Run the following command:

# Mkraid/dev/md0

In this way, a new device can be generated:

/Dev/md0.

Enable soft RAID:

# Raidstart/dev/md0

The other operations are the same as above.

If the Linux system version you are using is very new and may not be suitable for you in the above two cases, you can use the third method to use Soft RAID.

Iii. Latest Linux version

When I install Red Hat Linux 6.1 on a PC and compile Raidtools0.42 and 0.50beta2 on my own, I cannot find the desired header file. After I copy the required header file, the compilation will still fail. It turns out that the new version uses a series of new functions, and the situation is slightly different. However, in the new version, Raidtools are provided. In the/sbin directory, there are a series of Raidtools, including Mkraid, Raid0run, Raidstop, and Raidstart. If you want to compile the file by yourself, you can find the latest version of Raidtools 0.9 in the China free software library, compile the Raidtools version 0.9 by yourself, and the compilation is successful.

The new version of Raidtools is slightly different. The method for creating a soft RAID is as follows:

1. Create the/etc/raidtab file. The file content is as follows:

Raiddev/dev/md0

Raid-level 0

Nr-raid-disks 2

Persistent-superblock0

Chunk-size8

Device/dev/hdb1

Raid-disk0

Device/dev/hdd1

Raid-disk 1

2. Generate a soft RAID device and run the following command:

# Mkraid-c/etc/raidtab/dev/md0

Run the following command to check the running status of RAID:

[Root @ rh61/proc] # cat mdstat

If the system displays the following:

Personalities: [raid0]

Read-ahead 1024 sectors

Md0: active raid0 hdd1 [1] hdb1 [0] 2202416 blocks 8 k chunks

Unused devices:

It indicates that your RAID 0 is running properly.

3. Create a New File System

Now, to use new devices, we should create an Ext2 File System on the new RAID disk. The command to create a new file system is as follows:

[Root @ rh61/sbin] # mkfs. ext2/dev/md0

After about two or three minutes, the new file system is correctly generated. Now you can start using it. The usage is as follows:

[Root @ rh61/sbin] # mount-t ext2/dev/md0/opt

Mount the/dev/md0 device to the/opt Installation Point.

After that, I have installed Sybase 11.0.3.3 on this soft RAID disk. After testing, we found that the performance of the entire RAID0 system is good.

Related Article

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.