当我们创建好raid组并分区以后,分区的大小是固定不变的,那么我们怎么可以更改分区的大小呢,这就需要使用到逻辑卷LVM了
使用LVM可以在不关机的情况下,简单的改变各分区的大小
1.创建物理卷PV(多个物理卷可以组成一个卷组,也叫资源池)
[root@dinghuachong-98 ~]# yum install lvm2 -y
[root@dinghuachong-98 ~]# pvcreate /dev/md1 #将磁盘(raid组)转换成pv物理卷
#将上面添加的3个raid组都转变成物理卷
[root@dinghuachong-98 ~]# pvcreate /dev/md/raid0
WARNING: xfs signature detected on /dev/md/raid0 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/md/raid0.
Physical volume "/dev/md/raid0" successfully created.
[root@dinghuachong-98 ~]# pvcreate /dev/md1
WARNING: xfs signature detected on /dev/md1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/md1.
Physical volume "/dev/md1" successfully created.
{1}
[root@dinghuachong-98 ~]# pvcreate /dev/md5
WARNING: xfs signature detected on /dev/md5 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/md5.
Physical volume "/dev/md5" successfully created.
查看物理卷
[root@dinghuachong-98 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/md1 lvm2 --- 19.98g 19.98g
/dev/md127 lvm2 --- <39.97g <39.97g
/dev/md5 lvm2 --- <39.97g <39.97g
生成卷组lvm_raid
[root@dinghuachong-98 ~]# vgcreate lvm_raid /dev/md127 /dev/md1 /dev/md5
Volume group "lvm_raid" successfully created
[root@dinghuachong-98 ~]# vgs #查看卷组信息
VG #PV #LV #SN Attr VSize VFree
lvm_raid 3 0 0 wz--n- 99.91g 99.91g
#######################如果需要将卷组加大
[root@dinghuachong-98 ~]vgextend /dev/sdk #增加新物理卷到卷组
进行逻辑卷分区
##选项 -L 指定大小 -n指定名称,要以lv开头
[root@dinghuachong-98 ~]# lvcreate -L 5G lvm_raid
Logical volume "lvol0" created.
[root@dinghuachong-98 ~]# lvcreate -L 5G lvm_raid
Logical volume "lvol1" created.
[root@dinghuachong-98 ~]# lvcreate -L 5G -n lv1 lvm_raid
Logical volume "lv1" created.
可以对逻辑卷进行格式化,并且挂载
[root@dinghuachong-98 ~]# mkfs.xfs /dev/lvm_raid/lv1
[root@dinghuachong-98 ~]# mkfs.xfs /dev/lvm_raid/lvol0
meta-data=/dev/lvm_raid/lvol0 isize=512 agcount=8, agsize=163712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=1309696, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@dinghuachong-98 ~]# mkdir /lvm{1..5}
[root@dinghuachong-98 ~]# mount /dev/lvm_raid/lv1 /lvm1
[root@dinghuachong-98 ~]# mount /dev/lvm_raid/lvol0 /lvm2
[root@dinghuachong-98 ~]# df -h #查询成功,挂载成功,lvm逻辑卷创建成功
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 48G 1.5G 47G 4% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/lvm_raid-lv1 5.0G 33M 5.0G 1% /lvm1
/dev/mapper/lvm_raid-lvol0 5.0G 33M 5.0G 1% /lvm2
[root@dinghuachong-98 ~]# lvextend -L +5G /dev/lvm_raid/lv1 #增加空间
Size of logical volume lvm_raid/lv1 changed from 5.00 GiB (1280 extents) to 10.00 GiB (2560 extents).
Logical volume lvm_raid/lv1 successfully resized.
[root@dinghuachong-98 ~]# df -h #发现逻辑卷没有增加容量
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 48G 1.5G 47G 4% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/lvm_raid-lv1 5.0G 33M 5.0G 1% /lvm1
/dev/mapper/lvm_raid-lvol0 5.0G 33M 5.0G 1% /lvm2
[root@dinghuachong-98 ~]# xfs_growfs /dev/lvm_raid/lv1 #对逻辑卷激活(只对xfs格式化的磁盘有效)
meta-data=/dev/mapper/lvm_raid-lv1 isize=512 agcount=8, agsize=163712 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=1309696, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 1309696 to 2621440
[root@dinghuachong-98 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 48G 1.5G 47G 4% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/lvm_raid-lv1 10G 33M 10G 1% /lvm1
/dev/mapper/lvm_raid-lvol0 5.0G 33M 5.0G 1% /lvm2
逻辑卷扩大成功,至于缩小逻辑卷,在工作场景中,很危险,轻易不要操作!
当磁盘已经分区过后,创建pv是不会成功的
[root@ecs-5fd3 dev]# pvcreate /dev/vdb
Device /dev/vdb excluded by a filter.
此时,将磁盘恢复初始化,使用parted 命令
[root@ecs-5fd3 dev]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel msdos
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes
(parted) quit
Information: You may need to update /etc/fstab.
[root@ecs-5fd3 dev]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 253:0 0 40G 0 disk
├─vda1 253:1 0 4G 0 part [SWAP]
└─vda2 253:2 0 36G 0 part /
vdb 253:16 0 500G 0 disk
这时可以正常使用pv命令了。
对逻辑卷进行扩大
lsblk
查看新家盘的情况
-- 如果发现看不到新加盘情况
刷新总线
1.查看主机总线号
ls /sys/class/scsi_host/
2.重新扫描总线
echo "- - -" > /sys/class/scsi_host/host0/scan
echo "- - -" > /sys/class/scsi_host/host1/scan
echo "- - -" > /sys/class/scsi_host/host2/scan
....
echo "- - -" > /sys/class/scsi_host/host9/scan
3.此时应该能看到了
-----
4.如果是新加盘,应首先创建pv
pvcreate /dev/sde
5.将新加盘扩大到已有的vg中去
vgextend vg01 /dev/sde
6.查看情况
vgs
pvs
7.添加到lv中
lvextend -L +100G /dev/cl/root
8.初始化磁盘(并不会对现有数据造成影响,放心使用)
xfs_growfs /dev/cl/root