Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1014034
  • 博文数量: 132
  • 博客积分: 14065
  • 博客等级: 上将
  • 技术积分: 1270
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-06 16:08
文章分类

全部博文(132)

文章存档

2009年(2)

2008年(58)

2007年(14)

2006年(58)

我的朋友

分类: LINUX

2006-05-15 16:04:28

在rhel4下,用mdadm命令创建RAID磁盘阵列实验
chinajz


1.创建4个新raid分区,每个为800M,过程如下:
[root@localhost ~]# fdisk /dev/hda

The number of cylinders for this disk is set to 4864.
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)

Command (m for help): p

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1912 15358108+ 7 HPFS/NTFS
/dev/hda2 1913 1937 200812+ 83 Linux
/dev/hda3 1938 3212 10241437+ 83 Linux
/dev/hda4 3213 4864 13269690 5 Extended
/dev/hda5 3213 3722 4096543+ 83 Linux
/dev/hda6 3723 3977 2048256 83 Linux
/dev/hda7 3978 4079 819283+ 83 Linux
/dev/hda8 4080 4144 522081 82 Linux swap

Command (m for help): n
First cylinder (4145-4864, default 4145):
Using default value 4145
Last cylinder or +size or +sizeM or +sizeK (4145-4864, default 4864): +800M

Command (m for help): n
First cylinder (4243-4864, default 4243):
Using default value 4243
Last cylinder or +size or +sizeM or +sizeK (4243-4864, default 4864): +800M

Command (m for help): n
First cylinder (4341-4864, default 4341):
Using default value 4341
Last cylinder or +size or +sizeM or +sizeK (4341-4864, default 4864): +800M

Command (m for help): n
First cylinder (4439-4864, default 4439):
Using default value 4439
Last cylinder or +size or +sizeM or +sizeK (4439-4864, default 4864): +800M

Command (m for help): p

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1912 15358108+ 7 HPFS/NTFS
/dev/hda2 1913 1937 200812+ 83 Linux
/dev/hda3 1938 3212 10241437+ 83 Linux
/dev/hda4 3213 4864 13269690 5 Extended
/dev/hda5 3213 3722 4096543+ 83 Linux
/dev/hda6 3723 3977 2048256 83 Linux
/dev/hda7 3978 4079 819283+ 83 Linux
/dev/hda8 4080 4144 522081 82 Linux swap
/dev/hda9 4145 4242 787153+ 83 Linux
/dev/hda10 4243 4340 787153+ 83 Linux
/dev/hda11 4341 4438 787153+ 83 Linux
/dev/hda12 4439 4536 787153+ 83 Linux

Command (m for help): t
Partition number (1-12): 9
Hex code (type L to list codes): l

