LVM (Logical Volume Manager)


          LVM (Logical Volume Manager)

If you need LVM commands, click the below link



In AIX first Physical volumes (PV) are added into volume group(VG),
After that only we can create logical volumes, and file systems.

Minimum one PV is belongs to VG, While creating the VG we should mention physical partition (pp) size, this pp’s pointed to logical portions (LP),

Suppose we have 40GB HDD, we have added in one VG named DataVG , While creating the VG we should mention the pp size, i.e.

PP size will be 4MB to 128MB, suppose we are mentioned pp size is 32MB, then that 40GB HDD divided into


1024MB *40 = 40960MB

Each pp size is 32MB, then 40GB HDD spited into i.e.

40960 / 32 = 1280 PP’s

So DATAVG has 1280 PP’s

While creating the Logical volumes we should mention the lv size by giving the no of pp

Suppose you want to create one file system /userdata, that file system size will be 1GB, this file system is belongs to one particular LV, So while creating the LV we should mention the lv size is 1GB, but directly we cannot mention the GB size.

Each pp has 32MB, So you create LV with 32 PP’s, then that lv size will be 1GB.

After creating the LV using 1GB space we can increase LV size online, reboot is not required.

This LVM we can do following things,

  1. List PV
  2. Change PV
  3. Create VG
  4. List VG
  5. Extend VG
  6. Reduce VG
  7. Varryon VG
  8. Varryoff VG
  9. Create LV
  10. List LV
  11. Extend LV
  12. Change LV
  13. Create LV copy
  14. Remove LV copy
  15. Remove LV
  16. Create FS
  17. Change FS
  18. List Fs
  19. Mount FS
  20. Unmount FS
  21. Remove FS
  22. Repair FS
  23. Mirror VG
  24. Syncvg
  25. Unmirror VG
  26. Migrate PV
  27. Migrate LV
  28. Export VG
  29. Import VG
  30. Change VG

NOTE:

After AIX installation by default root volume group (rootvg) will be available


1. List Physical Volumes

Suppose we want to know how many PV’s available in server, The following command is list the Pv’s

#lspv

Hdisk0
Hdisk1
Hdisk2
#
The above command is used to display the pv availability







Suppose you want to see particular PV information then your command will be

#lspv hdisk1

After executing lspv command it will display the hdisk2 PV information. All the information, like pp size, used pp’s, free pp, allocatable, hotspare etc.

Suppose we want to see logical volumes details in single hdisk2 PV
Then your command will be



#lspv –l hdisk2

The above command is used to display all the LV details across the PV hdisk2

Suppose we want to see pp storage information in hdisk2, then your command will be

#lspv –p hdisk2

The above command is display the pp usage information across the PV hdisk2



2. Change PV

Suppose we have three PV’s, like hdisk0, hdisk1, hdisk2, now you want to deactivate the hdisk2,

#chpv  -vr hdisk2 (To deactivate the hdisk2)
#chpv –va hdisk2 (To activate the hdisk2)
#chpv –an hdisk2 (hdisk2 is not allocatable)
#chpv –ay hdisk2 (hdisk2 is allocatable)
#chpv –hn hdisk2 (hotspare no)
#chpv –hy hdisk2 (Hotspare yes)
#chpv –c hdisk2 (To clear the boot image)

Above operations we can do by using chpv command






3. Create VG,

We can create VG by using mkvg commands

#mkvg –s 32 –y datavg hdisk4

The above command is creating datavg using pv hdisk4 and pp size is 32MB

#mkvg datavg hdisk4

The above command is creating datavg using pv hdisk4 and pp size is by default 128MB


4. List VG

We can list VG information using following commands

#lsvg – It will display the available vg’s
#lsvg datavg – It will display full details about datavg only
#lsvg –o    It will display the online vg’s
#lsvg – l datavg – It will display the all logical volume details across the datavg
#lsvg –p datavg – It will display the information about all PV’s in datavg

Above operations we can do by using lsvg commands


5. Extend VG

We can increase VG size by adding Pv into existing VG using extendvg command

#lsvg –p datavg
Hdisk4
Hdisk5
#
datavg has 2 PV’s  now we want to extend datavg, then your command will be

#extendvg datavg hdisk6

After executed command hdisk6 pv added with datavg

#lsvg –l datavg
Hdisk4
Hdisk5
Hdisk6
#


6. Reduce VG

