• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to remove used Physical Volume(PV) from Volume Group (VG) in LVM

by admin

We have already seen how to remove an unused PV from the volume group with vgreduce command.

CentOS / RHEL : How to remove unused Physical Volume(PV) from Volume Group (VG) in LVM

The vgreduce command shrinks the volume group by removing one or more PVs. But in case if the PV is in use by any of the LV, we have to first move the LVs onto some other free PVs using pvmove and then we can use the vgreduce command as usual to remove the PV. We can then either use these free PVS in another VG or remove them from the LVM configuration.

Removing used PV from VG

1. Extend the VG. where vg01 is the VG name and /dev/sdc is the destine device.

# vgextend vg01 /dev/sdc
  Volume group "vg01" successfully extended

If you have more than one disk, repeat this operation for all of them or provide disks in the same command with spaces.

2. Confirm the disk spaces using the pvs command. As you can see below the newly added disk is free with sufficient space to accommodate the data on /dev/sdb PV.

# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used  
  /dev/sda2  cl   lvm2 a--  19.00g     0  19.00g
  /dev/sdb   vg01 lvm2 a--  20.00g 10.00g 10.00g
  /dev/sdc   vg01 lvm2 a--  20.00g 20.00g     0

3. Run the pvmove command for the original PV that in this example is /dev/sdb. pvmove command will migrate all the LVs present on the device /dev/sdb to the device /dev/sdc. This is done online without any interruption. You could see the status on the command line.

# pvmove /dev/sdb
  /dev/sdb: Moved: 1.48%
  /dev/sdb: Moved: 100.00%

4. Reduce the VG in order to release the /dev/sdb PV.

# vgreduce vg01 /dev/sdb
  Removed "/dev/sdb" from volume group "vg01"

5. Check the /dev/sdb (origin) is completely free now.

# pvs -o+pv_used
  PV         VG   Fmt  Attr PSize  PFree  Used  
  /dev/sda2  cl   lvm2 a--  19.00g     0  19.00g
  /dev/sdb        lvm2 ---  20.00g 20.00g     0 
  /dev/sdc   vg01 lvm2 a--  20.00g 10.00g 10.00g

6. Now you can remove it completely from the LVM configuration if you want or you can use in some other volume group. Below is the example to remove it from LVM configuration.

# pvremove /dev/sdb
  Labels on physical volume "/dev/sdb" successfully wiped.

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to burn an ISO to CD or DVD using Wodim
  2. How to use execl (example included)
  3. Defining System Jobs Using Cron under Linux
  4. How to Convert a Directory to Partition in Linux
  5. lvremove Command Examples in Linux
  6. How to recreate LVM device files under /dev directory using vgmknodes
  7. How to configure DM-Multipath from an iSCSI initiator to an iSCSI target in CentOS / RHEL
  8. Failed to Download Metadata for Repo ‘repo_name’
  9. Apache HTTP server – most commonly used containers (special configuration directives)
  10. Linux “shutdown”, “poweroff”, “halt”, “reboot” Commands

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright