Implementing RAID functions in software under Linux (1)


Data security is one of the most important issues in people's use of computers. Usually, people use hard disk mirroring technology in the server environment to achieve double backup of data. Similarly, in the Linux environment, we can also use this technology.

In the Linux environment, using the Raidtools tool, you can not only mirror two hard disks, but also make soft RAID0, RAID1, and RAID5. It is said to be a soft RAID, because the RAID disk is usually made through a dedicated RAID card. In the Linux environment, the Raidtools software can be used to implement the RAID function, so it is called soft RAID. This article describes several ways to create and use RAID disks based on different Linux distributions.

First, the earlier version of Linux

Download and compile the Raidtools package yourself. The earlier version of the Raidtools package is called md, and has now been officially renamed to Raidtools. Download address: China Free Software Library.

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

$gunzip -d raidtools-0.41.tar.gz < Br>

$tar -xvf raidtools-0.4.1.tar

Before using Raidtools, first know if the core you are currently using supports md. If the core you are using is 2.0.X and it is not compiled by yourself, in most cases it supports soft RAID. If you are not sure, you should compile the kernel yourself. When configuring, you should choose support for md. After determining the core support RAID being used, compile the Raidtools package as follows:

$cd raidtools-0.41



$make install ##make install Generates 4 devices for md0-md3 under /dev.

Click the OK button to complete the installation.

Before using Raidtools, you need to determine the type of RAID to use. Currently, Raidtools can be used as RAID0, RAID1, and RAID5. Since there are only two hard disks and RAID5 cannot be used, in addition to RAID5, you can also choose to use Linear mode or RAID0. I chose to do RAID0. The following is the production process.

1.Create a RAID disk

(1) Shutdown, add two small hard disks to the Slave interface of the first IDE controller and the Slave interface of the second IDE controller. On (the author's CD-ROM on this machine is connected to the master of the second IDE controller).

(2) Power on the system, log in as root, run the following command to partition the hard disk:

#fdisk /dev/hdb

Divide all hard disks into one The primary partition, create a /dev/hdb1 partition.

#fdisk /dev/hdd

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

(3) After:

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

Of course, in order to improve access speed, You can divide the hard disk into more detailed partitions and distribute the partitions on different hard disks as much as possible. Then, use Mdcreate to combine them into one mdx (x: 1, 2, 3).

2. Use RAID0 disk

(1) Start the newly created RAID disk:

#/sbin/mdadd -ar

(2) View The contents of the /proc/mdstats file to check the status of RAID0.

#cat /proc/mdstats

System Display:

personalities : [1 linear] [2 raid0]

read-ahead not 8092 sectors < Br>

md0 : active raid0 hdb1 hdd1 xxxx

blocks 8k chunks

md1 : inactive

md2 : inactive

md3 : inactive

This means that the newly created RAID0 is already working properly.

In order to use the new RAID disk, you should also create a new file system on the new disk. The process is as follows:

#mke2fs /dev/md0 ##Note: On a new storage device Create Ext2 file system

Create a new file system, and then mount it to a directory under the root directory, you can use it. The installation method is as follows:

#mount /dev/md0 /opt ##Note: /opt is a Mount point that the author built in the root partition

If necessary, Raidtools can also be used to create RAID5. To improve the reliability of the data.

Copyright © Windows knowledge All Rights Reserved