Tuesday, January 5, 2010

LVM - Volume Group

Naming Convention:

Volume group's name is unique and can have a max. 255 chars.
Default names of the form /dev/vgxx

Few Points to remember :

1. Max VGs per system can be changed thru the kernel tunable 'maxvgs'.
Minimum value is 0
Default Value is 16
Maximum value is 256
This tunable has been removed in version 11.31.

2. A Volume group can contain minimum 1 PV and maximum 255 PVs.

3. A VG can contain maximum 255 LVs.

Here is the list of mostly used commands for managing VG's :

To create a volume group :

# vgcreate

To remove a volume group :

# vgremove

To activate, deactivate, change the chars of a VG :

# vgchange

To modify the config parameters of a VG :

# vgmodify

To backup the VG config details :

# vgcfgbackup

To restore the VG config details from a config file :

# vgcfgrestore

To display the info for all or a particular VG :

# vgdisplay

To export a VG and its associated LVs:

# vgexport

To import a VG into the system as well as adding an existing VG into /etc/lvmtab :

# vgimport

To scan all PV s looking for LVs and VGs :

# vgscan

To add a PV to a VG :

# vgextent

To remove a PV from a VG :

# vgreduce

To sync all the mirrored LVs in a VG :

# vgsync

To modify the VGID on a PV :

# vgchgid

To migrate a VG from legacy to persistent device files :

# vgdsf

Here are few Examples,

1. To create a volume group :

a. Create a directory under /dev,

# mkdir /dev/vg01

b. Create a group device file

# mknod /dev/vg01/group c 64 0xnn0000

c -> to mention group is a character device file
64 -> is the major number for the group file. It should be always 64
0xnn0000 -> is the monir number for the group file in hexadecimal and nn is the unique vg number

c. Finally create the vg using a pv
# vgcreate /dev/vgname /dev/disk/disk12

2. To display all the volume groups :

# vgdisplay

3. To display the properties of a volume group :

# vgdisplay vg00

4. To display the detailed properties of a volume group :

# vgdisplay -v vg00

5. To add a PV to a VG :

# vgextend /dev/vg01 /dev/disk/disk13

6. To remove a PV from a VG :

# vgreduce /dev/vg01 /dev/disk/disk13

Before executing this command, make sure the PV disk13 doesnot hold any LV.

Otherwise vgreduce command wont work.

7. To deactivate a VG :

# vgchange -a n vg01

8. To activate a VG :

# vgchange -a y vg01

9. To export a VG :

# vgexport -s -v -m /tmp/vg01.map vg01
where /tmp/vg01.map is the map file whicj will hold PE-LE mappings and other config details.

10. To import a VG :

You need to create the VG dir and the group device file as like in the VG creation process.
Then you can import the VG using the below command,

# vgimport -s -v -N -m /tmp/vg01.map /dev/vg01

11. To change the "Max PV" attribtue to 255 for a VG :

# vgchange -a n vg01
# vgmodify -p 255 -n vg01
# vgchange -a y vg01

12. To change the "Max PE per PV" attribtue to 8128 for a VG :

# vgchange -a n vg01
# vgmodify -e 8128 -n vg01
# vgchange -a y vg01

13. To hold the write operation on a VG for 400 secs :

# vgchange -Q w -t 400 vg01
This operation is called as quiescing a VG.

14. To hold both read and write operation on a VG untill it is explicitly resumed :

# vgchange -Q rw vg01

15. To resume a quiesced VG :

# vgchange -R vg01

16. To rename a VG :

a. Deactivate the VG :
# vgchange -a n vg01

b. Find out the minor number of the Vg's group file :
# ls -l /dev/vg01/group

c. Export the VG :
# vgexport -m /tmp/vg01.map vg01

d. Create the vg dir in the new name and create its group file with the same minor number
# mkdir /dev/dbvg
# mknod /dev/dbvg/group c 64 0x010000

e. Import the VG
# vgimport -m /tmp/vg01.map /dev/dbvg

f. Backup the VG config info :
#  vgcfgbackup /dev/dbvg

g. Activate the VG :
# vgchange -a y /dev/dbvg

h. Remove the saved conf information file for the old vg name :
# rm /etc/lvmconf/vg01.conf

i. Modify all the references in other config files like /etc/fstab

1 comment: