Series of tutorial to learn LVM commands. In this part, learn how to remove volume group from system and how to sync stale PE within VG (vgremove, vgsync)
This is forth and last post of part two which is related to volume group in our LVM commands tutorial. Rest of the parts and posts can be found in below links :
- Part 1 : Physical Volume (pvcreate, pvdisplay)
- Part 1 : Physical Volume (pvchange, pvmove)
- Part 2 : Volume group (vgcreate, vgdisplay, vgscan)
- Part 2 : Volume group (vgextend, vgreduce, vgexport, vgimport)
- Part 2 : Volume group (vgcfgbackup, vgcfgrestore, vgchange)
- Part 3 : Logical volume (lvcreate, lvdisplay, lvremove)
- Part 3 : Logical Volume (lvextend, lvreduce, lvchange)
- Part 3 : Logical Volume (lvsync, lvlnboot)
We have seen 10 commands of volume group activities til now under part two. Now we will cover remaining two commands in this post.
Command : vgremove
vgremove commands used to remove volume group from system. But this is destroying command since it requires removal of all LV, PV in VG. It is always recommended to use vgexport instead of vgremove. Since vgexport also removes VG information from system but keeps it untouched on PV so that same PV can be imported to new VG on new/same system using vgimport.
Read : LVM legends
Safe removal of VG can be done with below steps :
- Backup all user data in that VG
- Get information of all LV and PV in that VG using vgdisplay -v command
- Make sure no LV is in use using fuser -cu /mount_point commandShell1234# fuser -cu /data/data: 223412c(user1)
- Unmount mount points of related LVShell123# umount /data
- Remove all LVs with lvremove /dev/vg01/lvol-name commandShell1234567# lvremove /dev/vg01/lvol1The logical volume "/dev/vg01/lvol1" is not empty;do you really want to delete the logical volume (y/n) : yLogical volume "/dev/vg01/lvol1" has been successfully removed.Volume Group configuration for /dev/vg03 has been saved in /etc/lvmconf/vg01.conf
- Remove all PVs in VG except any one with vgreduce /dev/vg01 /dev/disk/diskX commandShell12345#vgreduce /dev/vg01 /dev/disk/disk4Volume group "/dev/vg01" has been successfully reduced.Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf
- Finally use vgremove command to remove VG from systemShell1234# vgremove /dev/vg01Volume group "/dev/vg01" has been successfully removed
- Remove related group files from system using rm /dev/vg01 command
Command : vgsync
This command used to sync stale LE of LV mirrors in current VG. This used in mirroring only. Once can observe output of vgdisplay -v and confirm if there are any stale LE in current VG. If you found stale LE then you can synchronize them using this command.
# vgsync /dev/vg01
Resynchronized logical volume "/dev/vg01/lvol01".
Resynchronized logical volume "/dev/vg01/lvol02".
Resynchronized volume group "/dev/vg01".
There are no special option requried for this command.
This concludes part two (Volume group) of our LVM tutorials.