在vmware中添加4块硬盘,做raid5 这里不做备份盘,

1,更新分区信息,

[root@localhost ~]# partprobe

2,为硬盘分区;

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

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7161a9e8

  Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xcb372ed1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

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

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb372ed1

  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         130     1044193+  8e  Linux LVM

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk /dev/sdd
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xffc652e0.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

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

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd0cf69f4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

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

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisl -l
bash: fdisl: command not found
[root@localhost ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007d019

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      204800   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              26          91      524288   82  Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3              91        2611    20241408   83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x7161a9e8

  Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         130     1044193+  8e  Linux LVM

Disk /dev/sdc: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xcb372ed1

  Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         130     1044193+  8e  Linux LVM

Disk /dev/sdd: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xffc652e0

  Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         130     1044193+  8e  Linux LVM

Disk /dev/sde: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd0cf69f4

  Device Boot      Start         End      Blocks   Id  System
/dev/sde1               1         130     1044193+  8e  Linux LVM

3,建立raid5

[root@localhost ~]# mdadm --create --auto=yes /dev/md5 --level=5 --raid-device=4 /dev/sd{b..e}1
[root@localhost ~]# mdadm --detail /dev/md5
/dev/md5:
       Version : 1.2
 Creation Time : Wed May 29 23:29:01 2013
    Raid Level : raid5
    Array Size : 3130368 (2.99 GiB 3.21 GB)
 Used Dev Size : 1043456 (1019.17 MiB 1068.50 MB)
  Raid Devices : 4
 Total Devices : 4
   Persistence : Superblock is persistent

   Update Time : Wed May 29 23:29:15 2013
         State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
 Spare Devices : 0

        Layout : left-symmetric
    Chunk Size : 512K

          Name : localhost.localdomain:5  (local to host localhost.localdomain)
          UUID : 699389f8:98757123:8814f027:4c7117fc
        Events : 18

   Number   Major   Minor   RaidDevice State
      0       8       17        0      active sync   /dev/sdb1
      1       8       33        1      active sync   /dev/sdc1
      2       8       49        2      active sync   /dev/sdd1
      4       8       65        3      active sync   /dev/sde1
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sde1[4] sdd1[2] sdc1[1] sdb1[0]
     3130368 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
4,建立raid5的配置文件,设置系统启动时启动raid

[root@localhost ~]# vim /etc/mdadm.conf
[root@localhost ~]# mdadm --detail --scan >>/etc/mdadm.conf
[root@localhost ~]# cat /etc/mdadm.conf
ARRAY /dev/md5 UUID=699389f8:98757123:8814f027:4c7117fc
5,建立lvm

[root@localhost ~]# pvcreate /dev/md5
 Writing physical volume data to disk "/dev/md5"
 Physical volume "/dev/md5" successfully created
[root@localhost ~]# vgcreate haha /dev/md5
 Volume group "haha" successfully created
[root@localhost ~]# vgdisplay
 --- Volume group ---
 VG Name               haha
 System ID            
 Format                lvm2
 Metadata Areas        1
 Metadata Sequence No  1
 VG Access             read/write
 VG Status             resizable
 MAX LV                0
 Cur LV                0
 Open LV               0
 Max PV                0
 Cur PV                1
 Act PV                1
 VG Size               2.98 GiB
 PE Size               4.00 MiB
 Total PE              763
 Alloc PE / Size       0 / 0  
 Free  PE / Size       763 / 2.98 GiB
 VG UUID               6dBs5x-TTHn-NWQE-3BIH-dVXJ-OUne-1xAIWE

[root@localhost ~]# vgchange -ay haha //激活卷组 无需重启系统
 0 logical volume(s) in volume group "haha" now active
[root@localhost ~]# lvcreate -l 763 -n lvhaha haha //建立LV lvhaha 大小2.98G
 Logical volume "lvhaha" created

6,格式化逻辑卷

[root@localhost ~]# mkfs.ext4 /dev/haha/lvhaha
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks, Stripe width=384 blocks
195456 inodes, 781312 blocks
39065 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=801112064
24 block groups
32768 blocks per group, 32768 fragments per group
8144 inodes per group
Superblock backups stored on blocks:
   32768, 98304, 163840, 229376, 294912

正在写入inode表: 完成                            
Creating journal (16384 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

7,挂载到目录

[root@localhost ~]# mkdir /lvhaha
[root@localhost ~]# mount /dev/haha/lvhaha  /lvhaha/

[root@localhost ~]# df -hT
文件系统    类型      容量  已用  可用 已用%% 挂载点
/dev/sda3     ext4     20G  3.5G   15G  20% /
tmpfs        tmpfs    495M  276K  495M   1% /dev/shm
/dev/sda1     ext4    194M   28M  156M  16% /boot
/dev/mapper/haha-lvhaha
             ext4    3.0G   69M  2.8G   3% /lvhaha

8,让系统启动是自动挂载,

[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# cat /etc/fstab
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/haha/lvhaha        /lvhaha                 ext4    defaults        0 0
9, 查看分区空间与状态

[root@localhost ~]# df -h /lvhaha/
文件系统          容量  已用  可用 已用%% 挂载点
/dev/mapper/haha-lvhaha
                     3.0G   69M  2.8G   3% /lvhaha
[root@localhost ~]# pvdisplay
 --- Physical volume ---
 PV Name               /dev/md5
 VG Name               haha
 PV Size               2.99 GiB / not usable 5.00 MiB
 Allocatable           yes (but full)
 PE Size               4.00 MiB
 Total PE              763
 Free PE               0
 Allocated PE          763
 PV UUID               hmD22I-7iwk-qi23-Z5l0-CiKx-0etr-AWaqTq
10,模拟故障/dev/sdd1盘坏了,

[root@localhost ~]# mdadm /dev/md5 --fail /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md5
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sdb1[0] sde1[4] sdd1[2](F) sdc1[1]
     3130368 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/3] [UU_U]

11,解决办法,添加新盘

[root@localhost ~]# mdadm /dev/md5 -a /dev/sdd1
mdadm: added /dev/sdd1