先在虚拟机下添加4块新硬盘
用mdadm创建RAID 10
[root@localhost ~]# mdadm -Cv /dev/md0 -a yes -n 4 -l 10 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to n2
mdadm: layout defaults to n2
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]#
将RAID 10磁盘阵列格式化为ext4格式
[root@localhost ~]# mkfs.ext4 /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
2621440 inodes, 10477312 blocks
523865 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 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, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#
将硬盘挂载到系统
[root@localhost ~]# mkdir /opt/RAID
[root@localhost ~]# mount /dev/md0 /opt/RAID
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 12G 6.0G 66% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 80K 1.9G 1% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/md0 40G 49M 38G 1% /opt/RAID
[root@localhost ~]#
编辑fstab文件,以实现开机自启
[root@localhost ~]# echo "/dev/md0 /opt/RAID ext4 defaults 0 0" >> /etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Sep 17 08:27:01 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=0d1079c2-f7bf-4393-a174-326867ddf2c3 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/md0 /opt/RAID ext4 defaults 0 0
[root@localhost ~]#
用mdadm创建RAID 5并添加一块备份盘
[root@localhost ~]# mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]#
将RAID 5磁盘阵列格式化为ext4格式
[root@localhost ~]# mkfs.ext4 /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
2621440 inodes, 10477312 blocks
523865 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 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, 2654208,
4096000, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]#
将硬盘挂载到系统
[root@localhost ~]# mkdir /opt/RAID
[root@localhost ~]# mount /dev/md0 /opt/RAID
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 6.5G 12G 38% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/md0 40G 49M 38G 1% /opt/RAID
[root@localhost ~]#
编辑fstab文件,以实现开机自启
[root@localhost ~]# echo "/dev/md0 /opt/RAID ext4 defaults 0 0" >> /etc/fstab
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Sep 17 08:27:01 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 1 1
UUID=0d1079c2-f7bf-4393-a174-326867ddf2c3 /boot xfs defaults 1 2
/dev/mapper/rhel-swap swap swap defaults 0 0
/dev/md0 /opt/RAID ext4 defaults 0 0
[root@localhost ~]#
让新添加的硬盘支持LVM技术
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc /dev/sdd /dev/sde
Physical volume "/dev/sdb" successfully created
Physical volume "/dev/sdc" successfully created
Physical volume "/dev/sdd" successfully created
Physical volume "/dev/sde" successfully created
[root@localhost ~]#
把新设备加到vo卷组中
[root@localhost ~]# vgcreate vo /dev/sdb /dev/sdc /dev/sdd /dev/sde
Volume group "vo" successfully created
[root@localhost ~]#
切割成100M左右的逻辑卷设备
[root@localhost ~]# lvcreate -n ov -l 25 vo
Logical volume "ov" created
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID hgy1fQ-GcJ5-XCUn-KriK-zeSP-I0tQ-u6hOpR
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-09-17 16:27:00 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 7Kx057-PF8v-Fnx7-kNeT-TRkz-7VQ8-XTyC7p
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-09-17 16:27:01 +0800
LV Status available
# open 1
LV Size 17.51 GiB
Current LE 4482
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
--- Logical volume ---
LV Path /dev/vo/ov
LV Name ov
VG Name vo
LV UUID fw1bi5-wsZf-od8L-ibxn-TeoU-Z4ZV-eeMtjH
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2018-09-24 10:14:50 +0800
LV Status available
# open 0
LV Size 100.00 MiB
Current LE 25
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
[root@localhost ~]#
格式化并使用
[root@localhost ~]# mkfs.ext4 /dev/vo/ov
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
25688 inodes, 102400 blocks
5120 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=33685504
13 block groups
8192 blocks per group, 8192 fragments per group
1976 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mkdir /opt/volume
[root@localhost ~]# mount /dev/vo/ov /opt/volume
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 6.5G 12G 38% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vo-ov 93M 1.6M 85M 2% /opt/volume
[root@localhost ~]#
扩展逻辑卷
先解挂载
[root@localhost ~]# umount /dev/mapper/vo-ov
扩容
[root@localhost ~]# lvextend -l 50 /dev/mapper/vo-ov
Extending logical volume ov to 200.00 MiB
Logical volume ov successfully resized
[root@localhost ~]#
检查逻辑卷
[root@localhost ~]# e2fsck -f /dev/mapper/vo-ov
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vo-ov: 11/25688 files (9.1% non-contiguous), 8896/102400 blocks
[root@localhost ~]#
重置硬盘容量
[root@localhost ~]# resize2fs /dev/mapper/vo-ov
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vo-ov to 204800 (1k) blocks.
The filesystem on /dev/mapper/vo-ov is now 204800 blocks long.
[root@localhost ~]#
挂载
[root@localhost ~]# mount /dev/mapper/vo-ov /opt/volume
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 6.5G 12G 38% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vo-ov 190M 1.6M 175M 1% /opt/volume
[root@localhost ~]#
缩小逻辑卷
先卸载逻辑卷
检查逻辑卷
[root@localhost ~]# e2fsck -f /dev/mapper/vo-ov
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/mapper/vo-ov: 11/49400 files (9.1% non-contiguous), 11884/204800 blocks
[root@localhost ~]#
缩小逻辑卷
[root@localhost ~]# resize2fs /dev/mapper/vo-ov 50M
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/mapper/vo-ov to 51200 (1k) blocks.
The filesystem on /dev/mapper/vo-ov is now 51200 blocks long.
[root@localhost ~]#
挂载
[root@localhost ~]# mount /dev/mapper/vo-ov /opt/volume
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 6.5G 12G 38% /
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 84K 1.9G 1% /dev/shm
tmpfs 1.9G 8.9M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vo-ov 45M 1.1M 40M 3% /opt/volume
[root@localhost ~]#
快照逻辑卷
创建快照卷
[root@localhost ~]# lvcreate -l 50 -s -n kuaizhao /dev/vo/ov
Logical volume "kuaizhao" created
[root@localhost ~]#
卸载逻辑卷
还原快照卷
[root@localhost ~]# lvconvert --merge /dev/vo/kuaizhao
Merging of volume kuaizhao started.
ov: Merged: 100.0%
Merge of snapshot into logical volume ov has finished.
Logical volume "kuaizhao" successfully removed
[root@localhost ~]#
删除逻辑卷
卸载已挂载的逻辑卷
[root@localhost ~]# umnoun /opt/volume
[root@localhost ~]#
依次删除逻辑卷、卷组、物理卷
[root@localhost ~]# lvremove /dev/vo/ov
Do you really want to remove active logical volume ov? [y/n]: y
Logical volume "ov" successfully removed
[root@localhost ~]# vgremove /dev/vo
Volume group "vo" successfully removed
[root@localhost ~]# pvremove /dev/sdb /dev/sdc /dev/sdd /dev/sde
Labels on physical volume "/dev/sdb" successfully wiped
Labels on physical volume "/dev/sdc" successfully wiped
Labels on physical volume "/dev/sdd" successfully wiped
Labels on physical volume "/dev/sde" successfully wiped
[root@localhost ~]#