Linux系统从vg里删除某个pv

1、首先查看pv使用情况

[root@dzda01 ~]# pvscan
  PV /dev/vda3   VG vg01            lvm2 [62.00 GiB / 4.00 MiB free]
  PV /dev/vda4   VG vg01            lvm2 [<17.49 GiB / <17.49 GiB free]
  Total: 2 [79.49 GiB] / in use: 2 [79.49 GiB] / in no VG: 0 [0   ]

从pvscan给出的结果可以看出vda4这个pv是没有使用的,可以直接卸载掉。

2、从vg01中删除vda4

[root@dzda01 ~]# vgreduce vg01 /dev/vda4
  Removed "/dev/vda4" from volume group "vg01"
[root@dzda01 ~]# pvscan
  PV /dev/vda3   VG vg01            lvm2 [62.00 GiB / 4.00 MiB free]
  PV /dev/vda4                      lvm2 [<17.49 GiB]
  Total: 2 [79.49 GiB] / in use: 1 [62.00 GiB] / in no VG: 1 [<17.49 GiB]

3、删除pv
确认PV信息

[root@dzda01 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/vda3
  VG Name               vg01
  PV Size               <62.01 GiB / not usable 4.00 MiB
  Allocatable           yes
  PE Size               4.00 MiB
  Total PE              15873
  Free PE               1
  Allocated PE          15872
  PV UUID               yjxUQ0-UFPf-iziu-bnGj-sA1B-Qzvz-22l8ql
   
  "/dev/vda4" is a new physical volume of "<17.49 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/vda4
  VG Name               
  PV Size               <17.49 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               N5GfN7-3TDV-tMeU-JfTc-QLXL-g0aw-BCbZ03

删除pv

[root@dzda01 ~]# pvremove /dev/vda4
  Labels on physical volume "/dev/vda4" successfully wiped.

4、删除改盘上的lvm空间

[root@dzda01 ~]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bc594

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        6143        2048   83  Linux
/dev/vda2   *        6144     1054719      524288   83  Linux
/dev/vda3         1054720   131094527    65019904   8e  Linux LVM
/dev/vda4       131094528   167772159    18338816   8e  Linux LVM

Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted

Command (m for help): p

Disk /dev/vda: 322.1 GB, 322122547200 bytes, 629145600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000bc594

   Device Boot      Start         End      Blocks   Id  System
/dev/vda1            2048        6143        2048   83  Linux
/dev/vda2   *        6144     1054719      524288   83  Linux
/dev/vda3         1054720   131094527    65019904   8e  Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@dzda01 ~]# partprobe

现在vda4的空间就全部释放了,可以重新规划空间!如果是单盘pv的话,现在即可拔出硬盘了!

你可能感兴趣的:(Linux系统从vg里删除某个pv)