Linux LVM - delete volume group logical volume physical volume

View volume group related information

  1. [root@localhost /]# vgscan  
  2.   Reading all physical volumes.  This may take a while...  
  3.   Found volume group "VolGroup00" using metadata type lvm2  

View the PV and LV information contained in volume group VolGroup00.

  1. [root@localhost /]# vgdisplay -v VolGroup00  
  2.     Using volume group(s) on command line  
  3.     Finding volume group "VolGroup00"  
  4.   --- Volume group ---  
  5.   VG Name               VolGroup00  
  6.   System ID               
  7.   Format                lvm2  
  8.   Metadata Areas        1  
  9.   Metadata Sequence No  2  
  10.   VG Access             read/write  
  11.   VG Status             resizable  
  12.   MAX LV                0  
  13.   Cur LV                1  
  14.   Open LV               0  
  15.   Max PV                0  
  16.   Cur PV                1  
  17.   Act PV                1  
  18.   VG Size               1.01 GiB  
  19.   PE Size               8.00 MiB  
  20.   Total PE              129  
  21.   Alloc PE / Size       100 / 800.00 MiB  
  22.   Free  PE / Size       29 / 232.00 MiB  
  23.   VG UUID               Cug510-pQb6-RELO-lb1K-zjbt-3f62-jQLoQp  
  24.      
  25.   --- Logical volume ---  
  26.   LV Path                /dev/VolGroup00/iscsi00  
  27.   LV Name                iscsi00  
  28.   VG Name                VolGroup00  
  29.   LV UUID                tE78D6-5kJf-0HOh-4jRX-oLhI-ehyR-XhMmMQ  
  30.   LV Write Access        read/write  
  31.   LV Creation host, time localhost.iscsi, 2017-01-19 14:25:40 +0800  
  32.   LV Status              available  
  33.   # open                 0  
  34.   LV Size                800.00 MiB  
  35.   Current LE             100  
  36.   Segments               1  
  37.   Allocation             inherit  
  38.   Read ahead sectors     auto  
  39.   - currently set to     256  
  40.   Block device           253:0  
  41.      
  42.   --- Physical volumes ---  
  43.   PV Name               /dev/sda7       
  44.   PV UUID               OWz0uw-gTR1-WylF-z6HW-cgpe-LLd9-2W8Q9g  
  45.   PV Status             allocatable  
  46.   To edit/etc/fstab,Delete the corresponding mount information tal PE / Free PE    129 / 29  

Unmount logical volume LV on volume group

To unmount all logical volumes LV for the corresponding volume group VG. From the above information, we can see that the corresponding volume group VolGroup00 only has the logical volume Lv of / dev/VolGroup00/iscsi00

  1. [root@localhost /]# umount /dev/VolGroup00/iscsi00  

If the process is also using the file of the corresponding logical volume, you must force the mount point to be unloaded (ාdf -Th view).

Delete logical volume LV

  1. [root@localhost /]# lvremove /dev/VolGroup00/iscsi00  
  2. Do you really want to remove active logical volume iscsi00? [y/n]: y  
  3.   Logical volume "iscsi00" successfully removed  
  4. [root@localhost /]#   

If there is an error in the deletion prompt, check the process currently using the logical volume, and then end the process or service.

Verify LV is removed

  1. [root@localhost /]# lvdisplay | grep "dev/VolGroup00/iscsi00"  

Delete volume group VG

  1. [root@localhost /]# vgremove VolGroup00  
  2.   Volume group "VolGroup00" successfully removed  
  3. [root@localhost /]#   

If you delete a volume group VG in a secure way, you must shut it down using vgchange -a n VolGroup00, and then delete it.

  1. [root@localhost /]# vgchange -a n VolGroup00  
  2.   0 logical volume(s) in volume group "VolGroup00" now active  
  3. [root@localhost /]# vgremove VolGroup00  
  4.   Volume group "VolGroup00" successfully removed  
  5. [root@localhost /]#   

Verify that the volume group (VG) is deleted

  1. [root@localhost /]# vgscan   
  2.   Reading all physical volumes.  This may take a while...  
  3.   No volume groups found  
  4. [root@localhost /]#   

Delete physical volume PV

  1. [root@localhost /]# pvremove /dev/sda7  
  2.   Labels on physical volume "/dev/sda7" successfully wiped  
  3. [root@localhost /]# pvscan  
  4.   No matching physical volumes found  
  5. [root@localhost /]#  

Edit / etc/fstab to delete the corresponding mount point information

If the mount point is not set, this step can be ignored, otherwise there will be problems in restarting the system. Remember!

Reproduced from: http://blog.csdn.net/jazzsoldier/article/details/54631183

Added by tempa on Mon, 04 May 2020 10:22:53 +0300