AIX LOGICAL VOLUME MANAGER (LVM)
- Each individual fixed-disk drive is called a physical volume (PV).
- All physical volumes belong to one volume group (VG) named rootvg.
- All of the physical volumes in a volume group are divided into physical partitions (PPs) of the same size.
- Within each volume group, one or more logical volumes (LVs) are defined.
- Logical volumes are groups of information located on physical volumes.
- Each logical volume consists of one or more logical partitions (LPs).
- Each logical partition corresponds to at least one physical partition.
Before you can start using Logical Volume Manager you must understand the basic mechanics and terminology.
The vary-on process is one of the mechanisms that the LVM uses to ensure that a volume group is ready to use and contains the most up-to-date data. The varyonvg and varyoffvg commands activate or deactivate a volume group that you have defined to the system.
If the vary-on operation cannot access one or more of the physical volumes defined in the volume group, the command displays the names of all physical volumes defined for that volume group and their status. This helps you decide whether to vary-off this volume group.
Two important thing you should know:-
/var/adm/ras/lvmcfg.log lvm log file shows what lvm commands were used
(alog -ot lvmcfg)
alog -ot lvmt shows lvm commands and libs
There are limitations that you have to be aware of, which are listed in table-
|VG type||Maximum PVs||Maximum LVs||Maximum PPsper VG||Maximum PP size|
|Normal VG||32||256||32512 (1016*32)||1 GB|
|Big VG||32||128||130048(1016*128)||1 GB|
|Scalable VG||1024||4096||2097152||128 GB|
Physical Volumes (PV):
When a disk drive is initially added to the system, it is seen a simple device. The disk is not yet accessible for LVM operations. To be made accessible, it has to be assigned to a volume group, which means changing from a disk to a physical volume. For each disk, two device drivers will be created under the /dev directory: one block device driver and one character device driver. The disk drive is assigned an 32-bit unique identifier that is called a physical volume identifier (PVID).
- Two disks would never have the same PVID.
- The PVIDs are stored also in ODM.
- They are used by LVM commands and external applications such as HACMP.
- command changes an available disk device to a physical volume by assigning a PVID
#chdev -l <hdiskname> -a pv=yes( for clearing PV use pv=clear)
Listing information about physical volumes
# lspv hdisk2
PHYSICAL VOLUME: hdisk2 VOLUME GROUP: testvg
PV IDENTIFIER: 00c478de09caf37f VG IDENTIFIER 00c478de00004c00000001078fc3497d
PV STATE: active
STALE PARTITIONS: 0 ALLOCATABLE: yes
PP SIZE: 128 megabyte(s) LOGICAL VOLUMES: 1
TOTAL PPs: 546 (69888 megabytes) VG DESCRIPTORS: 2
FREE PPs: 542 (69376 megabytes) HOT SPARE: no
USED PPs: 4 (512 megabytes) MAX REQUEST: 256 kilobytes
FREE DISTRIBUTION: 110..105..109..109..109
USED DISTRIBUTION: 00..04..00..00..00
# lspv -l hdisk0
option → -M ( it is used to display the layout of a physical volume)
Changing the allocation permission for a physical volume-
if physical partitions located on that physical volume, which have not been allocated to a logical volume yet, can be allocated to logical volumes.
To turn on the allocation permission, use the following command:
#chpv -ay hdisk2
Changing the availability of a physical volume-
# lsvg testvg ( shows that the VG is active, contains two PVs, both PVs are active, and the VG has three VGDAs.)
options–> -p (shows all hdisk and it status)
# lspv hdiskn ( shows that hdisk3 is active and has two VGDAs)
# chpv -vr hdisk3 ( makes hdisk3 unavailable.)
# chpv -va hdisk3 ( makes hdisk3 available again)
Cleaning the boot record from a physical volume-
#chpv -c <hdiskname> ( To clear the boot record located on physical volume)
Declaring a physical volume hot spare-
#chpv -hy hdiskn ( To define hdisk3 as a hot spare)
#chpv -hn hdiskn ( To remove hdisk3 from the hot spare pool of its volume group)
Migrating data from physical volumes-
# lsvg -p rootvg ( displays all PVs that are contained in rootvg.)
# lsvg -M <hdiskname> ( displays the map of all physical partitions located on <hdiskname>.)
# lsvg -M <hdiskname> ( shows that all partitions of <hdiskname> are not allocated.)
# migratepv <hdiskname> <hdiskname>( migrates the data from <hdiskname> to <hdiskname>)
# lspv -M <hdiskname> ( confirms that <hdiskname> has all partitions free.)
# chpv -c <hdiskname> ( clears the boot record from <hdiskname>.)
# lspv -M <hdiskname> ( confirms that all physical partitions have been migrated to <hdiskname>.)
# migratelp testlv/1/2 <hdiskname>/123 ( migrates the data from the second copy of the logical partition number 1 of logical volume to <hdiskname> on physical partition 123.)
Finding the LTG size-
# lquerypv -M hdisk0 ( Logical track group (LTG) size is the maximum allowed transfer size for an I/O disk operation.)
O/p → 256
Volume Groups (VG):
When the operating system is installed, one volume group named rootvg is created by default.
Additional volume groups can be created on the system using one or more physical volumes that have not been allocated to other volume groups yet and are in an available state. All physical volumes will be divided in physical partitions having the same size. The size of the physical partitions cannot be changed after the volume group is created.
Basic Commands for VG:
# lsvg -o
# lsattr -El hdiskn
Creating an original volume group :-
# mkvg -y vg1 -s64 -V99 hdiskn
O/p → vg1
Suppose if vg creating fails
# mkvg -y testvg -s 4 -f <hdiskname>
0516-1254 mkvg: Changing the PVID in the ODM.
0516-1208 mkvg: Warning, The Physical Partition Size of 4 requires the
creation of 17501 partitions for <hdiskname>. The system limitation is
physical partitions per disk at a factor value of 16. Specify a larger
Physical Partition Size or a larger factor value in order create a
volume group on this disk.
0516-862 mkvg: Unable to create volume group.
Creating a big volume group and Scalable volume group:-
# mkvg -B -y vg2 -s 128 -f -n -V 101 <hdiskname>
O/p → vg2
Options -S is used to for Scalable VG
# mkvg -S -y vg2 -s 128 -f -n -V 101 <hdiskname> <hdiskname> <hdiskname> <hdiskname>
O/p → 0516-1254 mkvg: Changing the PVID in the ODM.
0516-1254 mkvg: Changing the PVID in the ODM.
0516-1254 mkvg: Changing the PVID in the ODM.
0516-1254 mkvg: Changing the PVID in the ODM.
Suppose if it fails, it give the same o/p will print.
The mkvg command will automatically vary on the newly created volume group by calling the varyonvg command.
Changing volume group characteristics:-
Command changes the volume group testvg to be activated automatically the next time the system is restarted.
# chvg -ay newvg
Command changes the volume group testvg to not be activated automatically next time the system is restarted.
# chvg -an newvg
The quorum is one of the mechanisms that the LVM uses to ensure that a volume group is ready to use and contains the most up-to-date data.
Nonquoram Volume Group:-
The Logical Volume Manager (LVM) automatically deactivates the volume group when it lacks a quorum of Volume Group Descriptor Areas (VGDAs) or Volume Group Status Areas (VGSAs). However, you can choose an option that allows the group to stay online as long as there is one VGDA/VGSA pair intact. This option produces a nonquorum volume group.
To turn off the quorum, use the command:
#chvg -Qn testvg
To turn on the quorum, use the command:
# chvg -Qy testvg
Changing a volume group format:-
You can change the format of an original volume group to either big or scalable. Once the volume group has been converted to a scalable format, it cannot be changed into a different format.Type
# varyoffvg xyz
# chvg -G xyz
The chvg -G command is use to change the format of the volume group tttt from original to scalable.
# varyonvg xyz
Changing LTG size:-
volume groups in AIX 5L Version 5.3 are created with a variable logical track group size. For volume groups created to be compatible with a previous version of AIX 5L, you can change the LTG size to 0, 128, 256, 512, or 1024. The new LTG size should be less than or equal to the smallest of the maximum transfer size of all disks in the volume group. You can change the LTG size for the testvg volume group using the following command.
# chvg -L 128 testvg
Changing the hot spare policy:-
To improve data availability, one or more disks from a volume group can be designated as hot spares. Physical volumes that are to be used as a hot spare must have all physical partitions free. All logical volumes from the volume group that contain hot spare disks must be mirrored
# chpv -hy hdiskn( tries to designate <hdiskname> as a hot spare)
# chvg -hy test1v( changes the hot spare policy of the volume group to migrate data from a failing disk to one spare disk)
options → -Y ( changes the hot spare policy of the volume group to migrate data from a failing disk to the entire pool of spare disks)
-n ( disables the hot spare policy of the volume group)
-sy (Changing synchronization policy of a volume group)
-P ( the -P option in chvg command to change the maximum number of physical partitions within a volume group)
-v ( the -v option in chvg command to change the maximum number of logical volumes within a volume group)
-u( You can remove the lock using -u option)
# lsvg -p test1vg ( displays physical volumes that are part of test1vg)
Extending a volume group:-
You can increase the space available in a volume group by adding new physical volumes using the extendvg command. Before adding a new disk, you have to ensure that the disk is in an available state. If the disk has one VGDA corresponding to another already varied on volume group, the command exits. If the VGDA belongs to a volume group that is varied off, the system will prompt the user for confirmation in continuing with command execution. If the user says yes, the old VGDA is erased and all previous data on that disk will be unavailable.
How to Extend VG:-
# extendvg test1vg <hdiskname> (lets suppose x is the disk which you have added)
O/p → 0516-1254 extendvg: Changing the PVID in the ODM.
Assigns an PVID to <hdiskname>and adds it to the volume group test1vg.
Options- -f ( forcibly adds hdisk to volume group )
Reducing a volume group:-
The volume group must be varied on. When you remove the last physical volume from the volume group, the VG will also be removed. For volume groups created on AIX 5L Version 5.3 and varied on without using varyonvg -M reducevg will dynamically raise the LTG size if the remaining disks permit it.
# reducevg -f testvg <hdiskname> ( prompts the user for confirmation, deletes the data located on physical volume <hdiskname>, and removes the disk definition from the testvg volume group. lets y is any number of disk)
Resynchronizing the device configuration database:-
# synclvodm testvg
Exporting a volume group & Importing a volume group-
There are situations when all data from a volume group needs to be moved from one system to another system. You will need to delete any reference to that data from the originating system
The exportvg command only removes volume group definition from the ODM and does not delete any data from the physical disks. It clears the stanzas from /etc/filesystem
Importing a volume group means recreating the reference to the volume group data and making that data available. The importvg command reads the VGDA of one the physical volumes that are part of the volume group. It uses redefinevg to find all other disks that belong tothe volume group.It will add corresponding entries into the ODM database and update /etc/filesystems.
To export the volume group testvg, use the command
# exportvg testvg
To import the volume group testvg, use the command
# importvg -y testvg <hdiskname>
O/p → 0516-530 synclvodm: Logical volume name test1lv changed to fslv02.
0516-530 synclvodm: Logical volume name loglv00 changed to loglv01.
imfs: Warning: mount point /testmp already exists in /etc/filesystems.
# lsvg -l test1vg
An imported volume group is automatically varied on, unless it is concurrent capable.
inter-physical volume allocation policy, can be minimum or maximum
minimum: to allocate pp’s the minimum pv will be used (not spreading to all pv’s tha data if possible)
maximum: to spread the physical partitions of this logical volume over as many physical volumes as possible.
This illustration shows 2 physical volumes. One contains partition 1 and a copy of partition 2. The other contains partition 2 with a copy of partition 1. The formula for allocation is Maximum Inter-Disk Policy (Range=maximum) with a Single Logical Volume Copy per Disk (Strict=y).
each lp copy on separate pv The strictness value. Current state of allocation, strict, nonstrict, or superstrict. A strict allocation states that no copies for a logical partition are allocated on the same physical volume. If the allocation does not follow the strict criteria, it is called nonstrict. A nonstrict allocation states that copies of a logical partition can share the same physical volume. A superstrict allocation states that no partition from one mirror copy may reside the same disk as another mirror copy. (mirror 2 and mirror 3 cannot be on the sam edisk)
So inter-policy and strictness have effect together how many disks are used: spreading to maximumdisks (1st lps) then mirroring them we need another bunch of disks; however spreading to minimum disks and mirroring, we need less disks.
Intra-physical volume allocation policy, it specifies what startegy should be used for choosing pp‘s on a pv.it can be: edge (outer edge), middle (outer middle), center, inner middle, inner edge. If you specify a region, but it gets full, further partitions are allocated from near as possible to far away. The more i/o-s used, the pp‘s should be allocate to the outer edge.
Reorganizing a volume group:-
The reorgvg command is used to reorganize physical partitions within a volume group.
To reorganize only logical volumes lv1 and lv1 from volume group testvg, use:
# reorgvg testvg lv1 lv2
To reorganize only partitions located on physical volumes <hdiskname> and <hdiskname> that belong to logical volumes lv1 and lv2 from volume group testvg, use:
echo “<hdiskname> <hdiskname>” | reorgvg -i testvg lv1 lv2
Synchronizing a volume group:-
The syncvg command is used to synchronize stale physical partitions. It acceptsnames of logical volumes, physical volumes, or volume groups as parameters.The synchronization process can be time consuming, depending on the hardware characteristics and the total amount of data.
To synchronize the copies located on physical volumes <hdiskname> and <hdiskname>, use:
#syncvg -p <hdiskname> <hdiskname>
To synchronize the all physical partitions from volume group testvg, use:
#syncvg -v testvg
Mirroring a volume group:-
You can use the mirrorvg command to mirror all logical volumes within a volume group.
# extendvg rootvg hdiskA
# mirrorvg rootvg
Op → 0516-1124 mirrorvg: Quorum requirement turned off, reboot system for thisto take effect for rootvg.
0516-1126 mirrorvg: rootvg successfully mirrored, user should perform
bosboot of system to initialize boot records. Then, user must modify
bootlist to include: hdisk0 <hdiskname>.
# bosboot -ad /dev/hdiskA
# bootlist -m normal hdiskA hdiskB
# lsvg -l rootvg
Logical Volumes (LV):
Logical volumes provide applications with the ability to access data as though it was stored contiguously. A logical volume consists of a sequence of one or more numbered logical partitions. Each logical partition has at least one and a maximum of three corresponding physical partitions that can be located on different physical volumes. The location on the disk for physical partitions is determined by intra-physical and inter-physical allocation policies.
Notes: When the system is installed, the root volume group (rootvg) is created. This is where the AIX operating system files will be contained. Additional disks can either be added to rootvg or a new volume group can be created for them. There can be up to 255 VGs per system.
If you have external disks, it is recommended that they be placed in a separate volume group. By maintaining the user file systems and the operating system files in distinct volume groups, the user files are not jeopardized during operating system updates, reinstallations, and crash recoveries.
Maintenance is easier because you can update or reinstall the operating system without having to restore user data. For security, you can make the volume group unavailable using varyoffvg.
Logical Volume types:
1. log logical volume: used by jfs/jfs2
2.dump logical volume: used by system dump, to copy selected areas of kernel data when a unexpected syszem halt occurs
3. boot logical volume: contains the initial information required to start the system
4. paging logical volume: used by the virtual memory manager to swap out pages of memory users and appl.-s will use these lvs:
5. raw logical volumes: these will be controlled by the appl. (it will nit use jfs/jfs2)
6. journaled filesystems:
Striped logical volumes:-Helps I/O capacity of the physical volumes to be used in parallel to access the data.
LVCB (Logical Volume Control Block):-He LVCB stores the attributes of the LV. Jfs does not access this area.Traditionally it was the fs boot block of 512 bytes.
# getlvcb -AT <lvname>
Creating a new log logical volume:
You can create logical volumes using the mklv command.
# mklv -y lv3 -t jfs2 -a lvname vgname 1 pvname (creates the log lv)
# logform -V jfs2 /dev/lvname (used to create logfile )
# chfs -a log=/dev/lvname /fsname(changes the log lv (it can be checked in /etc/filesystems)
Removing a logical volume:-
# rmlv lvname (prompts for user confirmation and then deletes lv.)
# umount /fs ( closes lv)
# rmlv -p hdiskname lvname (tries to delete partitions of lv1 located on hdisk7 and prompts for user confirmation. and completes successfully..)
# lslv -l lv1 (confirms that physical partitions of lv located on hdisk were deleted.)
Listing information about logical volumes:-
# lslv -l lv1
O/p → lv1:/fs1
PV COPIES IN BAND DISTRIBUTION
hdisk5 009:000:000 66% 000:003:000:000:006
hdisk6 009:000:000 66% 000:003:000:000:006
# lsvg -p testvg
O/p → testvg:
PV_NAME PV STATE TOTAL PPs FREE PPs FREE DISTRIBUTION
hdisk5 active 273 266 55..48..54..54..55
hdisk6 active 273 273 55..55..54..54..55
hdisk7 active 273 266 55..48..54..54..55
# lslv -m testlv
O/p → testlv:/test
LP PP1 PV1 PP2 PV2 PP3 PV3
0001 0056 hdisk5 0059 hdisk7
0002 0057 hdisk5 0060 hdisk7
0003 0058 hdisk5 0061 hdisk7
# lslv -n hdisk6 testlv
# getlvcb -AT lv1( You can display the LVCB of a logical volume using intermediate level)
Increasing the size of a logical volume:-
Additional logical partitions can be added to an already existing logical volume using the extendlv command. By default, the logical volume is expanded while preserving its characteristics. The initial characteristics of the whole volume group will remain unchanged. You can specify one or multiple disks. You can also specify blocks whose size is measured in KB, MB, or GB.
# extendlv -a ie -ex lv1 3 hdisk5 hdisk6
# lslv -l lv1
Copying a logical volume:-
You can copy the content of a logical volume to either a new or an already existing logical volume.
# cplv -v dumpvg -y lvA lvB
Creating copies of logical volumes
We used the mklvcopy command to create and synchronize one extra copy of each of the logical partitions of logical volume
# mklvcopy -k lv1 3 hdisk7 &
# lslv -m lv1
Changing characteristics of logical volumes:-
We use the chlv command to change, for logical volume lv1, the maximum number of logical partitions to 1000 and the scheduling policy for I/O operations to parallel/round-robin.
# chlv -x 1000 -d pr lv1
# lslv lv1
Splitting a logical volume:-
You can use the splitlvcopy command to split a logical volume that has at least two copies of each logical partition into two different logical volumes. If the original logical volume contains a file system, the data from the newly created logical volume will have to be accessed as a different file system.
# umount /test (closes logical volume testlv.)
# splitlvcopy -y copylv testlv 2 (splits the logical volume.)
# crfs -v jfs2 -d /dev/copylv -m /copy ( creates the file system structure for copylv. Note that this command will destroy any file system data.)
# lsvg -l testvg
# lslv -m testlv
# lslv -m copylv
If you want to maintain the file system data on the original logical volume, instead of running the crfs command in the last step, perform the following:
# mkdir /copy (creates a copy directory.)
#mount /dev/copylv /copy (mounts the copied file system.)
Edit the /etc/filesystems file manually and add an entry for the /copy mount point.
Removing a copy of a logical volume:-
You can use the rmlvcopy command to remove copies of logical partitions of a logical volume
# rmlvcopy testlv 2 hdisk6 ( removes copies located on hdisk6 and leaves two mirror copies.)
# lslv -m testlv ( shows that testlv now has two mirror copies located on hdisk5 and hdisk7.)