转载自:https://blog.csdn.net/zyqash/article/details/123685343
前言
扩容是一项很简单的工作,但是有时候因为长时间没有操作过扩容,指令会比较生疏,因此写一篇扩容的文档,方便在再次失忆的情况下能快速回忆起操作流程。
逻辑卷扩容的流程:创建PV-->扩容VG-->扩容LV。
以下是扩容的详细流程。
1、查看当前 / 分区大小
-
[root
@rt7_node03 ~]
# df -Th
-
Filesystem Type Size Used Avail Use% Mounted on
-
/dev/mapper
/cl-root xfs 7.1G 1.2G 6.0G 16% /
-
devtmpfs devtmpfs
486M
0
486M
0%
/dev
-
tmpfs tmpfs 496M 0 496M 0% /dev
/shm
-
tmpfs tmpfs 496M 6.7M 490M 2% /run
-
tmpfs tmpfs
496M
0
496M
0%
/sys/fs
/cgroup
-
/dev
/vda1 xfs 1014M 139M 876M 14% /boot
-
tmpfs tmpfs
100M
0
100M
0%
/run/user
/0
-
2、添加一块磁盘,查看新磁盘的大小
-
[root@rt7_node03 ~]
# lsblk
-
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
-
sr
0
11:
0
1
1024M
0 rom
-
vda
252:
0
0
9G
0 disk
-
|-vda1
252:
1
0
1G
0 part /boot
-
`-vda2 252:2 0 8G 0 part
-
|-cl-swap 253:0 0 924M 0 lvm [SWAP]
-
`-cl-root
253:
1
0
7.1G
0 lvm /
-
vdb
252:
16
0
20G
0 disk
3、给新磁盘分区
-
[
root@rt7_node03 ~]
# 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.
-
-
Device does not contain a recognized partition table
-
Building a new DOS disklabel with disk identifier 0x67c61676.
-
-
Command (m for help): n
-
Partition type:
-
p primary (0 primary, 0 extended, 4 free)
-
e extended
-
Select (default p):
-
Using default response p
-
Partition number (1-4, default 1):
-
First sector (2048-41943039, default 2048):
-
Using default value 2048
-
Last sector, +sectors or +size{K,M,G} (
2048
-41943039,
default
41943039):
-
Using
default
value
41943039
-
Partition
1 of type Linux
and of size
20
GiB is set
-
-
Command (m for help): w
-
The partition table has been altered!
-
-
Calling ioctl() to re-read partition table.
-
Syncing disks.
-
[root@rt7_node03 ~]# lsblk
-
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
-
sr0 11:0 1 1024M 0 rom
-
vda 252:0 0 9G 0 disk
-
|-vda1 252:1 0 1G 0 part /boot
-
`-vda2 252:2 0 8G 0 part
-
|-cl-swap 253:0 0 924M 0 lvm [SWAP]
-
`-cl-root 253:1 0 7.1G 0 lvm /
-
vdb 252:16 0 20G 0 disk
-
`-vdb1 252:17 0 20G 0 part
4、安装所需的软件包
[root@rt7_node03 ~]# yum install -y lvm2-2.02.166-1.el7.x86_64
5、创建pv物理卷
-
[root
@rt7_node03 ~]
# pvcreate /dev/vdb1
-
Physical volume
"/dev/vdb1" successfully created.
6、查看新创建的物理卷
-
[root
@rt7_node03
~]# pvdisplay
-
--- Physical volume ---
-
PV Name
/dev
/vda2
-
VG Name cl
-
PV Size
8.00 GiB
/
not usable
3.00 MiB
-
Allocatable yes (but
full)
-
PE Size
4.00 MiB
-
Total PE
2047
-
Free PE
0
-
Allocated PE
2047
-
PV UUID KToRtg
-Mwyz
-bkxt
-Erln
-a5Ro
-HJDw
-orTvQo
-
-
"/dev/vdb1"
is a
new physical volume
of "20.00 GiB"
-
--- NEW Physical volume ---
-
PV Name
/dev
/vdb1
-
VG Name
-
PV Size
20.00 GiB
-
Allocatable
NO
-
PE Size
0
-
Total PE
0
-
Free PE
0
-
Allocated PE
0
-
PV UUID po26cZ
-PVjR
-NZxG
-UkDw
-wzcC
-yJ7z
-EnXlGa
7、查看VG
-
[root
@rt7_node03
~]# vgdisplay
-
--- Volume group ---
-
VG Name cl
-
System ID
-
Format lvm2
-
Metadata Areas
1
-
Metadata Sequence
No
3
-
VG Access read
/write
-
VG Status resizable
-
MAX LV
0
-
Cur LV
2
-
Open LV
2
-
Max PV
0
-
Cur PV
1
-
Act PV
1
-
VG Size
8.00 GiB
-
PE Size
4.00 MiB
-
Total PE
2047
-
Alloc PE
/ Size
2047
/
8.00 GiB
-
Free PE
/ Size
0
/
0
-
VG UUID U8mInR
-Xnzq
-hTka
-AE2D
-Y5fV
-r3Qx
-LLbdi9
-
-
[root
@rt7_node03
~]# vgs
-
VG #PV #LV #SN Attr VSize VFree
-
cl
1
2
0 wz
--n- 8.00g 0
8、扩展VG
-
[
root@rt7_node03 ~]
# vgextend cl /dev/vdb1
-
Volume
group
"cl" successfully extended
9、查看VG
-
[root
@rt7_node03
~]# vgs
-
VG #PV #LV #SN Attr VSize VFree
-
cl
2
2
0 wz
--n- 27.99g 20.00g
-
[root
@rt7_node03
~]# vgdisplay
-
--- Volume group ---
-
VG Name cl
-
System ID
-
Format lvm2
-
Metadata Areas
2
-
Metadata Sequence
No
4
-
VG Access read
/write
-
VG Status resizable
-
MAX LV
0
-
Cur LV
2
-
Open LV
2
-
Max PV
0
-
Cur PV
2
-
Act PV
2
-
VG Size
27.99 GiB
-
PE Size
4.00 MiB
-
Total PE
7166
-
Alloc PE
/ Size
2047
/
8.00 GiB
-
Free PE
/ Size
5119
/
20.00 GiB
-
VG UUID U8mInR
-Xnzq
-hTka
-AE2D
-Y5fV
-r3Qx
-LLbdi9
10、查看LV
-
[root
@rt7_node03
~]# lvs
-
LV VG Attr LSize Pool Origin Data
% Meta
% Move Log Cpy
%Sync
Convert
-
root cl
-wi
-ao
---- 7.09g
-
swap cl
-wi
-ao
---- 924.00m
11、扩展LV
-
[
root@rt7_node03 ~]
# lvextend -L +19G /dev/cl/root
-
Size of logical volume cl/root changed
from
7.09 GiB (
1816 extents) to
26.09 GiB (
6680 extents).
-
Logical volume cl/root successfully resized.
12、使用xfs_growfs命令使扩容生效
-
[root@rt7_node03 ~]# xfs_growfs /dev/cl/root
-
meta-
data=/dev/mapper/cl-root isize=512 agcount=4, agsize=464896 blks
-
= sectsz=
512 attr=
2, projid32bit=
1
-
= crc=
1 finobt=
0 spinodes=
0
-
data = bsize=4096 blocks=1859584, imaxpct=25
-
= sunit=
0 swidth=
0 blks
-
naming =version
2 bsize=
4096 ascii-ci=
0 ftype=
1
-
log =internal bsize=
4096 blocks=
2560, version=
2
-
= sectsz=
512 sunit=
0 blks, lazy-count=
1
-
realtime =none extsz=
4096 blocks=
0, rtextents=
0
-
data blocks changed from 1859584 to 6840320
13、查看 / 分区的大小
-
[root
@rt7_node03 ~]
# df -Th
-
Filesystem Type Size Used Avail Use% Mounted on
-
/dev/mapper
/cl-root xfs 27G 1.2G 25G 5% /
-
devtmpfs devtmpfs
486M
0
486M
0%
/dev
-
tmpfs tmpfs 496M 0 496M 0% /dev
/shm
-
tmpfs tmpfs 496M 6.7M 490M 2% /run
-
tmpfs tmpfs
496M
0
496M
0%
/sys/fs
/cgroup
-
/dev
/vda1 xfs 1014M 139M 876M 14% /boot
-
tmpfs tmpfs
100M
0
100M
0%
/run/user
/0
-
可以看到 / 分区已新增了19G。