Linux系统之逻辑卷(lvm)创建及扩容
1.查看本机磁盘情况
[root@VM-4-13-centos soft]# fdisk -l 磁盘 /dev/vda:42.9 GB, 42949672960 字节,83886080 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x0009ac89 设备 Boot Start End Blocks Id System /dev/vda1 * 2048 83886046 41941999+ 83 Linux 磁盘 /dev/vdb:107.4 GB, 107374182400 字节,209715200 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节
如上所示,磁盘 /dev/vdb 未分区
2.对 /dev/vdb进行分区
2.1.将/dev/vdb 分一个主分区,执行 fdisk /dev/vdb
2.2.命令输入顺序: n p 回车 回车 t 8e w
[root@VM-4-13-centos soft]# fdisk /dev/vdb 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 Device does not contain a recognized partition table 使用磁盘标识符 0xdbdd859d 创建新的 DOS 磁盘标签。 命令(输入 m 获取帮助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p 分区号 (1-4,默认 1): 起始 扇区 (2048-209715199,默认为 2048): 将使用默认值 2048 Last 扇区, +扇区 or +size{K,M,G} (2048-209715199,默认为 209715199): 将使用默认值 209715199 分区 1 已设置为 Linux 类型,大小设为 100 GiB 命令(输入 m 获取帮助):t 已选择分区 1 Hex 代码(输入 L 列出所有代码):8e 已将分区“Linux”的类型更改为“Linux LVM” 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盘。
3.分完区后查看磁盘情况
[root@VM-4-13-centos soft]# fdisk -l 磁盘 /dev/vda:42.9 GB, 42949672960 字节,83886080 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x0009ac89 设备 Boot Start End Blocks Id System /dev/vda1 * 2048 83886046 41941999+ 83 Linux 磁盘 /dev/vdb:107.4 GB, 107374182400 字节,209715200 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0xdbdd859d 设备 Boot Start End Blocks Id System /dev/vdb1 2048 209715199 104856576 8e Linux LVM
4.创建物理卷
[root@VM-4-13-centos soft]# pvcreate /dev/vdb1 Physical volume "/dev/vdb1" successfully created.
5.查看物理卷信息
[root@VM-4-13-centos soft]# pvdisplay "/dev/vdb1" is a new physical volume of "<100.00 GiB" --- NEW Physical volume --- PV Name /dev/vdb1 VG Name PV Size <100.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID lADdMb-9Sy1-I1tC-9pyk-fTmp-hFkr-F8J1J1
6.创建逻辑卷组
[root@VM-4-13-centos soft]# vgcreate centos-mapper /dev/vdb1 Volume group "centos-mapper" successfully created
7.查看逻辑卷组
[root@VM-4-13-centos soft]# vgdisplay --- Volume group --- VG Name centos-mapper System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 1 Act PV 1 VG Size <100.00 GiB PE Size 4.00 MiB Total PE 25599 Alloc PE / Size 0 / 0 Free PE / Size 25599 / <100.00 GiB VG UUID 0yqlCa-Tilf-lwgd-ddXl-38sF-0YfE-Jfdf0c
8.创建逻辑卷
[root@VM-4-13-centos soft]# lvcreate -L 20G -n data centos-mapper Logical volume "data" created.
9.查看逻辑卷信息
[root@VM-4-13-centos soft]# lvdisplay --- Logical volume --- LV Path /dev/centos-mapper/data LV Name data VG Name centos-mapper LV UUID 3JrAdY-pUI0-y5x4-RCwd-qI4v-AySN-1kpbF3 LV Write Access read/write LV Creation host, time VM-4-13-centos, 2022-10-28 10:31:20 +0800 LV Status available # open 0 LV Size 20.00 GiB Current LE 5120 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 252:0
10.格式化逻辑卷
[root@VM-4-13-centos soft]# mkfs.xfs /dev/centos-mapper/data meta-data=/dev/centos-mapper/data isize=512 agcount=4, agsize=1310720 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=5242880, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
11.查看分区信息
[root@VM-4-13-centos soft]# blkid /dev/sr0: UUID="2022-09-27-09-14-19-00" LABEL="config-2" TYPE="iso9660" /dev/vda1: UUID="4b499d76-769a-40a0-93dc-4a31a59add28" TYPE="ext4" /dev/vdb1: UUID="lADdMb-9Sy1-I1tC-9pyk-fTmp-hFkr-F8J1J1" TYPE="LVM2_member" /dev/mapper/centos--mapper-data: UUID="693dc3dd-54ea-46e5-b822-5a53f2faaa59" TYPE="xfs"
12.挂载
12.1 创建挂载目录
mkdir /soft
12.2 编辑文件 /etc/fstab
vi /etc/fstab
# # /etc/fstab # Created by anaconda on Thu Mar 7 06:38:37 2019 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=4b499d76-769a-40a0-93dc-4a31a59add28 / ext4 defaults 1 1 /www/swap swap swap defaults 0 0 /dev/centos-mapper/data /soft xfs defaults
保存退出 :wq
12.3 挂载 /soft
[root@VM-4-13-centos soft]# mount /dev/centos-mapper/data /soft
13 逻辑卷的扩展
13.1 同一块盘还没用完,继续扩展
[root@VM-4-13-centos soft]# lvextend -L +2G /dev/centos-mapper/data Size of logical volume centos-mapper/data changed from 20.00 GiB (5120 extents) to 22.00 GiB (5632 extents). Logical volume centos-mapper/data successfully resized. [root@VM-4-13-centos soft]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 60.9M 0 rom vda 253:0 0 40G 0 disk └─vda1 253:1 0 40G 0 part / vdb 253:16 0 100G 0 disk └─vdb1 253:17 0 100G 0 part └─centos--mapper-data 252:0 0 22G 0 lvm /soft
13.2 扩充vbd2
# 创建物理卷 pvcreate /dev/vdb2 # 扩展逻辑卷组 vgextend centos-mapper /dev/vdb2 # 扩展逻辑卷 lvextend -L +2G /dev/centos-mapper/data xfs_growfs /dev/centos-mapper/data #刷新xfs文件系统容量 resize2fs /dev/centos-mapper/data #刷新ext4类型文件系统容量