[root@cz-03 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0x608072d8 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select(default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-419430399,默认为 2048):
将使用默认值 2048
Last 扇区,+扇区 or +size{K,M,G}(2048-419430399,默认为 419430399):
将使用默认值 419430399
分区 1 已设置为 Linux 类型,大小设为 200 GiB
命令(输入 m 获取帮助):t
已选择分区 1
Hex 代码(输入 L 列出所有代码):
Hex 代码(输入 L 列出所有代码):8e
已将分区“Linux”的类型更改为“Linux LVM”
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@cz-03 ~]# lvm
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12543
Free PE 0
Allocated PE 12543
PV UUID uqeOzg-qRxV-HzxY-kyq1-WjQu-jIgf-Db52dV
4.2 新建pv卷
lvm> pvcreate /dev/sdb1
WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/sdb1.
Physical volume "/dev/sdb1" successfully created.
4.3 再次查看pv卷,已经有两个pv卷了
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <49.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 12543
Free PE 0
Allocated PE 12543
PV UUID uqeOzg-qRxV-HzxY-kyq1-WjQu-jIgf-Db52dV
"/dev/sdb1" is a new physical volume of "<200.00 GiB"--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <200.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Ye5p9k-KQa7-fdc8-yITc-jWah-E9Up-UVz8RZ
4.4 查看vg组
lvm> vgdisplay
--- Volume group---
VG Name centos
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 <49.00 GiB
PE Size 4.00 MiB
Total PE 12543
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 0 / 0
VG UUID asHWXn-Pqs4-vzR2-xs6u-tCMv-tcPV-8n3HI9
lvm> vgdisplay
--- Volume group---
VG Name centos
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 248.99 GiB
PE Size 4.00 MiB
Total PE 63742
Alloc PE / Size 12543 / <49.00 GiB
Free PE / Size 51199 / <200.00 GiB
VG UUID asHWXn-Pqs4-vzR2-xs6u-tCMv-tcPV-8n3HI9
# 看到vg size 增加到了248.99 GiB,Free PE size 也有了200.00 GiB(51199)的大小。(我们要增加的就是这个PE的大小!!)
4.7 查看lv卷
lvm> lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Bo1IOj-Ce01-FMTS-AJ1P-h11n-eYci-X7IiAu
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-09-14 11:53:35 +0800
LV Status available
# open 2
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID T0HSKo-WS64-plXU-T0yx-WZRh-qEHU-hJ4AxX
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-09-14 11:53:36 +0800
LV Status available
# open 1
LV Size <44.00 GiB
Current LE 11263
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
4.8 使用 lvextend 为根目录进行扩容
lvm> lvextend -l +51199 /dev/centos/root
Size of logical volume centos/root changed from <44.00 GiB (11263 extents) to 243.99 GiB (62462 extents).
Logical volume centos/root successfully resized.
4.9 再次查看lv卷,LV Size 已经有243.99 GiB
lvm> lvdisplay
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID Bo1IOj-Ce01-FMTS-AJ1P-h11n-eYci-X7IiAu
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-09-14 11:53:35 +0800
LV Status available
# open 2
LV Size 5.00 GiB
Current LE 1280
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID T0HSKo-WS64-plXU-T0yx-WZRh-qEHU-hJ4AxX
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-09-14 11:53:36 +0800
LV Status available
# open 1
LV Size 243.99 GiB
Current LE 62462
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
lvm> exit
Exiting.