欢迎来到云服务器

系统配置

如何安全的删除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

显示如下:

……

腾讯云代理

Copyright © 2003-2021 MFISP.COM. 国外vps服务器租用 梦飞云服务器租用 版权所有 粤ICP备11019662号