2T以上硬盘进行lvm管理
一 、将2t硬盘分区为lvm
root@localhost ~]# parted /dev/sdb
(parted) mklabel gpt # 将MBR磁盘格式化为GPT
(parted) mkpart primary 0 -1 #将整块磁盘划分为一个分区
警告: The resulting partition is not properly
aligned for best performance.
忽略/Ignore/放弃/Cancel? I #忽略警告
(parted) p #打印当前分区
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sdb: 2199GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 标志
1 17.4kB 2199GB 2199GB primary
(parted) quit #退出
信息: You may need to update /etc/fstab.
使用lsblk查看磁盘分区情况:
1 1024M 0 rom
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 2G 0 part [SWAP]
└─sda3 8:3 0 47G 0 part /
sdb 8:16 0 2T 0 disk
└─sdb1 8:17 0 2T 0 part
2 将磁盘转化为逻辑卷
pvcreate /dev/sdb1 // 创建的一个分区/dev/sdb1 转化成物理卷,主要是添加LVM属性信息并划分PE存储单元后面磁盘目录可以跟多个
3 查看
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sda2 cl lvm2 a-- <15.00g 0
/dev/sdb1 lvm2 a-- <4.00t 0
4 创建卷组
vgcreate vgdata /dev/sdb1 //创建卷组,名称为vgdata我理解为创建一个大的存储池,后面基于这个存储池划分
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vgdata
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 0
Max PV 0
Cur PV 1
Act PV 1
VG Size <4.00 TiB
PE Size 4.00 MiB
Total PE 1048575
Alloc PE / Size 1022362 / 3.90 TiB
Free PE / Size 26213 / 102.39 GiB
VG UUID oMuOTd-zAxm-cfi9-cRsM-ZxZf-PQYe-LGn27Y
5 从物理卷vgdata上面分割3.9T给新的逻辑卷lvdata1
lvcreate -L 3.9T -n lvdata1 vgdata
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 13.39g
swap cl -wi-ao---- 1.60g
lvdata1 vgdata -wi-a----- 3.90t
[root@localhost ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vgdata/lvdata1
LV Name lvdata1
VG Name vgdata
LV UUID Z9X2d3-TGza-26XV-6w3O-dJq2-TLFq-iUcNkw
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2021-02-17 21:51:14 -0500
LV Status available
# open 0
LV Size 3.90 TiB
Current LE 1022362
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
6 使用mkfs.ext4命令在逻辑卷lvdata1上创建ext4文件系统
[root@localhost ~]# mkfs.ext4 /dev/vgdata/lvdat
7 挂载
mount /dev/vgdata/lvdata1 mm
8 设置自动挂载
设置自动挂载
[root@localhost mm]# blkid //查看分区uuid
/dev/mapper/vgdata-lvdata1: UUID="eef0bdbc-7bac-418d-ab8c-b3fccc9379a2" TYPE=“ext4”
[root@localhost ~]# vim /etc/fstab. //修改挂载配置文件
#
# /etc/fstab
# Created by anaconda on Mon Dec 28 03:15:19 2020
#
# 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
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=eef0bdbc-7bac-418d-ab8c-b3fccc9379a2 /root/mm ext4 defaults 1 2
Reboot 重启
[root@localhost ~]# df -h
/dev/mapper/vgdata-lvdata1 3.9T 89M 3.7T 1% /root/mm
二、逻辑卷lvdata1不够用了,如何扩展。
1 查看vgdata空间
[root@localhost ~]# vgdisplay. //查看vgdata卷,发现free pe /size剩余100g的空间
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
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 <4.00 TiB
PE Size 4.00 MiB
Total PE 1048575
Alloc PE / Size 1022618 / 3.90 TiB
Free PE / Size 25957 / 101.39 GiB
VG UUID oMuOTd-zAxm-cfi9-cRsM-ZxZf-PQYe-LGn27Y
2 将vgdata空间给lvdata1
给逻辑卷增加空间并不会影响以前空间的使用,所以无需卸载文件系统
lvextend -L +100G /dev/vgdata/lvdata1 // 将100G的空间划分给/lvdata1
resize2fs /dev/vgdata/lvdata1 //将空间同步
同步前
/dev/mapper/vgdata-lvdata1 3.9T 89M 3.7T 1% /root/mm
同步后
/dev/mapper/vgdata-lvdata1 4.0T 87M 3.8T 1% /root/mm
tmpfs 184M 0 184M 0% /run/user/0
三、当卷组不够用的情况下,如何扩大卷组
扩容之前卷组查看
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
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 <4.00 TiB
PE Size 4.00 MiB
Total PE 1048575
Alloc PE / Size 1048218 / <4.00 TiB
Free PE / Size 357 / 1.39 GiB
VG UUID oMuOTd-zAxm-cfi9-cRsM-ZxZf-PQYe-LGn27Y
开始扩容,此处省略添加磁盘操作
vgextend vgdata /dev/sdc1
扩容之后卷组查看
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name vgdata
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 2
Act PV 2
VG Size <8.00 TiB
PE Size 4.00 MiB
Total PE 2097150
Alloc PE / Size 1048218 / <4.00 TiB
Free PE / Size 1048932 / 4.00 TiB
VG UUID oMuOTd-zAxm-cfi9-cRsM-ZxZf-PQYe-LGn27Y
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb1 vgdata lvm2 a-- <4.00t 1.39g
/dev/sdc1 vgdata lvm2 a-- <4.00t <4.00t
[root@localhost ~]#
参考资料:https://blog.51cto.com/dreamfire/1084729