Remove LVM VG and PV

#ff0000;">[Just for learning and practice][all data will be deleted ]

Removing Logical Volume, volume group, physical volume and delete partition to make /dev/sdb clean

  • in order to do that you have to check what volume group, logical volume and physical volume is in that drive and delete it
  • check it with below commands
[[root@rhce1 ~]# fdisk -l /dev/sdb
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         128     1028128+  8e  Linux LVM

[root@rhce1 ~]# pvs
  PV         VG    Fmt  Attr PSize    PFree
  /dev/sda5  sysvg lvm2 a--    67.75g   56.75g
  /dev/sdb1  appvg lvm2 a--  1000.00m 1000.00m
[root@rhce1 ~]# vgs
  VG    #PV #LV #SN Attr   VSize    VFree
  appvg   1   0   0 wz--n- 1000.00m 1000.00m
  sysvg   1   6   0 wz--n-   67.75g   56.75g
[root@rhce1 ~]# lvs
  LV         VG    Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  testlv     appvg -wi-ao---- 200.00m
  homelv     sysvg -wi-ao---- 2.00g
  optlv      sysvg -wi-ao---- 1.00g
  tmplv      sysvg -wi-ao---- 1.00g
  usrlocallv sysvg -wi-ao---- 1.00g
  usrlv      sysvg -wi-ao---- 4.00g
  varlv      sysvg -wi-ao---- 2.00
  • so from above we found out that  on sdb there is sdb1 partition
  • sdb1 is also a physical volume
  • on physical volume sdb1 there is appvg volume group
  • and one testlv logical volume in appvg
  • so start from bottom:  ……  remove required lvm, then remove vg, then remove pv and then remove partition

 

 

so we start with removing logical volume

 

  • first use umount command to unmount
[root@rhce1 ~]# umount /test
  • check if logical volume is unmounted with df -h command logical volume testlv should not be there
[root@rhce1 ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda2                     9.9G  457M  8.9G   5% /
tmpfs                         1.6G  168K  1.6G   1% /dev/shm
/dev/sda1                     248M   34M  202M  15% /boot
/dev/mapper/sysvg-homelv      2.0G   68M  1.9G   4% /home
/dev/mapper/sysvg-optlv      1008M  494M  464M  52% /opt
/dev/mapper/sysvg-tmplv      1008M  507M  451M  53% /tmp
/dev/mapper/sysvg-usrlv       4.0G  3.0G  790M  80% /usr
/dev/mapper/sysvg-usrlocallv 1008M   34M  924M   4% /usr/local
/dev/mapper/sysvg-varlv       2.0G  378M  1.5G  20% /var
  • remove logical volume and check with lvs command
[root@rhce1 ~]# lvremove /dev/appvg/testlv
Do you really want to remove active logical volume testlv? [y/n]: y
  Logical volume "testlv" successfully removed
[root@rhce1 ~]# lvs
  LV         VG    Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  homelv     sysvg -wi-ao---- 2.00g
  optlv      sysvg -wi-ao---- 1.00g
  tmplv      sysvg -wi-ao---- 1.00g
  usrlocallv sysvg -wi-ao---- 1.00g
  usrlv      sysvg -wi-ao---- 4.00g
  •     remove volume group and check with vgs
  •  [root@rhce1 ~]# vgremove /dev/appvg
      Volume group "appvg" successfully removed
    
    [root@rhce1 ~]# vgs
      VG    #PV #LV #SN Attr   VSize  VFree
      sysvg   1   6   0 wz--n- 67.75g 56.75g
  • remove physical volume and check with pvs
  • [root@rhce1 ~]# pvremove /dev/sdb1
      Labels on physical volume "/dev/sdb1" successfully wiped
    [root@rhce1 ~]# pvs
      PV         VG    Fmt  Attr PSize  PFree
      /dev/sda5  sysvg lvm2 a--  67.75g 56.75g
    
    
  • now delete partitions
  • [root@rhce1 ~]# fdisk /dev/sdb
    
    WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
     switch off the mode (command 'c') and change display units to
     sectors (command 'u').
    
    Command (m for help): d
    Selected partition 1
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@rhce1 ~]# partprobe

check with fdisk -l /dev/sdb command and it should be empty

 

[root@rhce1 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xf0881c67

   Device Boot      Start         End      Blocks   Id  System
[root@rhce1 ~]#

also check creating physical volume volume group and logical volume    < click here

 

Leave a Reply