We can remove the VG using reducevg command, Suppose we want remove testvg and testvg has one pv hdisk9

#lsvg –p testvg
Hdisk9
#

Now we will remove the pv from testvg

#reducevg –f testvg hdisk9

f-  option is used to force reduce, you have data in pv hdisk9, that time I will not any questions,  directly it will remove the pv from testvg. Suppose 2 PV’s available in testvg then one by one we can reduce the PV’s


7. Varryon VG

This is just for VG activation; some times clients want to deactivate VG for project restriction. After that we want to activate the VG for further data access

Suppose we want to activate testvg, then your command will be

#lsvg
Rootvg
Datavg
Testvg

The above command shows what are VG’s available

#lsvg –o
Rootvg
Datavg









The above commands shows only online VG’s because testvg is offline so we have to activate testvg

#varryonvg testvg

#lsvg –o
Rootvg
Datavg
Testvg

Now above command is display the testvg.


8. Varryoff VG

This is just for VG deactivation; some clients want to deactivate VG for project Restriction. Suppose customer want deactivate testvg then your command will be

#lsvg –o
Rootvg
Datavg
Testvg

#Varryoff testvg

#lsvg –o
Rootvg
Datavg

The above command display only two online VG’s and it will not show testvg because testvg is offline VG.

9. Create LV

All the File systems belongs to individual LV, after creating the VG’s we should create the LV using mklv command

Suppose you want to create LV name as newlv

#mklv –y newlv –t jfs2 datavg 5 hdisk4

-y for confirmation
-t type mentioning the filesystem type i.e. jfs or jfs2,
Datavg – lv created on datavg
5 – 5 PP’s allocated for newlv ( 1 pp size 32MB the newlv size is 32MB*5 = 160MB)
Hdisk4 – that newlv is belongs to PV hdisk4


10. List LV

Suppose we want see what are the Lv’s available in datavg, then your command will be

#lsvg –l datavg
It will login list LV details

   newlv

Now we want see newlv properties, then your command will be



#lslv newlv

The above command is used to display the newlv properties, i.e. available pp’s mount pint, label name, stale partitions. Etc.

#lslv –m newlv – To display the lvcopy information’s


11. Extend LV

Suppose we want to increase LV size using extendlv command

#lslv newlv

The above command shows LV size, no of LP’s and some other information about LV, suppose LV has 10 LP’s and usage is up to 95% full, that time we can increase the LV size online by adding no of LP’s in newlv i.e.

#extendlv newlv 5

After executing the above command 5 PP’s added with newlv, then some additional space will available in newlv. Suppose you want to see this changes again use the lslv command

#lslv newlv (it will show no of LV’s is 15 and some additional space)






12. Change LV

In this change LV option we can change LV name and permissions for the LV using chlv command.

#chlv –n newlvname oldlvname

#lslv testlv

Output is some details about testlv

#chlv –n newlv testlv

After executing the above command the testlv renamed to newlv

#lslv testlv
Some error message will come i.e. testlv is not found

#lslv newlv

It will show newlv details, because testlv is renamed as newlv.


Changing the LV permissions: suppose we want to change LV permissions to read only then the command will be

#chlv –p r testlv

After executing the above command testlv permissions changed as read only , so we can only read the LV, we can not copy new files into this LV.


13. Create LV copy

We can create LV content copy to another PV, after this same LV content is available in Lvcopy configured PV.

#lspv
Hdisk0
Hdisk1
Hdisk2
#lspv –l hdisk1
Assume testlv available in hdisk1, now we will make testlv copy to hdisk2, using
After this testlv data available in both PV, hdisk1 and hdisk2, suppose hdisk1 is fail, we can recover testlv data from hdisk2

#mklvcopy testlv 2 hdisk2

Testlv –lv name
2- No of copies, (we can make 3 copies also; this case you put 3 and mention hdisk0 then third copy will be available in hdisk0)

##mklvcopy testlv 3 hdisk0 ( It will make third lvcopy on hdisk0

After executing above command testlv is copied to hdisk2

If you want to confirm run the following command

#lslv –m testlv (it will show lvcopy details for testlv)

Hdiks1            hdisk2             hdisk0

Testlv (copy1)            testlv (copy2)  testlv (copy3)
14. Remove LV copy

Using rmlvcopy we can remove the lvcopy from the PV’s

Suppose we want to remove testlv copy from hdisk0

#rmlvcopy testlv 3 hdisk0

