Removing physical volume from VG


Step 1: Move Data Off the Physical Volume with pvmove

Before removing the physical volume, you need to ensure that all data on the physical volume is moved to other available physical volumes in the volume group.

  1. Move data off /dev/sdb1:

    Run the pvmove command to move data off the physical volume /dev/sdb1 (or whatever physical volume you want to remove):

    sudo pvmove /dev/sdb1

    This will move the data to other physical volumes in the volume group. You should wait for this process to complete before proceeding. You can check the progress with the following command:

    sudo pvdisplay /dev/sdb1

    When pvmove finishes, all the data will be relocated, and /dev/sdb1 will be free.


Step 2: Remove the Physical Volume from the Volume Group

Once the data has been moved, you can attempt to remove /dev/sdb1 from the volume group.

  1. Try to remove the physical volume:

    Use the vgreduce command to remove /dev/sdb1 from the volume group:

    sudo vgreduce myvg /dev/sdb1

    Replace myvg with the name of your volume group.

    Note: If there are no allocation extents left on /dev/sdb1, the command may fail with an error such as:

    No allocation extents available

Step 3: Add a New Disk (If Needed)

If the vgreduce command fails with the error "No allocation extents available," it means the volume group is full, and there is no free space available to remove the physical volume. In this case, you need to extend the volume group by adding a new disk.

  1. Add a new disk to the volume group:

    If you have a new disk (e.g., /dev/sdc) that you can add to the volume group, first partition it using fdisk or parted to create an LVM partition (8e type). Afterward, use the following command to add the new disk to the volume group:

    sudo vgextend myvg /dev/sdc

    This adds the new disk (/dev/sdc) to the volume group, freeing up space for the vgreduce operation.


Step 4: Retry Removing the Physical Volume

Once you have added a new disk to the volume group and extended the group, you should now have enough space to remove the physical volume.

  1. Remove the physical volume:

    Run the vgreduce command again to remove /dev/sdb1:

    sudo vgreduce myvg /dev/sdb1

    If successful, /dev/sdb1 will be removed from the volume group.


Step 5: Remove the Physical Volume Label

Once the physical volume is no longer part of the volume group, you can remove the LVM metadata and label from the disk, which makes it available for reuse.

  1. Remove the LVM metadata from /dev/sdb1:

    sudo pvremove /dev/sdb1

    This will completely erase the LVM metadata from /dev/sdb1 and make it ready for other uses, such as creating a new partition or using it for a different purpose.


Step 6: Verify the Changes

  1. Check the volume group to confirm the removal:

    sudo vgdisplay myvg

    This will show the updated details of the volume group. /dev/sdb1 should no longer be listed as part of the group.

  2. Check the physical volume list:

    sudo pvs

    This will show the physical volumes in use by the volume group. /dev/sdb1 should no longer appear.

Last updated