Series of the tutorial to learn LVM commands. In this part, learn how to remove volume group from the system and how to sync stale PE within VG (vgremove, vgsync)
This is the fourth and the 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 until now under part two. Now we will cover the remaining two commands in this post.
Command: vgremove
vgremove commands used to remove the volume group from the 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 the system but keeps it untouched on PV so that the same PV can be imported to new VG on the new/same system using vgimport.
- Also read: LVM legends
Safe removal of VG can be done with the below steps :
- Backup all user data in that VG
- Get information about all LV and PV in that VG using
vgdisplay -v
command - Make sure no LV is in use using
fuser -cu /mount_point
command# fuser -cu /data /data: 223412c(user1)
- Unmount mount points of related LV
# umount /data
- Remove all LVs with
lvremove /dev/vg01/lvol-name
command# lvremove /dev/vg01/lvol1 The logical volume "/dev/vg01/lvol1" is not empty; do you really want to delete the logical volume (y/n) : y Logical 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 anyone with
vgreduce /dev/vg01 /dev/disk/diskX
command#vgreduce /dev/vg01 /dev/disk/disk4 Volume 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 system# vgremove /dev/vg01 Volume 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. One can observe the 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 options required for this command.
This concludes part two (Volume group) of our LVM tutorials.