[root@gbase8s ~]# parted -s /dev/sdb mklabel gpt
[root@gbase8s ~]# parted /dev/sdb
GNU Parted 3.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
(parted) mkpart
分区名称? []?
文件系统类型? [ext2]? xfs
起始点? 1MiB
结束点? 10GiB
错误: The location 10GiB is outside of the device /dev/sdb.
(parted) mkpart
分区名称? []?
文件系统类型? [ext2]? xfs
起始点? 1MiB
结束点? 9GiB
(parted)
(parted)
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 9664MB 9663MB
(parted) q
信息: You may need to update /etc/fstab.
[root@gbase8s ~]# parted -s /dev/sdb set 1 lvm on
[root@gbase8s ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <39.00g 0
[root@gbase8s ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 2 0 wz--n- <39.00g 0
[root@gbase8s ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <35.00g
swap rhel -wi-ao---- 4.00g
[root@gbase8s ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs b2e254ef-a8c3-4e12-824d-6e14242ede15 /boot
└─sda2 LVM2_member 5ExIkS-cVh0-ETU5-HWye-DYvi-BhWo-jZpasj
├─rhel-root xfs bffb5904-cc95-40b0-8c9d-c325305ffb93 /
└─rhel-swap swap 9c5383be-a927-407f-b23c-743671ae21f3 [SWAP]
sdb
sr0 iso9660 RHEL-7.4 Server.x86_64 2018-01-19-09-23-44-00 /run/media/root/RHEL-7.4 Server.x86_64
从上面可以看到卷组大小不够,PV也不够,此处需要自行添加PV,扩展逻辑卷组(如果/dev/sda磁盘大小充足,就不要去其它磁盘上新建分区来作为PV,并且尽量需要多大容量就给接近的容量,不要一次性分配过大)。
挂载点:
[root@gbase8s ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/rhel-root 35G 6.2G 29G 18% /
devtmpfs 896M 0 896M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 9.1M 903M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 183M 16K 183M 1% /run/user/0
/dev/sr0 4.1G 4.1G 0 100% /run/media/root/RHEL-7.4 Server.x86_64
[root@gbase8s ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Oct 8 14:35:28 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=b2e254ef-a8c3-4e12-824d-6e14242ede15 /boot xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
[root@gbase8s ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created.
[root@gbase8s ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 rhel lvm2 a-- <39.00g 0
/dev/sdb1 lvm2 --- <9.00g <9.00g
[root@gbase8s ~]# vgextend rhel /dev/sdb1
Volume group "rhel" successfully extended
[root@gbase8s ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 2 2 0 wz--n- 47.99g <9.00g
[root@gbase8s ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- <35.00g
swap rhel -wi-ao---- 4.00g
[root@gbase8s ~]# lvextend -r -L 40GiB /dev/rhel/root
Size of logical volume rhel/root changed from <35.00 GiB (8959 extents) to 40.00 GiB (10240 extents).
Logical volume rhel/root successfully resized.
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=2293504 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=9174016, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=4479, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 9174016 to 10485760
成功后如下图所示:

注意:此处扩展文件系统可以用上述命令一次性搞定,也可以采用传统方法,如果是XFS,先lvextend -L 40GiB /dev/rhel/root,再xfs_growfs,如果是EXT文件系统,先lvextend-L 40GiB /dev/rhel/root,再resize2fs ;或对于EXT文件系统和XFS都使用:lvextend -r -L 40GiB /dev/rhel/root 一条命令搞定;扩展后的逻辑卷大小可能有微小差别,这很正常,在小范围的差别是正常的。