0 Empty 1c Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid
1 FAT12 1e Hidden W95 FAT1 75 PC/IX be Solaris boot
2 XENIX root 24 NEC DOS 80 Old Minix c1 DRDOS/sec (FAT-
3 XENIX usr 39 Plan 9 81 Minix / old Lin c4 DRDOS/sec (FAT-
4 FAT16 <32M 3c PartitionMagic 82 Linux swap c6 DRDOS/sec (FAT-
5 Extended 40 Venix 80286 83 Linux c7 Syrinx
6 FAT16 41 PPC PReP Boot 84 OS/2 hidden C: da Non-FS data
7 HPFS/NTFS 42 SFS 85 Linux extended db CP/M / CTOS / .
8 AIX 4d QNX4.x 86 NTFS volume set de Dell Utility
9 AIX bootable 4e QNX4.x 2nd part 87 NTFS volume set df BootIt
a OS/2 Boot Manag 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
b W95 FAT32 50 OnTrack DM 93 Amoeba e3 DOS R/O
c W95 FAT32 (LBA) 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
e W95 FAT16 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
f W95 Ext'd (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
10 OPUS 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
11 Hidden FAT12 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
12 Compaq diagnost 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
14 Hidden FAT16 <3 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
16 Hidden FAT16 61 SpeedStor a9 NetBSD f2 DOS secondary
17 Hidden HPFS/NTF 63 GNU HURD or Sys ab Darwin boot fd Linux raid auto
18 AST SmartSleep 64 Novell Netware b7 BSDI fs fe LANstep
1b Hidden W95 FAT3 65 Novell Netware b8 BSDI swap ff BBT
Hex code (type L to list codes): fd
Changed system type of partition 9 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-12): 10
Hex code (type L to list codes): fd
Changed system type of partition 10 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-12): 11
Hex code (type L to list codes): fd
Changed system type of partition 11 to fd (Linux raid autodetect)

Command (m for help): t
Partition number (1-12): 12
Hex code (type L to list codes): fd
Changed system type of partition 12 to fd (Linux raid autodetect)

Command (m for help): p

Disk /dev/hda: 40.0 GB, 40007761920 bytes
255 heads, 63 sectors/track, 4864 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/hda1 * 1 1912 15358108+ 7 HPFS/NTFS
/dev/hda2 1913 1937 200812+ 83 Linux
/dev/hda3 1938 3212 10241437+ 83 Linux
/dev/hda4 3213 4864 13269690 5 Extended
/dev/hda5 3213 3722 4096543+ 83 Linux
/dev/hda6 3723 3977 2048256 83 Linux
/dev/hda7 3978 4079 819283+ 83 Linux
/dev/hda8 4080 4144 522081 82 Linux swap
/dev/hda9 4145 4242 787153+ fd Linux raid autodetect
/dev/hda10 4243 4340 787153+ fd Linux raid autodetect
/dev/hda11 4341 4438 787153+ fd Linux raid autodetect
/dev/hda12 4439 4536 787153+ fd Linux raid autodetect

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

Calling ioctl() to re-read partition table.

The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

2使用mdadm 命令来建立一个 RAID 0 阵列/dev/md0.
[root@localhost ~]# mdadm -C /dev/md0 --level=0 --raid-devices=4 /dev/hda9 /dev/hda10 /dev/hda11 /dev/hda12
mdadm: /dev/hda9 appears to contain an ext2fs file system
size=786432K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/hda10 appears to contain an ext2fs file system
size=786432K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/hda11 appears to contain an ext2fs file system
size=786432K mtime=Thu Jan 1 08:00:00 1970
mdadm: /dev/hda12 appears to contain an ext2fs file system
size=786432K mtime=Thu Jan 1 08:00:00 1970
Continue creating array? yes
mdadm: array /dev/md0 started.
3.使用mdadm -D命令查看/dev/md0
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 00.90.01
Creation Time : Sat Nov 19 10:01:47 2005
Raid Level : raid0
Array Size : 3148288 (3.00 GiB 3.22 GB)
Raid Devices : 4
Total Devices : 4
Preferred Minor : 0
Persistence : Superblock is persistent

Update Time : Sat Nov 19 10:01:47 2005
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0

Chunk Size : 64K

Number Major Minor RaidDevice State
0 3 9 0 active sync /dev/hda9
1 3 10 1 active sync /dev/hda10
2 3 11 2 active sync /dev/hda11
3 3 12 3 active sync /dev/hda12
UUID : da00d68c:ec3e8057:dafaf27a:fb0c2fa3
Events : 0.1
4.(这步可省略,但为了便于以后管理,建议使用)创建mdadm.conf
[root@localhost ~]#echo DEVICE /dev/hd*[0-9] /dev/sd*[0-9] > /etc/mdadm.conf
[root@localhost ~]#mdadm --detail --scan >> /etc/mdadm.conf
5.在新建的raid上创建ext3
[root@localhost ~]# mkfs.ext3 /dev/md0
mke2fs 1.35 (28-Feb-2004)
max_blocks 805961728, rsv_groups = 24596, rsv_gdb = 192
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
393600 inodes, 787072 blocks
39353 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=809500672
25 block groups
32768 blocks per group, 32768 fragments per group
15744 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
inode.i_blocks = 9224, i_size = 4243456
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 22 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
6.挂载raid阵列
[root@localhost ~]# mkdir /data
[root@localhost ~]# mount /dev/md0 /data
[root@localhost ~]# cd /data
[root@localhost data]# ls
lost+found
[root@localhost data]# df -H /data
Filesystem 容量 已用 可用 已用% 挂载点
/dev/md0 3.2G 39M 3.0G 2% /data
[root@localhost data]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 hda12[3] hda11[2] hda10[1] hda9[0]
3148288 blocks 64k chunks

unused devices:
[root@localhost ~]#umount /data
7.装配已经存有的阵列
先停止活动的磁盘阵列:
mdadm -S /dev/md0
再装配到/dev/md1:
[root@localhost data]# mdadm -A /dev/md1 /dev/hda9 /dev/hda10 /dev/hda11 /dev/hda12
mdadm: /dev/md1 has been started with 4 drives.
[root@localhost data]# mdadm -D /dev/md1
/dev/md1:
Version : 00.90.01
Creation Time : Sat Nov 19 10:01:47 2005
Raid Level : raid0
Array Size : 3148288 (3.00 GiB 3.22 GB)
Raid Devices : 4
Total Devices : 4
Preferred Minor : 1
Persistence : Superblock is persistent

Update Time : Sat Nov 19 10:01:47 2005
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0

Chunk Size : 64K

Number Major Minor RaidDevice State
0 3 9 0 active sync /dev/hda9
1 3 10 1 active sync /dev/hda10
2 3 11 2 active sync /dev/hda11
3 3 12 3 active sync /dev/hda12
UUID : da00d68c:ec3e8057:dafaf27a:fb0c2fa3
Events : 0.1


mdadm /dev/md0 -f /dev/sdax
set faulty for sdax

mdadm /dev/md0 -r /dev/sdax
hot remove /dev/sdax from /dev/md0

mdadm /dev/md0 -a /dev/sdax
hot add /dev/sdax to /dev/md0

if the array is full ,new added /dev/sdax will be a spare device
it'll be auto added when a device in array is down

删除已有的software raid:
1.stop /dev/mdX:
mdadm -S /dev/mdX
or
rm /dev/mdX
2.del /etc/mdadm.conf
3.del raid mount in /etc/fstab and autofs
4.del raid part use fdisk or parted
.

怎么样设置热备盘
mdadm -C /dev/md0 -l5 --raid-devices=3 /dev/sda1 /dev/sda2 /dev/sda3 --spare-device=1 /dev/sda4
/dev/sda4就是 spare devcie

Number Major Minor RaidDevice State
0 8 7 0 active sync /dev/sda7
1 8 8 1 active sync /dev/sda8
2 8 9 2 active sync /dev/sda9
3 8 10 -1 spare /dev/sda10


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