场景:对/dev/vdb 扩容,原大小:150G,扩容后大小:500G
/dev/vdb 进行lvm逻辑卷管理,挂载在/data 目录下
通过lsblk -f 可以看到 vg–data-lv–data 属于 vdb
这里磁盘vdb没有进行分区,有的情况下可能对vdb进行了分区,这里就会显示如下:
fdisk -l 可以看到/dev/vdb 已经变为500G
此时仅仅是磁盘大小发生了变化,LVM逻辑卷大小并没有变,我们需要将磁盘空间分配到逻辑卷里面
对/dev/vdb进行整盘扩容
[root@localhost root]# pvresize /dev/vdb
Physical volume “/dev/vdb” changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
pvresize 重设pv大小后,vg 大小也会随之调整,接下来直接扩展lv 就可以了
[root@localhost root]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb vg-data lvm2 a-- <500.00g 350.00g
[root@localhost root]# vgs
VG #PV #LV #SN Attr VSize VFree
vg-data 1 1 0 wz--n- <500.00g 350.00g
[root@localhost root]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv-data vg-data -wi-ao---- <150.00g
[root@localhost root]# lvextend -l +100%FREE /dev/mapper/vg--data-lv--data
Size of logical volume vg-data/lv-data changed from 350.00 GiB (89600 extents) to <500.00 GiB (127999 extents).
Logical volume vg-data/lv-data successfully resized.
[root@localhost root]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv-data vg-data -wi-ao---- <500.00g
报错
[root@localhost root]# lvextend -l 100%FREE /dev/mapper/vg--data-lv--data New size given (38399 extents) not larger than existing size (89600 extents)
原因:
使用以上命令调整逻辑卷的大小时,尝试将其调整为可用扩展盘区的数量,而不是当前大小加上可用扩展盘区的数量
解决:
使用X%FREE前面的+符号表示应将空格添加到当前大小lvextend -l +100%FREE /dev/volgroup/logvol
/dev/vdb分区扩容
如果是对/dev/vdb进行了分区vdb1…,操作如下,否则跳过本步骤
[root@localhost data]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xff1f5f9b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): #回车
First sector (209715200-419430399, default 209715200): #回车
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-419430399, default 419430399): #回车
Using default value 419430399
Partition 2 of type Linux and of size 100 GiB is set
Command (m for help): p
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xff1f5f9b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
/dev/vdb2 209715200 419430399 104857600 83 Linux
Command (m for help): t
Partition number (1,2, default 2): #回车
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/vdb: 214.7 GB, 214748364800 bytes, 419430400 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0xff1f5f9b
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209715199 104856576 8e Linux LVM
/dev/vdb2 209715200 419430399 104857600 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost root]# partprobe #同步分区表
[root@localhost base]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 data lvm2 a-- <100.00g 0
[root@localhost base]# pvcreate /dev/vdb2 ##创建PV
Physical volume "/dev/vdb2" successfully created.
[root@localhost base]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 data lvm2 a-- <100.00g 0
/dev/vdb2 lvm2 --- 100.00g 100.00g
[root@localhost base]# vgs
VG #PV #LV #SN Attr VSize VFree
data 1 1 0 wz--n- <100.00g 0
[root@localhost base]# vgextend vg-data /dev/vdb2 ##扩展VG
Volume group "vg-data" not found
Cannot process volume group vg-data
[root@localhost base]# vgextend data /dev/vdb2
Volume group "data" successfully extended
[root@localhost base]# vgs
VG #PV #LV #SN Attr VSize VFree
data 2 1 0 wz--n- 199.99g <100.00g
[root@localhost base]# lvextend -l +100%free /dev/mapper/data-data ##扩展LV
Size of logical volume data/data changed from <100.00 GiB (25599 extents) to 199.99 GiB (51198 extents).
Logical volume data/data successfully resized.
[root@localhost base]# vgs
VG #PV #LV #SN Attr VSize VFree
data 2 1 0 wz--n- 199.99g 0
[root@localhost base]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
data data -wi-ao---- 199.99g
[root@localhost base]# resize2fs /dev/mapper/data-data ##刷新文件系统
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/mapper/data-data is mounted on /data; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/mapper/data-data is now 52426752 blocks long.
[root@localhost base]#
[root@localhost base]#
[root@localhost base]#
[root@localhost base]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 516K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/vda1 50G 43G 4.0G 92% /
/dev/mapper/data-data 197G 93G 95G 50% /data