简单易懂讲解LVM
1、LVM是什么?
LVM是管理磁盘的一种方式,特点是灵活调整大小,方便空间扩容
2、LVM整个流程
物理硬盘变成–物理卷PV–加入卷组VG–制作逻辑卷LV–格式化–挂载
3、查看现有的物理卷
通过使用pvdisplay命令查看物理卷,这里有两个物理卷,分别是/dev/sda2和/dev/sdc,这里的PE Size是一个存储单元4MiB,Total PE为共计有4994个存储单元,PV的大小为4X4994/1024=19.51GiB
[root@linuxprobe ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID IqpyhR-Gk1a-Hew8-aaY3-xCtQ-Guus-PS4D6L
"/dev/sdc" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 8ixdTd-I0Rn-47b1-Spkm-wqMe-iFnb-7KiIW9
4、查看现有卷组
通过vgdisplay命令查看卷组,这里的卷组名为rhel
[root@linuxprobe ~]# vgdisplay
--- Volume group ---
VG Name rhel
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 19.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID oSiZYq-GjEe-AyTH-YfUm-xq94-yIDA-5LG9k3
5、查看逻辑卷
通过使用lvdisplay命令查看逻辑卷,这里有两个逻辑卷,分别为swap和root
[root@linuxprobe ~]# lvdisplay
--- Logical volume ---
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID FnYPjs-huSu-xmCo-c8p4-WoYV-lsm2-IdVsYC
LV Write Access read/write
LV Creation host, time localhost, 2024-12-07 18:28:11 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1
--- Logical volume ---
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID Pzio3Z-wBmP-Q19D-Z9iU-eCZK-5VrK-PiLrIO
LV Write Access read/write
LV Creation host, time localhost, 2024-12-07 18:28:11 +0800
LV Status available
# open 1
LV Size 17.51 GiB
Current LE 4482
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0
[root@linuxprobe ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─rhel-root 253:0 0 17.5G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
6、扩展逻辑卷
首先确保物理服务器上有足够的空间或者添加新的硬盘
- lsblk查看目前根的大小
- lvextend -L +5g /dev/rhel/root
- lsblk再次查看空间多了5G,并且是跨越两块磁盘空间,同时vgdisplay查看,rhel卷组可用空间少了5G,但是使用df-h查看还是原来的空间,这里需要注意一下,调整完成逻辑卷大小后,需要对文件系统调整大小进行匹配,使用命令xfs_growfs /dev/rhel/root,如果使用的是ext4则将xfs_growfs换成resize2fs
[root@linuxprobe ~]# pvcreate /dev/sdc
Physical volume "/dev/sdc" successfully created
[root@linuxprobe ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID IqpyhR-Gk1a-Hew8-aaY3-xCtQ-Guus-PS4D6L
"/dev/sdc" is a new physical volume of "5.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sdc
VG Name
PV Size 5.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 8ixdTd-I0Rn-47b1-Spkm-wqMe-iFnb-7KiIW9
[root@linuxprobe ~]# vgextend rhel /dev/sdc
Volume group "rhel" successfully extended
[root@linuxprobe ~]# vgdisplay
--- Volume group ---
VG Name rhel
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 24.50 GiB
PE Size 4.00 MiB
Total PE 6273
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 1279 / 5.00 GiB
VG UUID oSiZYq-GjEe-AyTH-YfUm-xq94-yIDA-5LG9k3
[root@linuxprobe ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─rhel-root 253:0 0 17.5G 0 lvm /
└─rhel-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 2G 0 part /newFS
└─sdb2 8:18 0 3G 0 part [SWAP]
sdc 8:32 0 5G 0 disk
sr0 11:0 1 3.5G 0 rom /media/cdrom
[root@linuxprobe ~]# lvextend -L +5g /dev/rhel/root
Extending logical volume root to 22.51 GiB
Insufficient free space: 1280 extents needed, but only 1279 available
[root@linuxprobe ~]# xfs_growfs /dev/rhel/root
7、创建逻辑卷过程详解
- 首先使用lsblk查看新的硬盘
- 创建新的物理卷pvcreate /dev/sdx,使用pvdisplay查看物理卷
- 创建卷组vgcreate jzyue /dev/sdx,使用vgdisplay查看卷组
- 创建逻辑卷lvcreate -L 大小 -n 逻辑卷名字 卷组名字,使用lvdisplay查看
- 逻辑卷格式化mkfs.xfs /dev/jzyue/lj01
- 挂载逻辑卷:创建挂载点逻辑01命令mkdir /mnt/lj01 临时挂载mount /dev/jzyue/lj01 /mnt/lj01
- 卸载逻辑卷umount /mnt/lj01
- 删除卷组vgremove jzyue
- 移除物理卷pvremove /dev/sdx
原文地址:https://blog.csdn.net/m0_46180357/article/details/144321159
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!