操作系统:
CentOS Stream9
测试过程:
模拟磁盘被沾满,
创建文件
测试脚本
for i in `seq 10`
do
# echo $i
dd if=/dev/zero of=./$i-$RANDOM.txt bs=1M count=1024
Done
[root@localhost ~]# vim 2.txt
[root@localhost ~]# sh 2.txt
记录了1024+0 的读入
记录了1024+0 的写出
1073741824字节(1.1 GB,1.0 GiB)已复制,0.749692 s,1.4 GB/s
记录了1024+0 的读入
记录了1024+0 的写出
1073741824字节(1.1 GB,1.0 GiB)已复制,8.16303 s,132 MB/s
记录了1024+0 的读入
记录了1024+0 的写出
模拟结果;
可以看到磁盘快占满了
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 777M 11M 767M 2% /run
/dev/mapper/cs-root xfs 10G 9.4G 628M 94% /
/dev/sda1 xfs 5.0G 222M 4.8G 5% /boot
tmpfs tmpfs 389M 0 389M 0% /run/user/0
[root@localhost ~]#
关机添加磁盘,
开机查看磁盘信息
[root@localhost ~]# fdisk -l
Disk /dev/sda:120 GiB,128849018880 字节,251658240 个扇区
磁盘型号:VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x9a7d2330
设备 启动 起点 末尾 扇区 大小 Id 类型
/dev/sda1 * 2048 10487807 10485760 5G 83 Linux
/dev/sda2 10487808 31475711 20987904 10G 8e Linux LVM
Disk /dev/sdb:5 GiB,5368709120 字节,10485760 个扇区
磁盘型号:VMware Virtual S
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
Disk /dev/mapper/cs-root:10 GiB,10737418240 字节,20971520 个扇区
单元:扇区 / 1 * 512 = 512 字节
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@localhost ~]#
创建pv
[root@localhost ~]# pvcreate /dev/sdb
Physical volume "/dev/sdb" successfully created.
[root@localhost ~]#
[root@localhost ~]#
确认卷组
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cs 1 1 0 wz--n- 10.00g 4.00m
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name cs
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 10.00 GiB
PE Size 4.00 MiB
Total PE 2561
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 1 / 4.00 MiB
VG UUID Ca3Che-cvC9-54Jr-GzM3-AIex-xnfd-B5nZkA
[root@localhost ~]#
将pv扩容到vg
[root@localhost ~]# vgextend cs /dev/sdb #vgextend 卷组名称
Volume group "cs" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cs 2 1 0 wz--n- 15.00g 5.00g
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name cs
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 15.00 GiB
PE Size 4.00 MiB
Total PE 3840
Alloc PE / Size 2560 / 10.00 GiB
Free PE / Size 1280 / 5.00 GiB
VG UUID Ca3Che-cvC9-54Jr-GzM3-AIex-xnfd-B5nZkA
[root@localhost ~]#
查看磁盘容量
[root@localhost ~]# df -Th
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs tmpfs 777M 9.0M 768M 2% /run
/dev/mapper/cs-root xfs 10G 9.4G 628M 94% /
/dev/sda1 xfs 5.0G 222M 4.8G 5% /boot
tmpfs tmpfs 389M 0 389M 0% /run/user/0
查看lv详细信息
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cs -wi-ao---- 10.00g
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/cs/root
LV Name root
VG Name cs
LV UUID xbdeiT-PCxR-ss1w-RTkq-35Uu-gJtX-NQa4oy
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2024-06-05 15:35:41 +0800
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@localhost ~]# ls -lhrt /dev/mapper/cs-root
lrwxrwxrwx 1 root root 7 6月 5 16:04 /dev/mapper/cs-root -> ../dm-0
[root@localhost ~]# ls -lhrt /dev/cs/root
lrwxrwxrwx 1 root root 7 6月 5 16:04 /dev/cs/root -> ../dm-0
扩展逻辑分区使其100%生效
[root@localhost ~]# lvextend -l+100%FREE /dev/mapper/cs-root
Size of logical volume cs/root changed from 10.00 GiB (2560 extents) to 15.00 GiB (3840 extents).
Logical volume cs/root successfully resized.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cs -wi-ao---- 15.00g
使其扩展生效
[root@localhost ~]# xfs_growfs /dev/mapper/cs-root
meta-data=/dev/mapper/cs-root isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1 nrext64=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621440 to 3932160
验证结果:
[root@localhost ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
devtmpfs 4096 0 4096 0% /dev
tmpfs 1988396 0 1988396 0% /dev/shm
tmpfs 795360 9200 786160 2% /run
/dev/mapper/cs-root 15663104 9814436 5848668 63% /
/dev/sda1 5177344 226756 4950588 5% /boot
tmpfs 397676 0 397676 0% /run/user/0
[root@localhost ~]#