Tag Archives: how to export volume group

How to rename volume group

Learn how to rename the volume group in Linux or Unix. Understand what happens in the background when you change the volume group name of existing VG.

A volume group can be renamed with easy vgrename command Linux. But first, we will see how it can be done without vgrename command so that step by step you will understand what actually happens in the background while VG name changes.

We have seen how to create VG in the past and how to export/import VG. We are going to use these commands to rename VG. Below steps needs to be followed –

  1. Stop all user/app access to all mount points within VG using fuser
  2. Un-mount all LV using umount
  3. Deactivate VG using vgchange
  4. Export VG using vgexport
  5. Create a new name folder and group file using mknod
  6. Import VG with a new name in command options using vgimport
  7. Activate VG using vgchange
  8. Mount all LV using mount
  9. Edit related entries in /etc/fstab with a new name

See below output for the above-mentioned steps (HPUX console).

# fuser -cku /data
/data:   223412c(user1)
# umount /data
# vgchange -a n /dev/vg01
Volume group "/dev/vg01" has been successfully changed.
# vgexport -v -m /tmp/vg01.map vg01
Beginning the export process on Volume Group "/dev/vg01". 
/dev/dsk/c0t1d0 vgexport:Volume Group “/dev/vg01” has been successfully removed.
# mkdir /dev/testvg
# mknod /dev/testvg/group c major 0xminor
# vgimport -v -m /tmp/vg01.map /dev/testvg list_of_disk
vgimport: Volume group “/dev/testvg” has been successfully created.
Warning: A backup of this volume group may not exist on this machine.
Please remember to take a backup using the vgcfgbackup command after activating the volume group
# vgchange -a y testvg
Volume group “/dev/testvg” has been successfully changed.
# mount /dev/testvg/lvol1 /data

In the above step by step process, you can see how VG changes its name. We are changing its VG related file and directory and then we import it using old configuration but the new name.

In Linux, we have one command which does all this stuff in the background for you. vgrename is a command which used to rename VG in Linux. You have to supply the old VG name and required a new name.

# vgrename /dev/vg01 /dev/testvg
Volume group "/dev/vg01" successfully renamed to "/dev/testvg"
OR
# vgrename vg01 testvg
Volume group "vg01" successfully renamed to "testvg"

Keep in mind, this command also requires de-activated VG to work. So this is not an online process. It supports the below options :

  • -f Forcefully rename
  • -v Verbose mode

LVM commands tutorial : Part 2 : Volume group (vgextend, vgreduce, vgexport, vgimport)

Series of the tutorial to learn LVM commands. In this part, how to extend, reduce, export, and import volume group  (vgextend, vgreduce, vgexport, vgimport).

In this post, we are going to see how to extend the volume group, how to reduce the volume group, how to export volume groups, and how to import it. Previous posts of this LVM tutorial series can be found on below links :

This is the second post in part two of the volume group. In previous posts, we have seen commands like vgcreate, vgdisplay and vgscan. Let’s walk through new VG related commands.

Command: vgextend

Whenever there is a need for extra space on mount points and new disks are added to the system, related volume groups need to accommodate these new disks. Let’s say vg01 is existing VG and new disk5 is added to the server then you need to use vgextend command to add these new disks into vg01. This will, in turn, add new free PE in existing VG vg01 and hence free space will hike in VG.

To add disks into existing VG, you need to initialize it first with pvcreate command (see part one tutorial for pvcreate). Once done disk can be used in vgextend like below :

# vgextend /dev/vg01 /dev/disk/disk5
Volume group "/dev/vg01" has been successfully extended.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

After successful completion, you can verify that new PV is added to VG by looking at vgdisplay -v vg01 output.

This command can be used with below options :

  • -f Forcefully extend
  • -x Set allocation permissions
  • -z sparepv Should be used to mirroring to define spare PV
  • -g pvg_name Extend with the physical volume group specified.

Command: vgreduce

Its just reverse of the above command. It reduces VG by removing specified PV in command. It’s a bit risky to use hence extra precaution needed. You should make sure that no PE from targeted PV is being used in any LV of VG. This can be verified by lvdisplay and vgdisplay command. If no then you can use pvmove, lvremove commands to move/delete data. Once you are sure that no PE from targeted PV is being used i.e. all PEs are free to form this PV then run below command to remove PV from VG.

# vgreduce /dev/vg01 /dev/disk/disk5
Volume group "/dev/vg01" has been successfully reduced.
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

If you are using multiple PV links then you should remove all PV paths from VG using the above command.

This command allows two options :

  • -f Forcefully remove PV
  • -l pv_path Remove only specified particular PV path from VG

Command: vgexport

Using vgexport one can export all VG related information from disks into map file leaving data on disks intact. With the help of this map file, the same VG can be imported on another system provided all related disks are presented to this another system.

Please note that running this command removes all VG related files from /dev directory and all its related entries in /etc/lvmtab file. This means after running vgexport, that particular VG is turned into non-existent VG for the system.

Before running vgexport, one has to make sure that no one is using data on LVOLs from this VG. This can be verified using fuser -cu /mount_point command. Also, VG shouldn’t be active at the time of export hence you need to de-activate VG using vgchange.

# vgchange -a n /dev/vg01
Volume group "/dev/vg01" has been successfully changed.

# vgexport -v -m /tmp/vg01.map vg01
Beginning the export process on Volume Group "/dev/vg01". 
/dev/dsk/c0t1d0 vgexport:Volume Group “/dev/vg01” has been successfully removed.

This command allows below options :

  • -p Preview only. It won’t actually export Vg but creates a map file. Useful for live VG
  • -v Verbose mode
  • -f file Writes all PV paths to file. This file can be used as input to vgimport.

Command: vgimport

This command imports VG which been exported using the above command. Map file extracted from vgimport command should be supplied as an argument to vgimport. In case if a map file is not available, it will still try to import VG by reading LVM information lies of physical disks. In this case, a list of all PV should be supplied.

After vgimport successfully imports VG, note that it’s in an inactive state. You need to activate VG to use it on the system. Also, its recommended to take a configuration backup once you import new VG on system

# vgimport -v -m /tmp/vg01.map /dev/vg01 list_of_disk
vgimport: Volume group “/dev/vg01” has been successfully created.
Warning: A backup of this volume group may not exist on this machine.
Please remember to take a backup using the vgcfgbackup command after activating the volume group.

# vgchange -a y vg01
Volume group “/dev/vg01” has been successfully changed.

# vgcfgbackup /dev/vg01
Volume Group configuration for /dev/vg01 has been saved in /etc/lvmconf/vg01.conf

This command can be supplied with below options :

  • -N Import with persistent device file names
  • -s Scan each disk
  • -p Preview only
  • -v Verbose mode
  • -f file Import PV paths from the file

This concludes the second post of part two. In the next post, we will be seeing how to backup and restore volume group configurations and how to change volume group states.