Linux中raid的创建步骤:

1、添加硬盘

Raid设备的成员是硬盘分区,需要先对硬盘分区,分区不能同一个物理硬盘上

2、安装Raidtools工具

raidtools中包含有raid创建管理工具和默认的示范性配置文件

3、编写配置文件/etc/raidtab

可以从raidtools中的示范配置文件里复制后,再做修改处理

4、创建Raid设备

实例如下:

[root@localhost root]# fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System
/dev/sda1   *         1       652   5237158+  83  Linux

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks   Id  System

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

[root@localhost root]# fdisk /dev/sdb

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522):
Using default value 522

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost root]# fdisk /dev/sdc

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-522, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-522, default 522):
Using default value 522

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

[root@localhost root]# fdisk -l

Disk /dev/sda: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks     Id   System
/dev/sda1   *         1       652   5237158+  83   Linux

Disk /dev/sdb: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks       Id  System
/dev/sdb1             1       522   4192933+  83   Linux

Disk /dev/sdc: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot    Start       End    Blocks      Id   System
/dev/sdc1             1       522   4192933+  83   Linux

[root@localhost root]# rpm -q raidtools
raidtools-1.00.3-2
[root@localhost root]# rpm -ql raidtools
/sbin/arytst
/sbin/detect_multipath
/sbin/lsraid
/sbin/mkraid
/sbin/raid0run
/sbin/raidhotadd
/sbin/raidhotremove
/sbin/raidreconf
/sbin/raidsetfaulty
/sbin/raidstart
/sbin/raidstop

/usr/share/doc/raidtools-1.00.3
/usr/share/doc/raidtools-1.00.3/COPYING
/usr/share/doc/raidtools-1.00.3/README
/usr/share/doc/raidtools-1.00.3/multipath.conf.sample
/usr/share/doc/raidtools-1.00.3/raid0.conf.sample
/usr/share/doc/raidtools-1.00.3/raid1.conf.sample
/usr/share/doc/raidtools-1.00.3/raid4.conf.sample
/usr/share/doc/raidtools-1.00.3/raid5.conf.sample
/usr/share/doc/raidtools-1.00.3/raidtab.sample
/usr/share/man
/usr/share/man/man5
/usr/share/man/man5/raidtab.5.gz
/usr/share/man/man8
/usr/share/man/man8/ckraid.8.gz
/usr/share/man/man8/lsraid.8.gz
/usr/share/man/man8/mkraid.8.gz
/usr/share/man/man8/raid0run.8.gz
/usr/share/man/man8/raidadd.8.gz
/usr/share/man/man8/raidreconf.8.gz
/usr/share/man/man8/raidrun.8.gz
/usr/share/man/man8/raidstart.8.gz
/usr/share/man/man8/raidstop.8.gz
[root@localhost root]# cp /usr/share/doc/raidtools-1.00.3/raid0.conf.sample /etc/raidtab
[root@localhost root]# vi /etc/raidtab
# Sample raid-0 configuration

raiddev                 /dev/md0

raid-level              0    # it’s not obvious but this *must* be
                               # right after raiddev

persistent-superblock   0     # set this to 1 if you want autostart,
                                     # BUT SETTING TO 1 WILL DESTROY PREVIOUS
                                    # CONTENTS if this is a RAID0 array created
                                   # by older raidtools (0.40-0.51) or mdtools!

chunk-size              16

nr-raid-disks            2
nr-spare-disks          0

device                  /dev/hda1     <———修改此项为/dev/sdb1
raid-disk               0

device                 /dev/hdb1   <———修改此项为/dev/sdc1
raid-disk               1
 

[root@localhost root]# cat /etc/raidtab
# Sample raid-0 configuration

raiddev                 /dev/md0      <—–确认这一项

raid-level              0    # it’s not obvious but this *must* be
                             # right after raiddev

persistent-superblock   0    # set this to 1 if you want autostart,
                                   # BUT SETTING TO 1 WILL DESTROY PREVIOUS
                                 # CONTENTS if this is a RAID0 array created
                               # by older raidtools (0.40-0.51) or mdtools!

chunk-size              16

nr-raid-disks           2
nr-spare-disks          0

device                  /dev/sdb1     <—–确认这一项
raid-disk               0

device                  /dev/sdc1     <—–确认这一项
raid-disk               1

[root@localhost root]# mkraid /dev/md0
handling MD device /dev/md0
analyzing super-block
[root@localhost root]# mkfs.ext3 /dev/md0
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096464 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@localhost root]# mount /dev/md0 /opt
[root@localhost root]# mount
/dev/sda1 on / type ext3 (rw)
none on /proc type proc (rw)
usbdevfs on /proc/bus/usb type usbdevfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
none on /dev/shm type tmpfs (rw)
/dev/md0 on /opt type ext3 (rw)

如果想始终使用raid 0 的话,那就做如下的操作:

[root@localhost root]# mkdir /mnt/raid0
[root@localhost root]# vi /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
none                    /dev/pts                devpts  gid=5,mode=620  0 0
none                    /proc                   proc    defaults        0 0
none                    /dev/shm                tmpfs   defaults        0 0
/dev/cdrom              /mnt/cdrom              udf,iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0                /mnt/floppy             auto    noauto,owner,kudzu 0 0
/dev/sdb5               /mnt/sdb5               ext3    defaults        0 0
/dev/md0                /mnt/raid0               ext3    defaults        0 0   <———–增加此行记录

如不想使用的话,可以先卸载raid目录,然后停止raid,最后删除/etc/raidtab文件,操作如下:

[root@localhost root]# mkdir /mnt/raid0
[root@localhost root]# umount /dev/md0
[root@localhost root]# raidstop /dev/md0
[root@localhost root]# rm /etc/raidtab
rm: remove regular file `/etc/raidtab’? y

完成所有的配置任务.