【云计算】CentOS7.9. LVM扩容实战小记
文章目录
- 1、查看磁盘分区
- 2、查看磁盘分区挂载信息
- 3、创建磁盘分区,并查看分区信息
- 4、依次查看LV、PV、VG信息
- 5、将新建分区加入pv
- 6、将pv加入vg
- 7、将vg卷组中的lv的资源池,给lv设备扩容,并扩容文件系统
【云计算】CentOS7.9. LVM扩容实战小记
1、查看磁盘分区
[root@computer ~]# fdisk -l
磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009a480
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 9766911 4882432 83 Linux
/dev/sda2 9766912 68372479 29302784 8e Linux LVM
磁盘 /dev/sdb:214.7 GB, 214748364800 字节,419430400 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-root:30.0 GB, 30001856512 字节,58597376 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
2、查看磁盘分区挂载信息
[root@computer ~]# df -TH
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 13M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 30G 1.4G 29G 5% /
/dev/sda1 xfs 5.0G 158M 4.9G 4% /boot
tmpfs tmpfs 809M 0 809M 0% /run/user/0
3、创建磁盘分区,并查看分区信息
[root@computer ~]# cat /proc/partitions
major minor #blocks name
8 0 125829120 sda
8 1 4882432 sda1
8 2 29302784 sda2
8 16 209715200 sdb
11 0 996352 sr0
253 0 29298688 dm-0
[root@computer ~]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):p
磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009a480
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 9766911 4882432 83 Linux
/dev/sda2 9766912 68372479 29302784 8e Linux LVM
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (68372480-251658239,默认为 68372480):
将使用默认值 68372480
Last 扇区, +扇区 or +size{K,M,G} (68372480-251658239,默认为 251658239):
将使用默认值 251658239
分区 3 已设置为 Linux 类型,大小设为 87.4 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sda:128.8 GB, 128849018880 字节,251658240 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x0009a480
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 9766911 4882432 83 Linux
/dev/sda2 9766912 68372479 29302784 8e Linux LVM
/dev/sda3 68372480 251658239 91642880 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘。
[root@computer ~]# cat /proc/partitions
major minor #blocks name
8 0 125829120 sda
8 1 4882432 sda1
8 2 29302784 sda2
8 16 209715200 sdb
11 0 996352 sr0
253 0 29298688 dm-0
[root@computer ~]# partprobe
Warning: 无法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。
[root@computer ~]# !ca
cat /proc/partitions
major minor #blocks name
8 0 125829120 sda
8 1 4882432 sda1
8 2 29302784 sda2
8 3 91642880 sda3
8 16 209715200 sdb
11 0 996352 sr0
253 0 29298688 dm-0
4、依次查看LV、PV、VG信息
[root@computer ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 27.94g 0
[root@computer ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root centos -wi-ao---- 27.94g
[root@computer ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 1 1 0 wz--n- 27.94g 0
[root@computer ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <27.95 GiB / not usable 4.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 7153
Free PE 0
Allocated PE 7153
PV UUID 2QmweY-rAYS-Wa0N-brMa-rgKo-jwVe-LzWwTR
[root@computer ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID nbMfrZ-Aark-FIDP-AhYq-uayo-lYMq-HU9dWl
LV Write Access read/write
LV Creation host, time localhost, 2024-11-22 16:37:17 +0800
LV Status available
# open 1
LV Size 27.94 GiB
Current LE 7153
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@computer ~]# vgdisplay
--- Volume group ---
VG Name centos
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 27.94 GiB
PE Size 4.00 MiB
Total PE 7153
Alloc PE / Size 7153 / 27.94 GiB
Free PE / Size 0 / 0
VG UUID TE2122-yAAf-KX02-TfSk-107H-uF2r-YTYvpP
5、将新建分区加入pv
[root@computer ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
[root@computer ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 centos lvm2 a-- 27.94g 0
/dev/sda3 lvm2 --- <87.40g <87.40g
6、将pv加入vg
[root@computer ~]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@computer ~]# vgs
VG #PV #LV #SN Attr VSize VFree
centos 2 1 0 wz--n- <115.34g 87.39
7、将vg卷组中的lv的资源池,给lv设备扩容,并扩容文件系统
[root@computer ~]# lvdisplay
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID nbMfrZ-Aark-FIDP-AhYq-uayo-lYMq-HU9dWl
LV Write Access read/write
LV Creation host, time localhost, 2024-11-22 16:37:17 +0800
LV Status available
# open 1
LV Size 27.94 GiB
Current LE 7153
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@computer ~]# lvextend -l 100%FREE /dev/centos/root
Size of logical volume centos/root changed from 27.94 GiB (7153 extents) to 87.39 GiB (22373 extents).
Logical volume centos/root successfully resized.
[root@computer ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1831168 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=7324672, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=3576, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 7324672 to 22909952
[root@computer ~]# df -TH
文件系统 类型 容量 已用 可用 已用% 挂载点
devtmpfs devtmpfs 4.1G 0 4.1G 0% /dev
tmpfs tmpfs 4.1G 0 4.1G 0% /dev/shm
tmpfs tmpfs 4.1G 13M 4.1G 1% /run
tmpfs tmpfs 4.1G 0 4.1G 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 94G 1.4G 93G 2% /
/dev/sda1 xfs 5.0G 158M 4.9G 4% /boot
tmpfs tmpfs 809M 0 809M 0% /run/user/0