下面是软raid5+lvm步骤 软raid0,1,步骤类似 了解raid概念请看上章节。 http://blog.csdn.net/make_zhf/article/details/73468647
1,将 /dev/sdj1 /dev/sdg1 /dev/sdi1 /dev/sdk1 四块盘做软raid5设备名为/dev/md5 热备一块盘实用也就三块盘。2,将设备/dev/md5 做pv,vg,lv,mkfs.ext4 /dev/md5, mount.
(1) 添加了/dev/sdj1 /dev/sdg1 /dev/sdi1 /dev/sdk1 四块盘
[root@localhost /]# fdisk -l
Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x0001f40a
Device Boot Start End Blocks Id System
/dev/sda1 * 1 103 819200 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 103 613 4096000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary.
/dev/sda3 613 6528 47512576 83 Linux
Disk /dev/sdb: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x60e635c5
Device Boot Start End Blocks Id System
/dev/sdb1 1 2088 16771828+ 8e Linux LVM
Disk /dev/sdc: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xd80d43e7
Device Boot Start End Blocks Id System
/dev/sdc1 1 2088 16771828+ 8e Linux LVM
Disk /dev/sde: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdd: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xd6f8ce31
Device Boot Start End Blocks Id System
/dev/sdd1 1 2088 16771828+ 8e Linux LVM
Disk /dev/sdh: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdj: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdg: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdi: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdk: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/sdf: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
Disk /dev/mapper/datavg-lvdata01: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 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: 0x00000000
Disk /dev/mapper/datavg-lvdata02: 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: 0x00000000
Disk /dev/sdl: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x00000000
(2)分区
[root@localhost /]# fdisk /dev/sdj
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xca12e5a0.
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): p
Disk /dev/sdj: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xca12e5a0
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-2088, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): p
Disk /dev/sdj: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xca12e5a0
Device Boot Start End Blocks Id System
/dev/sdj1 1 2088 16771828+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# fdisk /dev/sdg
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xac719a1e.
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): p
Disk /dev/sdg: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xac719a1e
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-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): p
Disk /dev/sdg: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xac719a1e
Device Boot Start End Blocks Id System
/dev/sdg1 1 2088 16771828+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# fdisk /dev/sdi
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd4b19d46.
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): p
Disk /dev/sdi: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xd4b19d46
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-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): p
Disk /dev/sdi: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0xd4b19d46
Device Boot Start End Blocks Id System
/dev/sdi1 1 2088 16771828+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost /]# fdisk /dev/sdk
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x32d5562b.
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): p
Disk /dev/sdk: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x32d5562b
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-2088, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2088, default 2088):
Using default value 2088
Command (m for help): p
Disk /dev/sdk: 17.2 GB, 17179869184 bytes
255 heads, 63 sectors/track, 2088 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: 0x32d5562b
Device Boot Start End Blocks Id System
/dev/sdk1 1 2088 16771828+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
(3)创建raid5
[root@localhost /]# mdadm -C /dev/md5 -l 5 -n 3 -x 1 /dev/sdj1 /dev/sdg1 /dev/sdi1 /dev/sdk1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost /]# mdadm /dev/md5
/dev/md5: 31.97GiB raid5 3 devices, 2 spares. Use mdadm --detail for more detail.
[root@localhost /]# mdadm -Ds
ARRAY /dev/md5 metadata=1.2 spares=2 name=localhost.localdomain:5 UUID=bdafc01b:f8ae082e:d02ef0a4:b2a98161
[root@localhost /]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 sdi1[4] sdk1[3](S) sdg1[1] sdj1[0]
33526784 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
[===>.................] recovery = 17.8% (2993908/16763392) finish=9.6min speed=23856K/sec
unused devices:
[root@localhost /]# mdadm --detail /dev/md5
/dev/md5:
Version : 1.2
Creation Time : Wed Jun 21 19:54:56 2017
Raid Level : raid5
Array Size : 33526784 (31.97 GiB 34.33 GB)
Used Dev Size : 16763392 (15.99 GiB 17.17 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Wed Jun 21 20:06:57 2017
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : bdafc01b:f8ae082e:d02ef0a4:b2a98161
Events : 18
Number Major Minor RaidDevice State
0 8 145 0 active sync /dev/sdj1
1 8 97 1 active sync /dev/sdg1
4 8 129 2 active sync /dev/sdi1
3 8 161 - spare /dev/sdk1
(4)创建pv
root@localhost /]# pvcreate /dev/md5
Physical volume "/dev/md5" successfully created
[root@localhost /]# pvs
PV VG Fmt Attr PSize PFree
/dev/md5 lvm2 ---- 31.97g 31.97g
/dev/sdb1 datavg lvm2 a--u 15.99g 0
/dev/sdc1 datavg lvm2 a--u 15.99g 0
/dev/sdd1 datavg lvm2 a--u 15.99g 12.98g
/dev/sdh datavg lvm2 a--u 16.00g 16.00g
(5)创建vg
[root@localhost /]# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 4 2 0 wz--n- 63.97g 28.97g
[root@localhost /]# vgcreate datavg02 /dev/md5
Volume group "datavg02" successfully created
[root@localhost /]#
[root@localhost /]# vgs
VG #PV #LV #SN Attr VSize VFree
datavg 4 2 0 wz--n- 63.97g 28.97g
datavg02 1 0 0 wz--n- 31.97g 31.97
(6)创建lv
[root@localhost /]# lvcreate -L 10G -n lvdatavg0201 datavg02
Logical volume "lvdatavg0201" created.
[root@localhost /]#
[root@localhost /]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lvdata01 datavg -wi-ao---- 15.00g
lvdata02 datavg -wi-ao---- 20.00g
lvdatavg0201 datavg02 -wi-a----- 10.00g
[root@localhost /]# mkdir /datavg0201
[root@localhost /]# lvdisplay
--- Logical volume ---
LV Path /dev/datavg/lvdata01
LV Name lvdata01
VG Name datavg
LV UUID nYmHDL-uorm-h2P1-z2by-q0q7-cD41-hgJMJy
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-20 23:58:06 +0800
LV Status available
# open 1
LV Size 15.00 GiB
Current LE 3840
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/datavg/lvdata02
LV Name lvdata02
VG Name datavg
LV UUID ObJwel-aF2L-P6bR-SqCw-4gog-GKeR-Mdn0Py
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-21 00:03:21 +0800
LV Status available
# open 1
LV Size 20.00 GiB
Current LE 5120
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/datavg02/lvdatavg0201
LV Name lvdatavg0201
VG Name datavg02
LV UUID y2B8VI-DsSX-bTh1-C3PQ-ikJZ-TBzh-B14Ww3
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-06-21 21:25:45 +0800
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 4096
Block device 253:2
(6)格式化并挂载
[root@localhost /]# mkfs.ext4 /dev/datavg02/lvdatavg0201
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
655360 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# mount /dev/datavg02/lvdatavg0201 /datavg0201/
[root@localhost /]#
[root@localhost /]#
[root@localhost /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 45G 844M 42G 2% /
tmpfs 939M 0 939M 0% /dev/shm
/dev/sda1 772M 35M 698M 5% /boot
/dev/mapper/datavg-lvdata01
15G 141M 14G 1% /data01
/dev/mapper/datavg-lvdata02
20G 44M 19G 1% /data02
/dev/mapper/datavg02-lvdatavg0201
9.8G 23M 9.2G 1% /datavg0201