penglongli / blog

18 stars 1 forks source link

LVM 缩容 #78

Open penglongli opened 6 years ago

penglongli commented 6 years ago

本篇接上一篇:LVM 扩容

仅针对 Ext4 格式,xfs 格式未尝试。参考文章:

缩容比较危险,首先需要把挂载 umount 掉,请谨慎操作

本篇的目的:

机器上目前挂载了两块 10GiB 的盘,我们需要把第二章盘卸载掉

步骤

第一步,umount 掉挂载:

root@host-1:/# umount /data/

第二步:缩小 LV 的大小:

root@host-1:/# lvresize --resizefs --size 9.9GiB /dev/vg_data/lv_data

  Rounding size to boundary between physical extents: 9.90 GiB
fsck from util-linux 2.27.1
/dev/mapper/vg_data-lv_data: 11/1310720 files (0.0% non-contiguous), 122065/5240832 blocks
resize2fs 1.42.13 (17-May-2015)
Resizing the filesystem on /dev/mapper/vg_data-lv_data to 2595840 (4k) blocks.
The filesystem on /dev/mapper/vg_data-lv_data is now 2595840 (4k) blocks long.

  Size of logical volume vg_data/lv_data changed from 19.99 GiB (5118 extents) to 9.90 GiB (2535 extents).
  Logical volume lv_data successfully resized.

第三步:移除 PV

# 移除 /dev/vdc 上的数据
root@host-1:/# pvmove /dev/vdc
  No data to move for vg_data
# 把 /dev/vdc 从 vg_data 这个卷组移除出去
root@host-1:/# vgreduce vg_data /dev/vdc
  Removed "/dev/vdc" from volume group "vg_data"
root@host-1:/# vgs
  VG      #PV #LV #SN Attr   VSize  VFree
  vg_data   1   1   0 wz--n- 10.00g 96.00m

此时,我们的 PV 已经不再 vg_data 这个卷组里边了,我们就可以做其它的事情了。比如在其上新建卷组,或者把这快盘卸载掉。

注:

由于我们用的是云服务商的机器,并没有出现参考文章中的后续操作