Linux LVM管理 【内部操作手册】

LVM 管理手册

创建PV
pvcreate /dev/sdb1
pvcreate /dev/sdc1
pvcreate /dev/sdd1
pvcreate /dev/sde1

创建VG
vgcreate mygrp /dev/sdb1 /dev/sdd1

创建LV
lvcreate -L 350G -n disk1 mygrp

格式化分区
mkfs.xfs /dev/mygrp/disk1
mount -t xfs /dev/mygrp/disk1 /mnt/disk1/

新增硬盘到VG卷
vgextend mygrp /dev/sdc1
使用vgdisplay 可以查看到新增的分区

LV分区 新增空间
lvextend -L +10G /dev/mygrp/disk1
让它生效
xfs_growfs /dev/mygrp/disk1
会显示
meta-data=/dev/mapper/mygrp-disk1 isize=256 agcount=4, agsize=22937600 blks
= sectsz=512 attr=2
data = bsize=4096 blocks=91750400, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal bsize=4096 blocks=44800, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 91750400 to 94371840
完成了

LV分区 减少空间
lvreduce -L -190G /dev/mygrp/disk1
提示信息
WARNING: Reducing active and open logical volume to 130.00 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce disk1? [y/n]: y 输入y确认
Reducing logical volume disk1 to 130.00 GiB
Logical volume disk1 successfully resized

格式化 查看更改
mkfs.xfs -f /dev/mygrp/disk1
**Note with xfs filesystem It’s not posible shrink the filesystem,
you have to back up your files before the resize and format the volume.
With ext2/3 the utility resize2fs or resize4fs for ext4,
also with reiserfs you can use resize_reiserfs.

VG卷 从VG卷移除硬盘
首先移动数据
pvmove /dev/sdb1 /dev/sde1
然后 把 sdb1 移除
vgreduce mygrp /dev/sdb1
Removed “/dev/sdb1” from volume group “mygrp”
现在在移除 PV
pvremove /dev/sdb1

Scroll to top