Removing a LVM Volume Group in Linux

What if you created a volume group in LVM and no longer need it? Well, to properly clean everything up follow the steps below.

First, let’s identify the target.  In this case, I made a temporary /u2 partition, that I now no longer need:

# df -h /u2
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup02-LogVol00
148G 88G 53G 63% /u2

Of course, we need to unmount the drive:

# umount /u2

Let’s take a look at the volume we will be removing.  Notice there is a logical volume and a corresponding physical volume:

# vgdisplay /dev/mapper/VolGroup02
— Volume group —
VG Name VolGroup02
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 2
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 150.00 GB
PE Size 4.00 MB
Total PE 38399
Alloc PE / Size 38399 / 150.00 GB
Free PE / Size 0 / 0
VG UUID 7tVffs-U3id-Nksb-Yoqk-37Qg-JptR-bJYCy7

Next, we’ll deactivate the logical volume, then remove it:

# lvchange -an /dev/mapper/VolGroup02-LogVol00
# lvremove /dev/mapper/VolGroup02-LogVol00
Logical volume “LogVol00” successfully removed

If you look at the volume group now, you can see the logical volume has been removed.

# vgdisplay /dev/mapper/VolGroup02
— Volume group —
VG Name VolGroup02
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 150.00 GB
PE Size 4.00 MB
Total PE 38399
Alloc PE / Size 0 / 0
Free PE / Size 38399 / 150.00 GB
VG UUID 7tVffs-U3id-Nksb-Yoqk-37Qg-JptR-bJYCy7

Let’s take a look at the physical volume before changing it:

# pvdisplay /dev/sdc1
— Physical volume —
PV Name /dev/sdc1
VG Name VolGroup02
PV Size 150.00 GB / not usable 2.00 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 38399
Free PE 38399
Allocated PE 0
PV UUID B9zc6s-BvKl-TkWn-YTX9-lsBY-tstd-wQZFY3

Now we will go ahead and remove the volume group from the system, which also clears the physical volume for removal:

# vgremove /dev/mapper/VolGroup02
Volume group “VolGroup02” successfully removed

You can see that the physical volume is no longer tied to a volume group:

# pvdisplay /dev/sdc1
“/dev/sdc1” is a new physical volume of “150.00 GB”
— NEW Physical volume —
PV Name /dev/sdc1
VG Name
PV Size 150.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID B9zc6s-BvKl-TkWn-YTX9-lsBY-tstd-wQZFY3

We no longer need this hard drive, so we can now remove it:

# pvremove /dev/sdc1
Labels on physical volume “/dev/sdc1” successfully wiped

One last item of cleanup, remove the corresponding line in /etc/fstab:

# vi /etc/fstab





Please VOTE for this page at: ADD TO DEL.ICIO.US | ADD TO DIGG | ADD TO FURL | ADD TO NEWSVINE | ADD TO NETSCAPE | ADD TO REDDIT | ADD TO STUMBLEUPON | ADD TO TECHNORATI FAVORITES | ADD TO SQUIDOO | ADD TO WINDOWS LIVE | ADD TO YAHOO MYWEB | ADD TO ASK | ADD TO GOOGLE


Leave a reply