LVM 技术是在硬盘分区和文件系统之间添加了一个逻辑层,它提供了一个抽象的卷组,可以把多块硬盘进行卷组合并。 这样一来,用户不必关心物理硬盘设备的底层架构和布局,就可以实现对硬盘分区的动态调整。
常用的 LVM 部署命令
功能/命令 | 物理卷管理 | 卷组管理 | 逻辑卷管理 |
扫描 | pvscan | vgscan | lvscan |
建立 | pvcreate | vgcreate | lvcreate |
显示 | pvdisplay | vgdisplay | lvdisplay |
删除 | pvremove | vgremove | lvremove |
扩展 | vgextend | lvextend | |
缩小 | vgreduce | lvreduce |
实验:
部署逻辑卷
1、添加两个硬盘
2、让新添加的两块硬盘设备支持 LVM 技术
查看硬盘名字
创建物理卷
[root@hfj ~]# pvcreate /dev/nvme0n2 /dev/nvme0n3 Physical volume "/dev/nvme0n2" successfully created. Physical volume "/dev/nvme0n3" successfully created.
3、把两块硬盘设备加入到 storage 卷组中,然后查看卷组的状态
[root@hfj ~]# vgcreate storage /dev/nvme0n2 /dev/nvme0n3 Volume group "storage" successfully created
4、切割出一个约为15G的逻辑卷设备
[root@hfj ~]# lvcreate -n vo -L 15G storage Logical volume "vo" created.
5、把生成好的逻辑卷进行格式化,然后挂载使用
[root@hfj /]# mkfs.ext4 /dev/storage/vo mke2fs 1.45.4 (23-Sep-2019) Creating filesystem with 3932160 4k blocks and 983040 inodes Filesystem UUID: a5d9197a-f89c-4315-b432-8f65416b8fb9 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@hfj /]# mount /dev/storage/vo /mailbox
6、查看挂载状态,并写入配置文件,使其永久生效
写入配置文件fstab:
[root@hfj /]# echo "/dev/storage/vo /mailbox ext4 defaults 0 0" >>/etc/fstab
查看fstab:
扩容逻辑卷
1、卸载设备和挂载点的关联
[root@hfj /]# umount /mailbox
2、把上一个实验中的逻辑卷 vo 扩展至 17G
[root@hfj /]# lvextend -L 17G /dev/storage/vo Size of logical volume storage/vo changed from 15.00 GiB (3840 extents) to 17.00 GiB (4352 extents). Logical volume storage/vo successfully resized.
3、检查硬盘的完整性,确认目录结构、内容和文件内容没有丢失。一般情况下没 有报错,均为正常情况
[root@hfj /]# e2fsck -f /dev/storage/vo e2fsck 1.45.4 (23-Sep-2019) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/storage/vo: 11/983040 files (0.0% non-contiguous), 88340/3932160 blocks
4、重置设备在系统中的容量
[root@hfj /]# resize2fs /dev/storage/vo resize2fs 1.45.4 (23-Sep-2019) Filesystem at /dev/storage/vo is mounted on /mailbox; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 3 The filesystem on /dev/storage/vo is now 4456448 (4k) blocks long.
5、重新挂载硬盘设备并查看挂载状态