After executing the above command third copy of the testlv removed from PV hdisk0, like this we can remove


15. Remove LV

Suppose we want to LV testlv from server

#rmlv testlv (If data is available in testlv It will ask confirmation)

#rmlv –f testlv (It won’t ask any confirmation, directly it will delete the data)

After executing the above command testlv removed from the server. 








16. Create FS

Using crfs command we can create a file system. File systems belongs to LV’s

Whenever we create the file system we should mention the LV name

#crfs –v jfs2 –d testlv –m /newfs (Normal creation)

The /newfs file system created on testlv.

#crfs –v jfs2 –g testvg –a size=64465 –m /newfs (Directly we can create /fs from VG
This case lv name will be lv00 or lv01 like this after that also we can rename the lv name)


17. Change FS

Using chfs command we can rename and increase the size of the file system online

We want to increase file system size

#chfs –a size=+block size /filesystem name
#chfs –a size=+32m /filesystem name
#chfs-a size=+4g /filesystem name

+block size – We can mention the size using blocks (2048 blocks = 1MB)
+32m – We can mention the size using MB
+4g – We can mention the size using GB


After increasing the file system size, we can verify using commands

#df –k
#ls –q /newfs

Rename the file system using chfs command

#lsfs /newfs
It will display /newfs details
#

Now we want to rename /newfs to /testfs then your command will be




#chfs –m /testfs /newfs

After executing the above command /newfs renamed as /testfs

We can auto mount the file system while booting using chfs command

#chfs –A /testfs


18. List Fs

We can list file system details using lsfs command

#lsfs – List all filesystems in the /etc/filesystems entry
#lsfs –q (List all filesystems with detailed info)
#lsfs –a (list all filesystems (default)
#lsfs –l (specify the output in the list format)
#lsfs –c (specify the output in the column format)
#lsfs –v jfs (List all jfs filesystems)


19. Mount FS

After creating the file system, we should mount the file system, without file system mount we cannot access the file system using mount command we can mount the file system.

Before mount lsfs command is wont display the /newfs file system

#lsfs –a

That /newfs file system detail is not available

#mount /newfs

Now you put lsfs command it will show the /newfs details

#lsfs –a







20. Unmount FS

Using umount or unmount command we can umount the file system i.e. file system is moved to off line.

#umount /newfs

After this you run the lsfs –a command it wont display /newfs file system details.

#lsfs –a


21. Remove FS

Using rmfs command we can remove the file systems

#lsfs –a

/testfs

Before removing the /testfs. That file system should be unmounted.
#umount /testfs

#rmfs /testfs (Deletes FS /newfs and associated LV)

After executing the above command /testfs is removed.

#rmfs –r /testfs (Deletes FS /newfs its mount point and associated LV)


22. Repair FS

Using fsck command we can repair the problematic FS or corrupted FS

Suppose you want check /data FS

#fsck /data

Or directly we can repair the LV

#fsck –Y n /dev/datalv  (To fsck the FS associated to /dev/datalv assuming response “Yes”

#fsck –p /dev/datalv (To restore superblock from backup superblock)



23. Mirror VG

We can do mirroring in AIX, using mirrorvg command and we can create max. Three copy of mirror.

Suppose we have two PV’s in rootvg, now we want mirror, Data and OS installed in hdisk0 and now we want to mirror hdisk0 to hdisk1. Then your command will be

#mirrorvg –S –m rootvg hdisk1

S – Backgroup mirror
-m - exact (force) mirror

NOTE: in mirrored VG quorum should be off line because quorum is not recommended for mirror.


24. Synchronize VG

Using Syncvg command we can sync the mirrored Vg and LV copy information’s

Suppose we want to sync lvcopy

#syncvg –l lvname

#syncvg –l testlv

After executing the above command, testlv copy get sync with lv copied PV

Suppose we want to sync mirrored PV’s

#syncvg –v rootvg

The above sync the mirrored PV’s in rootvg


25. Unmirror VG

Using Unmirror command we can Unmirror the VG

#unmirrorvg rootvg hdisk1

PV hdisk1 is removed from rootvg mirror


26. Migrate PV

Using migratepv command we can move full PV data or single LV from one PV to another PV. This is not copy just cut and past method

Suppose we want to migrate data from PV to PV

#migratepv hdisk1 hdisk2

After executing above command hdisk1 data is moved to hdisk2


27. Migrate LV

Using migratepv command we can migrate lv from PV to PV

