硬盘2为新添加的磁盘
sdb为新加的磁盘,大小为10G,我们的目标为将根目录 (klas-root 253:0 0 99.8G 0 lvm / )扩容到110G
[root@tpops ~]# fdisk -l ##查看所有硬盘信息
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5e751d69
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 411647 409600 200M 83 Linux
/dev/sda2 411648 209715199 209303552 99.8G 8e Linux LVM
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: Virtual disk
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 /dev/mapper/klas-root: 99.82 GiB, 107160272896 bytes, 209297408 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
[root@tpops ~]# fdisk /dev/sdb ##分区
Welcome to fdisk (util-linux 2.35.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.
Created a new DOS disklabel with disk identifier 0x55988a9b.
Command (m for help): n ##新建
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): ##直接enter默认
Using default response p.
Partition number (1-4, default 1): ##直接enter默认
First sector (2048-20971519, default 2048): ##直接enter默认
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-20971519, default 20971519): ##直接enter默认
Created a new partition 1 of type 'Linux' and of size 10 GiB.
Command (m for help): p ##查看详情
Disk /dev/sdb: 10 GiB, 10737418240 bytes, 20971520 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x55988a9b
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 20971519 20969472 10G 83 Linux
Command (m for help): w ##保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@tpops ~]# fdisk /dev/sdb ##修改类型
Welcome to fdisk (util-linux 2.35.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): t ##修改类型
Selected partition 1
Hex code (type L to list all codes): 8e ##LVM的分区代码
Changed type of partition 'Linux LVM' to 'Linux LVM'.
Command (m for help): w ##保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@tpops ~]# pvcreate /dev/sdb1 ##创建物理卷
Physical volume "/dev/sdb1" successfully created.
查看物理卷详情
[root@tpops ~]# pvdisplay ##查看物理卷详情
--- Physical volume ---
PV Name /dev/sda2
VG Name klas
PV Size 99.80 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25549
Free PE 0
Allocated PE 25549
PV UUID 00KZbw-0Huv-vMDv-emeY-WKeI-kA6Z-slvq1s
"/dev/sdb1" is a new physical volume of "<10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdb1
VG Name
PV Size <10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID Hcl0LC-57hq-h3ph-xi0M-PVk4-Od6r-JTI4P6
将物理卷PV加入卷组VG
Bash
[root@tpops ~]# vgdisplay ##查看卷组情况
--- Volume group ---
VG Name klas ##卷组的名称
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 1
Act PV 1
VG Size 99.80 GiB
PE Size 4.00 MiB
Total PE 25549
Alloc PE / Size 25549 / 99.80 GiB
Free PE / Size 0 / 0
VG UUID cOs0jz-YCrA-jf3a-DBHd-jYOx-1mTG-42aKdW
Bash
[root@tpops ~]# vgextend klas /dev/sdb1
Volume group "klas" successfully extended
添加完成后再次查看卷组信息
Bash
[root@tpops ~]# vgdisplay
--- Volume group ---
VG Name klas
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size <109.80 GiB ##对比上面的信息容量增加了10g
PE Size 4.00 MiB
Total PE 28108
Alloc PE / Size 25549 / 99.80 GiB
Free PE / Size 2559 / <10.00 GiB ##可用已经多了将近10G
VG UUID cOs0jz-YCrA-jf3a-DBHd-jYOx-1mTG-42aKdW
下面是对现有分区进行逻辑卷扩容,我们这里根分区为100G,我们准备扩容根分区
查看根分区的LV路径
[root@tpops ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 31G 0 31G 0% /dev
tmpfs 31G 24K 31G 1% /dev/shm
tmpfs 31G 9.3M 31G 1% /run
tmpfs 31G 0 31G 0% /sys/fs/cgroup
/dev/mapper/klas-root 100G 34G 67G 34% /
tmpfs 31G 684K 31G 1% /tmp
/dev/sda1 195M 184M 12M 95% /boot
tmpfs 6.2G 0 6.2G 0% /run/user/993
tmpfs 6.2G 0 6.2G 0% /run/user/1000
tmpfs 6.2G 0 6.2G 0% /run/user/0
下面进行扩容
[root@tpops ~]# lvextend -l +100%FREE /dev/mapper/klas-root
Size of logical volume klas/root changed from 99.80 GiB (25549 extents) to <109.80 GiB (28108 extents).
Logical volume klas/root successfully resized.
查看扩容后的逻辑卷大小
[root@tpops ~]# lvdisplay /dev/mapper/klas-root
--- Logical volume ---
LV Path /dev/klas/root
LV Name root
VG Name klas
LV UUID WIF4tK-mt6v-Y1YH-7eKE-1cQ5-7fbH-5rl7zw
LV Write Access read/write
LV Creation host, time localhost, 2022-10-26 14:14:12 +0800
LV Status available
# open 1
LV Size <109.80 GiB
Current LE 28108
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
使用xfs_growfs进行在线调整xfs格式的文件系统大小
[root@tpops ~]# xfs_growfs /
meta-data=/dev/mapper/klas-root isize=512 agcount=4, agsize=6540544 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1
data = bsize=4096 blocks=26162176, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=12774, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 26162176 to 28782592
ext4格式在线调整为resize2fs xfs格式在线调整为xfs_growfs
最后查看根分区的大小是否扩容成功
[root@tpops ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 31G 0 31G 0% /dev
tmpfs 31G 24K 31G 1% /dev/shm
tmpfs 31G 9.3M 31G 1% /run
tmpfs 31G 0 31G 0% /sys/fs/cgroup
/dev/mapper/klas-root 110G 34G 77G 31% /
tmpfs 31G 684K 31G 1% /tmp
/dev/sda1 195M 184M 12M 95% /boot
tmpfs 6.2G 0 6.2G 0% /run/user/993
tmpfs 6.2G 0 6.2G 0% /run/user/1000
tmpfs 6.2G 0 6.2G 0% /run/user/0