系统小窝欢迎您

电脑公司 深度技术
当前位置:系统小窝 > 系统教程 > Linux教程 >

Linux删除LVM中PV物理卷的技巧

时间:2021-04-09 来源:来吧老妹 人气:

LVM通常用于装备大量磁盘的系统,具有良好的可伸缩性,可对卷组、逻辑卷的大小进行调整,今天小编要给大家介绍的是Linux如何删除LVM中的PV物理卷(硬盘或分区),一起来学习下吧。

一、由于硬盘或者分区的操作方式其实都一样,所以我这里就以分区为例。

二、/home分区2.6G,由如下pv组成:

/dev/sda5 100M

/dev/sda6 200M

/dev/sda7 300M

/dev/sda8 400M

/dev/sda9 500M

/dev/sda10 600M

/dev/sda11 500M

很碎对吧?^_^因为测试。

三、随机写了一堆文件进去,用量达到了2G,空闲500M

四、准备将sda6这个200M的PV卸掉(卸掉的容量必须小于空闲容量)

好了开始具体操作了。

卸载分区(缩小操作必须卸载才能进行):

umount /home

缩小分区:

e2fsck -f /dev/liuhg_disk/home

resize2fs /dev/liuhg_disk/home 2200M

首先将分区缩小到2200M这是为了给sda6腾出空间,sda6为200M,而我腾出了400M,因此应该是足够的。

缩小逻辑卷:

lvreduce -L 2200M /dev/liuhg_disk/home

分区缩小了用到的逻辑卷也要随着缩小,并查看PV使用的状态:

pvdisplay -m

显示如下:

--- Physical volume ---

PV Name /dev/sda5

VG Name liuhg_disk

PV Size 103.26 MiB / not usable 3.26 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 25

Free PE 0

Allocated PE 25

PV UUID 5lnx52-b4jc-OOfZ-f2QA-ttdQ-DZeD-Ce3rb3

--- Physical Segments ---

Physical extent 0 to 24:

Logical volume /dev/liuhg_disk/home

Logical extents 0 to 24

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 50

Free PE 0 《-----太悲剧了,sda6里写满了数据一点不剩

Allocated PE 50 《-----这50PE的数据要挪走才行,否则数据就丢了,并且存放的地方也必须是连续的至少50PE

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

--- Physical Segments ---

Physical extent 0 to 49:

Logical volume /dev/liuhg_disk/home

Logical extents 25 to 74

--- Physical volume ---

PV Name /dev/sda7

VG Name liuhg_disk

PV Size 305.89 MiB / not usable 1.89 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 76

Free PE 76 《---这个分区有76个空余,因此预计装那50个是不会有问题的

Allocated PE 0

PV UUID 9CFnlx-CAEw-CSul-Rig9-FiCN-zK0a-oGmTEP

--- Physical Segments ---

Physical extent 0 to 75:

FREE

--- Physical volume ---

PV Name /dev/sda8

VG Name liuhg_disk

PV Size 407.87 MiB / not usable 3.87 MiB

Allocatable yes

PE Size 4.00 MiB

Total PE 101

Free PE 60

Allocated PE 41

PV UUID X0I8p0-x2xr-2xLG-QQD4-jbtS-3C4i-xPn4Bl

--- Physical Segments ---

Physical extent 0 to 40:

Logical volume /dev/liuhg_disk/home

Logical extents 471 to 511

 

Physical extent 41 to 100:

FREE

--- Physical volume ---

PV Name /dev/sda9

VG Name liuhg_disk

PV Size 509.84 MiB / not usable 1.84 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 127

Free PE 0

Allocated PE 127

PV UUID avJQaA-oMKt-NEoJ-ojBK-2Csc-1dca-1mh6Ue

--- Physical Segments ---

Physical extent 0 to 126:

Logical volume /dev/liuhg_disk/home

Logical extents 225 to 351

--- Physical volume ---

PV Name /dev/sda10

VG Name liuhg_disk

PV Size 603.98 MiB / not usable 3.98 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 150

Free PE 0

Allocated PE 150

PV UUID JlMIAF-A49n-M6HA-ZLXf-d8nS-pfZr-YeQsKT

