Series of tutorial to learn LVM commands. In this part, how to extend, reduce, export and import volume group (vgextend, vgreduce, vgexport, vgimport)
This is second post in part two of volume group. In previous posts we have seen commands like vgcreate, vgdisplay and vgscan. Lets walk through new VG related commands.
Command : vgextend
Whenever there is need of extra space on mount points and new disks are added to system, related volume groups needs to accommodate this new disks. Lets say vg01 is existing VG and new disk5 is added to server then you need to use vgextend command to add this new disks into vg01. This will in turns add new free PE in existing VG vg01 and hence free space will hiked 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 :
After successful completion you can verify that new PV is added to VG by looking at vgdisplay -v vg01output.
This command can be used with below options :
- -f Forcefully extend
- -x Set allocation permissions
- -z sparepv Should be used ti mirroring to define spare PV
- -g pvg_name Extend with physical volume group specified.
Command : vgreduce
Its just reverse of above command. It reduces VG by removing specified PV in command. Its 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 an be verified by lvdisplay and vgdisplay command. If no then you can use pvmove, lvremovecommands to move/delete data. Once you are sure that no PE from targeted PV is being used i.e. all PEs are free form this PV then run below command to remove PV from VG.
If you are using multiple PV links then you should remove all PV paths from VG using above command.
This commands 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 help of this map file, same VG can be imported on another system provided all related disks are presented to this another system.
Please note that, running this commands 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 turns into non-existent VG for 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 needs to de-activate VG using vgchange.
This commands allows below options :
- -p Preview only. It wont actually exports Vg but creates 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 above command. Map file extracted from vgimportcommand should be supplied as argument to vgimport. In case map file is not available, it will still try to import VG by reading LVM information lies of physical disks. In this case, list of all PV should be supplied.
After vgimport successfully imports VG, note that its in inactive state. You need to activate VG to use it on system. Also, its recommended to take a configuration backup once you import new VG on system
1
2
3
4
5
6
7
8
9
10
11
12
|
# 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 persistant device file names
- -s Scan each disks
- -p Preview only
- -v Verbose mode
- -f file Import PV paths from file
0 comments:
Post a Comment