本文介绍 CentOS 7.x 系统基于 LVM 分区扩容的命令与方法,阅读本文前建议参考:CentOS 7.x 创建 LVM 系统分区。
目录
- 版本说明
- 方法步骤
版本说明
- CentOS Linux release 7.6
方法步骤
- 执行命令
lsblk
查看当前分区状态。
[root@... opt]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
xvda 202:0 0 40G 0 disk
├─xvda1 202:1 0 36G 0 part /
└─xvda2 202:2 0 4G 0 part [SWAP]
xvde 202:64 0 380G 0 disk
└─xvde1 202:65 0 200G 0 part
└─opt-opt 253:0 0 199G 0 lvm /opt
- 执行命令
fdisk
创建新分区。
[root@... opt]# fdisk /dev/xvde
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): 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 (419432448-796917759, default 419432448):
Using default value 419432448
Last sector, +sectors or +size{K,M,G} (419432448-796917759, default 796917759):
Using default value 796917759
Partition 2 of type Linux and of size 180 GiB is set
Command (m for help): p
Disk /dev/xvde: 408.0 GB, 408021893120 bytes, 796917760 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: 0x55a42d8e
Device Boot Start End Blocks Id System
/dev/xvde1 2048 419432447 209715200 8e Linux LVM
/dev/xvde2 419432448 796917759 188742656 83 Linux
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
- 执行命令
pvcreate
创建物理卷。
[root@... opt]# pvcreate /dev/xvde2
Physical volume "/dev/xvde2" successfully created.
[root@... opt]# pvscan
PV /dev/xvde1 VG opt lvm2 [<200.00 GiB / 1020.00 MiB free]
PV /dev/xvde2 lvm2 [<180.00 GiB]
Total: 2 [<380.00 GiB] / in use: 1 [<200.00 GiB] / in no VG: 1 [<180.00 GiB]
- 执行命令
vgextend
将物理卷加入卷组。
[root@... opt]# vgextend opt /dev/xvde2
Volume group "opt" successfully extended
[root@... opt]# vgs
VG #PV #LV #SN Attr VSize VFree
opt 2 1 0 wz--n- 379.99g 180.99g
- 执行命令
lvextend
扩展逻辑卷。
[root@... opt]# lvextend -L 379G /dev/opt/opt
Size of logical volume opt/opt changed from 199.00 GiB (50944 extents) to 379.00 GiB (97024 extents).
Logical volume opt/opt successfully resized.
[root@... opt]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 1024M 0 rom
xvda 202:0 0 40G 0 disk
├─xvda1 202:1 0 36G 0 part /
└─xvda2 202:2 0 4G 0 part [SWAP]
xvde 202:64 0 380G 0 disk
├─xvde1 202:65 0 200G 0 part
│ └─opt-opt 253:0 0 379G 0 lvm /opt
└─xvde2 202:66 0 180G 0 part
└─opt-opt 253:0 0 379G 0 lvm /opt
- 执行命令
df -h
检查/opt
所在分区大小未改变。
[root@... ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 36G 5.5G 29G 17% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 18M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/opt-opt 196G 61M 186G 1% /opt
tmpfs 1.6G 12K 1.6G 1% /run/user/991
tmpfs 1.6G 0 1.6G 0% /run/user/0
- 执行命令
resize2fs
重设卷组大小。
[root@... ~]# resize2fs /dev/opt/opt
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/opt/opt is mounted on /opt; on-line resizing required
old_desc_blocks = 25, new_desc_blocks = 48
The filesystem on /dev/opt/opt is now 99352576 blocks long.
[root@... ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 36G 5.5G 29G 17% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 18M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/opt-opt 373G 67M 356G 1% /opt
tmpfs 1.6G 12K 1.6G 1% /run/user/991
tmpfs 1.6G 0 1.6G 0% /run/user/0
网友评论