Chinaunix首页 | 论坛 | 博客
  • 博客访问: 146978
  • 博文数量: 52
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 490
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-05 12:05
文章分类

全部博文(52)

文章存档

2013年(1)

2010年(3)

2009年(6)

2008年(25)

2007年(17)

我的朋友

分类: LINUX

2007-11-12 21:51:06

Linux Soft Raid1 --- Example

Raidtools has been the standard software RAID management package for Linux since the inception of the software RAID driver. Over the years, raidtools have proven cumbersome to use, mostly because they rely on a configuration file (/etc/raidtab) that is difficult to maintain, and partly because its features are limited. Mdadm package provides a simple, yet robust way to manage software arrays. This document introduces mdadm by taking an example of creating raid1 in RHEL4 system. And how to replace a failed disk in raid1.

 

1.        Raid1 require same disk size of two disk, fdisk /dev/sdb and /dev/sdc to one partition sdb1 and sdc1

 

[root@RHEL3 root]# fdisk /dev/sdc

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel. Changes will remain in memory only,

until you decide to write them. After that, of course, the previous

content won't be recoverable.

The number of cylinders for this disk is set to 7832.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

 

Command (m for help): n

Command action

   e   extended

   p   primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-7832, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-7832, default 7832):

Using default value 7832

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

Syncing disks.

 

[root@RHEL3 root]# partprobe

[root@RHEL3 root]# fdisk -l

 

Disk /dev/sda: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot    Start       End    Blocks   Id  System

/dev/sda1   *         1        13    104391   83  Linux

/dev/sda2            14      1288  10241437+  83  Linux

/dev/sda3          1289      1925   5116702+  83  Linux

/dev/sda4          1926      7832  47447977+   f  Win95 Ext'd (LBA)

/dev/sda5          1926      2435   4096543+  83  Linux

/dev/sda6          2436      2690   2048256   83  Linux

/dev/sda7          2691      2817   1020096   82  Linux swap

/dev/sda8          2818      2830    104391   8e  Linux LVM

/dev/sda9          2831      2843    104391   fd  Linux raid autodetect

/dev/sda10         2844      2856    104391   83  Linux

 

Disk /dev/sdb: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot    Start       End    Blocks   Id  System

/dev/sdb1             1      7832  62910508+  83  Linux

 

Disk /dev/sdc: 64.4 GB, 64424509440 bytes

255 heads, 63 sectors/track, 7832 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot    Start       End    Blocks   Id  System

/dev/sdc1             1      7832  62910508+  83  Linux

[root@RHEL3 root]#

 

2.        Create raid1 with mdadm

 

mdadm -Cv /dev/md0 -l1 -n2 -x0 -c128 /dev/sdb1 /dev/sdc1

 

-C: create raid

-l: raid type, 0,1, 5. etc

-c: the size of block in new raid /dev/md0

 

3.        Status of raid

 

[root@RHEL3 root]# cat /proc/mdstat

Personalities : [raid1]

read_ahead 1024 sectors

Event: 1

md0 : active raid1 sdc1[1] sdb1[0]

      62910336 blocks [2/2] [UU]

      [>....................]  resync =  0.3% (199104/62910336) finish=99.6min speed=10479K/sec

unused devices:

 

######[UU] means normal, [U_] means abnormal.

######

 

4.        Configuration file /etc/mdadm.conf

/etc/mdadm.conf is optional for raid running, but some command read information from it.

Such as mdadm –As

Detect information with mdadm -Ds

[root@RHEL3 root]# mdadm -Ds

mdadm: bad /proc/mdstat line starts: Event:

ARRAY /dev/md0 level=raid1 num-devices=2 UUID=6a32b480:78bea1d2:89b65aaa:6e6c72bc

[root@RHEL3 root]#

And update above line

ARRAY /dev/md0 level=raid1 num-devices=2 UUID=6a32b480:78bea1d2:89b65aaa:6e6c72bc

to /etc/mdadm.conf with specify format.

 

 

Steps of replace a failed disk

 

1.        Mark failed device with –f option

mdadm /dev/md0 –f /dev/sda1

 

2.        Remove failed device with –r option

mdadm /dev/md0 –r /dev/sda1

 

3.        Add new device with –a option

mdadm /dev/md0 -a /dev/sdd1

 

 

 [root@allenlinux root]# mdadm /dev/md1 -a /dev/sdc2
mdadm: hot added /dev/sdc2
[root@
allenlinux root]# mdadm /dev/md2 -f /dev/sdc3
mdadm: set /dev/sdc3 faulty in /dev/md2
[root@
allenlinux root]# mdadm /dev/md2 -r /dev/sdc3
mdadm: hot remove failed for /dev/sdc3: No such device or address
[root@
allenlinux root]# mdadm /dev/md2 -a /dev/sdc3
mdadm: hot added /dev/sdc3
[root@
allenlinux root]#

 

 

 

阅读(917) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~