6

Linux如何在LVM中移除PV

 1 year ago
source link: https://halfcoke.github.io/2021/2d54e946/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Linux如何在LVM中移除PV

Linux如何在LVM中移除PV

网上很多人都在讲如何直接移除PV,但是实际过程中,很有可能我们的PV还没有空闲空间,这样也就没办法直接用pvmove指令。

我们先介绍如何将pv空闲出来。

移除PV准备工作

通过lsblk命令我们可以看到,当前根目录的LVM是用了两个盘的,即sdasdb。我们想将sdaLVM中拿出来,这样sda就可以用来做别的事情了。

image-20210318100540412

使用df -hT查看当前分区的使用情况,我们可以看到根目录只用了72G,/home目录空闲有249G,这个时候我们可以将/home中的一部分空间拿出来,最好空闲直接大于72G,保证能装得下。如果小于72G的时候不确定能不能装得下,这部分需要自己试一下。

image-20210318101352606

我们执行一下lvdisplay,查看一下lv的信息,下图列出了部分内容。

image-20210318101759476

这个时候我们执行lvreduce -L 150G /dev/cl/home命令,这条命令相当于将/home路径的空间直接缩小到150G,因为我们在上面通过df -hT看到了/home目录只用了144G。

这样我们相当于已经有空间用来存放根目录的数据了。

接下来我们执行移除PV的相关操作

我们执行pvs -o+pv_used,只要/dev/sda1used的是0就可以了。下面这个图忘记截了,放一个之前的数据的图。

image-20210318103700432

# 然后执行下面的命令,转移PV中的数据
pvmove /dev/sda1
# 然后从vg中移除pv
vgreduce {vg组名} /dev/sda1
即:vgreduce cl /dev/sda1
# 然后移除PV
pvremove /dev/sda1

至此,所有步骤完成。

[1] How to Remove Physical Volume from a Volume Group in LVM

[2] LVM : 缩减文件系统的容量

[3] Linux如何使用LVM进行磁盘扩容


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK