大家好,欢迎来到IT知识分享网。
逻辑卷LVM
是一种将一个或多个硬盘的分区在逻辑上集合,当成一个大硬盘来使用,当硬盘的空间不足时,可以将其他一盘的分区加入其中,实现动态扩容,对磁盘空间进行动态管理
PV 物理卷(linux系统中的分区通过命令转换而成)
VG 卷组,建立在PV上,可以划分多个PV (多个磁盘分区组合在一起)
LV 逻辑卷,建立在VG之上,是一个动态改变大小的分区 (分区)
PE 物理区域,PE的大小为4MB,如同block的作用,是LVM最小的寻址单位
LVM扩容原理
通过交换PE的方式,达到弹性变更文件系统大小
将PE添加的LV逻辑卷,就可以扩容LV容量
剔除原有的PE,LV逻辑卷的容量会变小
默认PE大小是4M,LVM最多有65534个PE,所以LVM最大的VG是256G单位
LVM逻辑卷的创建流程(示例)
1准备磁盘
2将磁盘PV化
3创建卷组vg
4创建逻辑卷lv
5格式化lv文件系统
6挂载使用
1 安装lvm工具
[root@localhost ~]# yum install lvm2 -y
2 创建物理卷(将磁盘pv化)
pvcreate 设备名
查看物理逻辑卷三种命令
pvs
pvscan
pvdisply
pvremove 设备名 将设备从物理逻辑卷中移除(删除磁盘的pv化)
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 800M 0 part [SWAP]
└─sda3 8:3 0 19G 0 part /
sdb 8:16 0 30G 0 disk
sdc 8:32 0 30G 0 disk
sr0 11:0 1 4.3G 0 rom
[root@localhost ~]# pvcreate /dev/sdb /dev/sdc 用磁盘创建物理逻辑卷
Physical volume "/dev/sdb" successfully created.
Physical volume "/dev/sdc" successfully created.
查看
[root@localhost ~]# pvs 查看物理逻辑卷
PV VG Fmt Attr PSize PFree
/dev/sdb lvm2 --- 30.00g 30.00g
/dev/sdc lvm2 --- 30.00g 30.00g
3创建卷组VG
vgcreate 卷组名 pv化的磁盘
三种命令查看卷组
vgs
vgscan
vgdisplay
vgremove 卷组名 删除卷组
[root@localhost ~]# vgcreate vg0224 /dev/sdb /dev/sdc 将sdb与sdc融合一起建立卷组
Volume group "vg0224" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0224 2 0 0 wz--n- 59.99g 59.99g
4创建lv逻辑卷(分区)
lvcrate -n 创建的lv逻辑卷名 -l 逻辑卷容量 vg卷组名
-L 直接指定容量 vg卷组名
查看逻辑卷
lvs
lvscan
lvdisply
lvremove 逻辑卷名,绝对路径 #删除逻辑卷
[root@localhost ~]# lvcreate -n 0224-lv1 -L 10G vg0224
Logical volume "0224-lv1" created.
[root@localhost ~]# lvcreate -n 0224-lv2 -L 15G vg0224
Logical volume "0224-lv2" created.
[root@localhost ~]# lvcreate -n 0224-lv3 -L 25G vg0224
Logical volume "0224-lv3" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
0224-lv1 vg0224 -wi-a----- 10.00g
0224-lv2 vg0224 -wi-a----- 15.00g
0224-lv3 vg0224 -wi-a----- 25.00g
5挂载
[root@localhost ~]# mkdir /test{1..3}
[root@localhost ~]# ls /dev/vg0224/
0224-lv1 0224-lv2 0224-lv3
[root@localhost ~]# mount /dev/vg0224/0224-lv1 /test1
mount: /dev/mapper/vg0224-0224--lv1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@localhost ~]# mount /dev/vg0224/0224-lv2 /test2
mount: /dev/mapper/vg0224-0224--lv2 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@localhost ~]# mount /dev/vg0224/0224-lv3 /test3
mount: /dev/mapper/vg0224-0224--lv3 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
永久挂载生效
[root@localhost ~]# vim /etc/fstab
[root@localhost ~]# tail -3 /etc/fstab
UUID=fc9557ea-daed-4688-809a-1954b5a9416f /test1 xfs defaults 0 0
UUID=bd533fe2-53ba-437f-9a06-6c213d915477 /test2 xfs defaults 0 0
UUID=401a803c-12fc-4aec-af14-16ca2a0826cd /test3 ext4 defaults 0 0
6格式化文件系统
[root@localhost ~]# mkfs.xfs /test1
mkfs.xfs: cannot open /test1: Is a directory
[root@localhost ~]# mkfs.xfs /dev/vg0224/0224-lv1
meta-data=/dev/vg0224/0224-lv1 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, 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
[root@localhost ~]# mkfs.xfs /dev/vg0224/0224-lv2
meta-data=/dev/vg0224/0224-lv2 isize=512 agcount=4, agsize=983040 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=3932160, 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
[root@localhost ~]# mkfs.ext4 /dev/vg0224/0224-lv3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1638400 inodes, 6553600 blocks
327680 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
200 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
查看文件系统信息
xfs类型文件系统 xfs_info命令 挂载点或逻辑卷路径
ext4类型文件系统 dumpe2fs命令 逻辑卷路径
查看文件系统信息
[root@localhost ~]# xfs_info /test1
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1246656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4986624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# xfs_info /test2
meta-data=/dev/sda3 isize=512 agcount=4, agsize=1246656 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4986624, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# dumpe2fs /dev/vg0224/0224-lv3 |grep -Ei "^inode|^block"
dumpe2fs 1.42.9 (28-Dec-2013)
Inode count: 1638400
Block count: 6553600
Block size: 4096
Blocks per group: 32768
Inodes per group: 8192
Inode blocks per group: 512
Inode size: 256
[root@localhost ~]#
逻辑卷扩容
1查看卷组VG容量,确认容量是否支持逻辑卷扩容
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0224 2 3 0 wz--n- 59.99g 9.99g
情况1 VG卷组容量不够
1添加新的磁盘加入卷组
1关机添加新硬盘
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 800M 0 part [SWAP]
└─sda3 8:3 0 19G 0 part /
sdb 8:16 0 30G 0 disk
├─vg0224-0224--lv1 253:0 0 10G 0 lvm /test1
└─vg0224-0224--lv2 253:1 0 15G 0 lvm /test2
sdc 8:32 0 30G 0 disk
└─vg0224-0224--lv3 253:2 0 25G 0 lvm /test3
sdd 8:48 0 80G 0 disk
sr0 11:0 1 4.3G 0 rom
2 将新添加的硬盘pv化
[root@localhost ~]# pvcreate /dev/sdd
Physical volume "/dev/sdd" successfully created.
[root@localhost ~]#
[root@localhost ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/sdb vg0224 lvm2 a-- <30.00g <5.00g
/dev/sdc vg0224 lvm2 a-- <30.00g <5.00g
/dev/sdd lvm2 --- 80.00g 80.00g
[root@localhost ~]#
3将pv化的磁盘加入卷组
vgextend 卷组名 磁盘名 将pv化的磁盘加入卷组
[root@localhost ~]# vgextend vg0224 /dev/sdd
Volume group "vg0224" successfully extended
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg0224 3 3 0 wz--n- <139.99g <89.99g
[root@localhost ~]#
4扩容逻辑卷
逻辑卷扩容命令
lvextend -L +容量 扩容逻辑卷路径
+号可不写
写+号代表增加多少容量
不写+号,直接指定逻辑卷容量
[root@localhost ~]# lvs 扩容前
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
0224-lv1 vg0224 -wi-ao---- 10.00g
0224-lv2 vg0224 -wi-ao---- 15.00g
0224-lv3 vg0224 -wi-ao---- 25.00g
[root@localhost ~]# lvextend -L 30G /dev/vg0224/0224-lv1 扩容,给逻辑卷lv1 30G容量
Size of logical volume vg0224/0224-lv1 changed from 10.00 GiB (2560 extents) to 30.00 GiB (7680 extents).
Logical volume vg0224/0224-lv1 successfully resized.
[root@localhost ~]# lvextend -L 30G /dev/vg0224/0224-lv3 给lv3 逻辑卷扩容到30G
Size of logical volume vg0224/0224-lv3 changed from 25.00 GiB (6400 extents) to 30.00 GiB (7680 extents).
Logical volume vg0224/0224-lv3 successfully resized.
[root@localhost ~]#
扩容后,系统是还没有识别的,需要用命令重读文件系统
xfs文件系统类型使用命令 xfs_growfs 扩容逻辑卷的路径
ext4文件系统类型使用命令 resize2fs 扩容逻辑卷的路径
[root@localhost ~]# xfs_growfs /dev/vg0224/0224-lv1
meta-data=/dev/mapper/vg0224-0224--lv1 isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 2621440 to 7864320
[root@localhost ~]# resize2fs /dev/vg0224/0224-lv3
resize2fs 1.42.9 (28-Dec-2013)
Filesystem at /dev/vg0224/0224-lv3 is mounted on /test3; on-line resizing required
old_desc_blocks = 4, new_desc_blocks = 4
The filesystem on /dev/vg0224/0224-lv3 is now 7864320 blocks long.
[root@localhost ~]# lvs 扩容后
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
0224-lv1 vg0224 -wi-ao---- 30.00g
0224-lv2 vg0224 -wi-ao---- 15.00g
0224-lv3 vg0224 -wi-ao---- 30.00g
[root@localhost ~]#
情况2卷组的容量足够
直接使用lvextend命令给逻辑卷扩容即可
移除逻辑卷,还原磁盘
1 将/etc/fstab配置文件中设定的挂载配置删除
2 取消挂载
3 移除lv逻辑卷
lvremove lv逻辑卷路径
4 删除vg卷组
vgremove vg卷组名
5 移除pv逻辑卷
pvremove 设备名
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/29957.html