--- Physical Segments ---

Physical extent 0 to 149:

Logical volume /dev/liuhg_disk/home

Logical extents 75 to 224

--- Physical volume ---

PV Name /dev/sda11

VG Name liuhg_disk

PV Size 478.47 MiB / not usable 2.47 MiB

Allocatable yes (but full)

PE Size 4.00 MiB

Total PE 119

Free PE 0

Allocated PE 119

PV UUID xnHJNA-tDVx-dryX-KM1x-g96Y-sptI-9iUOcU

--- Physical Segments ---

Physical extent 0 to 118:

Logical volume /dev/liuhg_disk/home

Logical extents 352 to 470

将sda6设置为离线状态:

pvchange -xn /dev/sda6

使用pvdisplay -m

显示如下:

hellip;hellip;

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable NO 《-----表示已经关闭了该PV

PE Size 4.00 MiB

Total PE 50

Free PE 0

Allocated PE 50

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

hellip;hellip;

将sda6的数据移走:

pvmove -i 1 /dev/sda6

-i 1是每1秒钟报告一次数据迁移的进度。

[root@liuhg /]# pvmove -i 1 /dev/sda6

/dev/sda6: Moved: 38.0%

/dev/sda6: Moved: 84.0%

/dev/sda6: Moved: 100.0%

重新用pvdisplay -m

显示如下:

hellip;hellip;

--- Physical volume ---

PV Name /dev/sda6

VG Name liuhg_disk

PV Size 203.92 MiB / not usable 3.92 MiB

Allocatable NO

PE Size 4.00 MiB

Total PE 50

Free PE 50 《----显示完全空闲和Total PE数一致

Allocated PE 0

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

hellip;hellip;

从卷组里把sda6删除:

[root@liuhg /]# vgreduce liuhg_disk /dev/sda6

Removed ;/dev/sda6; from volume group ;liuhg_disk;

pvdisplay -m再看看吧:

--- NEW Physical volume --- 《-----还告诉你这是一个新的PV ^_^

PV Name /dev/sda6

VG Name 《-----空了

PV Size 203.92 MiB

Allocatable NO

PE Size 0

Total PE 0

Free PE 0

Allocated PE 0

PV UUID S2ane6-nlFG-uSNR-35NP-Yxa6-cXRb-r8E8mK

到此vgdisplay -v能看到已经没有了/dev/sda6了。重新挂载/home

[root@liuhg /]# mount /dev/liuhg_disk/home /home

[root@liuhg /]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/sda1 2.0G 546M 1.3G 30% /

tmpfs 504M 0 504M 0% /dev/shm

/dev/mapper/liuhg_disk-home

2.2G 1.8G 42M 98% /home

进去看看数据,一个都没丢。

上面就是Linux删除LVM中的PV物理卷(硬盘或分区)的介绍了,如果你在系统中安装了LCM,而又不知道如何删除其中的PV物理卷的话,可以试试文中介绍的方法。

相关文章

  • Linux如何创建使用LVM

    Linux如何创建使用LVM

    LVM是逻辑卷管理,是Linux下对磁盘分区管理的一种机制,相信不少人想要知道Linux如何创建LVM和LVM的使用方法,因此小编将针对LVM的创建和使用做个详细介绍...
    2021-04-09 09.04.23
  • 在Linux系统中挂载LVM分区的步骤

    在Linux系统中挂载LVM分区的步骤

    LVM分区一般都是存在于U盘当中,Linux系统通过U盘来访问这些分区。如果想让Linux直接访问这些分区,可以在Linux系统中直接挂载这些分区。本文就来介绍一...
    2021-04-10 10.04.46
  • 使用PV命令监控Linux命令完成情况的方法

    使用PV命令监控Linux命令完成情况的方法

    Linux的系统管理员需要对命令实行实时的监控,这样才会知道命令是被顺利的执行了,而不是已经被挂起。下面就来介绍一下使用PV命令监控Linux命令完成情...
    2021-04-10 04.04.48

发表评论

验证码: 看不清?点击更换

注:网友评论仅供其表达个人看法,并不代表本站立场。