Suppose we want to migrate single LV

#migratepv –l testlv hdisk1 hdisk2

After executing above command testlv LV is moved hdisk2.


28. Export VG

Using exportvg command we can export VG (including all the PV’s) from one server to another server.

Suppose you have ServerA, in this server has DATAVG with two PV’s. Now we want export DATAVG to ServerB

Before exporting the DATAVG, we should Varryoff the DATAVG, i.e. DATAVG is moved to offline.

#varryoff DATAVG (Varryoff the DATAVG)
#exportvg DATAVG (VG information removed from ODM)









Now DATAVG is exported from the ServerA, after this run the following command to verify the export.

#lsvg

It won’t show DATAVG name. Because DATAVG is exported.

Then you should remove PV from the configuration

#rmdev –dl hdisk3
#rmdev –dl hdisk4

After that we can remove the PV’s from ServerA for import DATAVG to ServerB


29. Import VG

Using importvg command we can import the DATAVG to ServerB

First you should connect hdisk3, hdisk4, in ServerB then, run the
#cfgmgr (for hard disk detection)

Then check the PV’s installed or not using lspv command
#lspv (it will display the installed PV’s) if hdisk3, hdisk4 is available then PV’s are configured properly.

Then run the command importvg for import the DATAVG

#importvg –y DATAVG hdisk3 (VG information is added in ODM)
#importvg –y DATAVG hdisk4 (VG information is added in ODM)

NOTE:

Suppose ServerB has VG with same name DATAVG, This case we can rename the importing VG DATAVG to other name,

#importvg –y NEWDATAVG hdisk3
#importvg –y NEWDATAVG hdisk4

Like this we can import.

After importing the DATAVG, we no need to Varryon DATAVG, automatically it will Varryon while importing.




30. Change VG

Using chvg command we can change the VG options

#chvg –a y datavg (datavg is automatically activated at startup)
#chvg -a n datavg (To deactivate the automatic activation at startup)
#chvg –t 2 datavg (To change max. no of PP to 2032 on vg datavg)
#chvg –Qn datavg (To disable quorum on VG datavg)
#chvg –Qy datavg (To activate quorum on VG datavg)
#chvg –u datavg (To unlock the VG)

NOTE:

Quorum, VGDA, VGSA, LVCB

VGDA (Volume Group Descriptor Area)

Volume group descriptor area (VGDA) is an area on the disk that contains
Information pertinent to the volume group that physical volume belongs to. It
Also includes information about properties and status of all physical and
Logical volumes that are part of the volume group. The information from VGDA
is used and updated by LVM commands. There is at least one VGDA per
Physical volume. Information from VGDAs of all disks that are part of the
Same volume group must de identical. VGDA internal architecture and location on the disk depends on the type of the volume group (original, big, or
Scalable).





VGSA (Volume Group Status Area)

Volume group status area (VGSA) is used to describe the state of all physical
Partitions from all physical volumes within a volume group. The VGSA
indicates if a physical partition contains accurate or stale information. VGSA
Is used for monitoring and maintained data copies synchronization. The
VGSA is essentially a bitmap and its architecture and location on the disk
Depends on the type of the volume group.

LVCB (Logical Volume control block)

Logical volume control block (LVCB) contains important information about the
Logical volume, such as the number of the logical partitions or disk allocation
Policy. Its architecture and location on the disk depends on the type of the
Volume group it belongs to. For standard volume groups, the LVCB resides on
The first block of user data within the LV. For big volume groups there is
Additional LVCB information in VGDA on the disk. For scalable volume groups
All relevant logical volume control information is kept in the VGDA as part of
The LVCB information area and the LV entry area.

Quorum

The following commands change the quorum for the volume group testvg. This
Attribute determines if the volume group will be varied off or not after losing the
Simple majority of its physical volumes.

To turn off the quorum use the command:

#chvg -Qn testvg

To turn on the quorum use the command:

# chvg -Qy testvg

Quorum is used for data integrity. When we activate quorum in VG it will recover 51% of data in VG

If we have DATAVG, This DATAVG has two PV’s hdisk1, hdisk2.

First PV hdisk1 has 2 * VGDA and 1 *VGSA

Second PV hdisk2 has 1* VGDA and 1*VGSA

Each VGDA has 33% of data, so hdisk1 has 2 VGDA, it will protect 66% of data and Second PV hdisk2 has 1 VGDA, it will protect only 33% data.