1.安装包
yum -y install lvm2
2.创建卷组
# 1. 查看所有的vdb盘
[root@stream9 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 10G 0 disk
├─vdb1 253:17 0 2G 0 part
├─vdb2 253:18 0 3G 0 part
└─vdb3 253:19 0 5G 0 part
[root@stream9 ~]#
# 2. 创建卷组 vg => volume group vg1
[root@stream9 ~]# vgcreate vg1 /dev/vdb[2-3]
Physical volume "/dev/vdb2" successfully created.
Physical volume "/dev/vdb3" successfully created.
Creating devices file /etc/lvm/devices/system.devices
Volume group "vg1" successfully created
[root@stream9 ~]#
# 3. 查看卷组
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 0 0 wz--n- 7.99g 7.99g
[root@stream9 ~]#
# 4. 根据卷组 创建 逻辑卷 lv1 => logical volume
[root@stream9 ~]# lvcreate -L 4G -n lv1 vg1
Logical volume "lv1" created.
[root@stream9 ~]#
# 再次查看卷组
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 7.99g 3.99g
[root@stream9 ~]#
# 5. 查看逻辑卷
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 4.00g
[root@stream9 ~]#
[root@stream9 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 10G 0 disk
├─vdb1 253:17 0 2G 0 part
├─vdb2 253:18 0 3G 0 part
└─vdb3 253:19 0 5G 0 part
└─vg1-lv1 252:0 0 4G 0 lvm
[root@stream9 ~]# blkid
/dev/vda1: UUID="c3506e82-5c52-4fd1-aeeb-df31262e5dfd" TYPE="xfs" PARTUUID="c409ea87-01"
/dev/vdb2: UUID="3dk087-NPav-68qn-6w2A-SViD-bPuY-DBoq3t" TYPE="LVM2_member" PARTUUID="dd73c5e9-02"
/dev/vdb3: UUID="U0pcXJ-mKhE-9CdD-r83b-uMf2-3L3s-jeS0vV" TYPE="LVM2_member" PARTUUID="dd73c5e9-03"
/dev/vdb1: PARTUUID="dd73c5e9-01"
# 6. 格式化逻辑卷挂载
[root@stream9 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 10G 0 disk
├─vdb1 253:17 0 2G 0 part
├─vdb2 253:18 0 3G 0 part
└─vdb3 253:19 0 5G 0 part
└─vg1-lv1 252:0 0 4G 0 lvm
[root@stream9 ~]#
[root@stream9 ~]# mkfs.ext4 /dev/vg1/lv1
mke2fs 1.46.5 (30-Dec-2021)
Discarding device blocks: done
Creating filesystem with 1048576 4k blocks and 262144 inodes
Filesystem UUID: 61bcc5ac-94c6-4772-8f34-535f2f99ca68
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@stream9 ~]# blkid
/dev/vda1: UUID="c3506e82-5c52-4fd1-aeeb-df31262e5dfd" TYPE="xfs" PARTUUID="c409ea87-01"
/dev/vdb2: UUID="3dk087-NPav-68qn-6w2A-SViD-bPuY-DBoq3t" TYPE="LVM2_member" PARTUUID="dd73c5e9-02"
/dev/vdb3: UUID="U0pcXJ-mKhE-9CdD-r83b-uMf2-3L3s-jeS0vV" TYPE="LVM2_member" PARTUUID="dd73c5e9-03"
/dev/vdb1: PARTUUID="dd73c5e9-01"
/dev/mapper/vg1-lv1: UUID="61bcc5ac-94c6-4772-8f34-535f2f99ca68" TYPE="ext4"
[root@stream9 ~]#
[root@stream9 ~]# mkdir /mnt/test1
[root@stream9 ~]# mount /dev/vg1/lv1 /mnt/test1
[root@stream9 ~]#
[root@stream9 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 889M 0 889M 0% /dev/shm
tmpfs 356M 464K 356M 1% /run
/dev/vda1 20G 2.8G 18G 14% /
tmpfs 178M 4.0K 178M 1% /run/user/0
/dev/mapper/vg1-lv1 3.9G 24K 3.7G 1% /mnt/test1
# 7. 扩容逻辑卷
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 4.00g
[root@stream9 ~]#
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 7.99g 3.99g
[root@stream9 ~]#
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 4.00g
[root@stream9 ~]#
[root@stream9 ~]# lvextend -L 6G /dev/vg1/lv1
Size of logical volume vg1/lv1 changed from 4.00 GiB (1024 extents) to 6.00 GiB (1536 extents).
Logical volume vg1/lv1 successfully resized.
[root@stream9 ~]#
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 7.99g 1.99g
[root@stream9 ~]#
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 6.00g
[root@stream9 ~]#
[root@stream9 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 889M 0 889M 0% /dev/shm
tmpfs 356M 464K 356M 1% /run
/dev/vda1 20G 2.8G 18G 14% /
tmpfs 178M 4.0K 178M 1% /run/user/0
/dev/mapper/vg1-lv1 3.9G 24K 3.7G 1% /mnt/test1
[root@stream9 ~]#
# 刷新xfs文件系统: xfs_growfs
# 刷新ext4文件系统: resize2fs
[root@stream9 ~]# resize2fs /dev/vg1/lv1
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/vg1/lv1 is mounted on /mnt/test1; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/vg1/lv1 is now 1572864 (4k) blocks long.
[root@stream9 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 889M 0 889M 0% /dev/shm
tmpfs 356M 464K 356M 1% /run
/dev/vda1 20G 2.8G 18G 14% /
tmpfs 178M 4.0K 178M 1% /run/user/0
/dev/mapper/vg1-lv1 5.9G 24K 5.6G 1% /mnt/test1
[root@stream9 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 10G 0 disk
├─vdb1 253:17 0 2G 0 part
├─vdb2 253:18 0 3G 0 part
│ └─vg1-lv1 252:0 0 6G 0 lvm /mnt/test1
└─vdb3 253:19 0 5G 0 part
└─vg1-lv1 252:0 0 6G 0 lvm /mnt/test1
# 8. 扩容卷组 vg
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 2 1 0 wz--n- 7.99g 1.99g
[root@stream9 ~]#
[root@stream9 ~]# vgextend vg1 /dev/vdb1
Physical volume "/dev/vdb1" successfully created.
Volume group "vg1" successfully extended
[root@stream9 ~]#
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 1 0 wz--n- <9.99g <3.99g
# 9. 查看
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-ao---- 6.00g
[root@stream9 ~]#
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 1 0 wz--n- <9.99g <3.99g
[root@stream9 ~]#
[root@stream9 ~]# pvs # physical volume
PV VG Fmt Attr PSize PFree
/dev/vdb1 vg1 lvm2 a-- <2.00g <2.00g
/dev/vdb2 vg1 lvm2 a-- <3.00g 1.99g
/dev/vdb3 vg1 lvm2 a-- <5.00g 0
# 10. 删除逻辑卷和卷组
[root@stream9 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs 889M 0 889M 0% /dev/shm
tmpfs 356M 464K 356M 1% /run
/dev/vda1 20G 2.8G 18G 14% /
tmpfs 178M 4.0K 178M 1% /run/user/0
/dev/mapper/vg1-lv1 5.9G 24K 5.6G 1% /mnt/test1
[root@stream9 ~]#
[root@stream9 ~]# umount /mnt/test1
[root@stream9 ~]#
[root@stream9 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv1 vg1 -wi-a----- 6.00g
[root@stream9 ~]#
[root@stream9 ~]# lvremove /dev/vg1/lv1
Do you really want to remove active logical volume vg1/lv1? [y/n]: y
Logical volume "lv1" successfully removed.
[root@stream9 ~]#
[root@stream9 ~]# lvs
[root@stream9 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 253:0 0 20G 0 disk
└─vda1 253:1 0 20G 0 part /
vdb 253:16 0 10G 0 disk
├─vdb1 253:17 0 2G 0 part
├─vdb2 253:18 0 3G 0 part
└─vdb3 253:19 0 5G 0 part
[root@stream9 ~]#
[root@stream9 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg1 3 0 0 wz--n- <9.99g <9.99g
[root@stream9 ~]# vgremove vg1
Volume group "vg1" successfully removed
[root@stream9 ~]# vgs
[root@stream9 ~]#
[root@stream9 ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 lvm2 --- 2.00g 2.00g
/dev/vdb2 lvm2 --- 3.00g 3.00g
/dev/vdb3 lvm2 --- <5.00g <5.00g
标签:逻辑,lv1,19,dev,LVM,253,root,vg1,stream9
From: https://www.cnblogs.com/ckh2023/p/17771008.html