Intro
Requirements:
- To use lvm we require a partition or entire disk (we will go with partitions).
- Use
fdsikor similar kind of program to partition your disk.
Steps:
- Create physical volumes from disk partitions
- Create volume groups from physical volumes
- Create logical volumes from volume groups
Physical Volumes:
Listing Volumes:
PV VG Fmt Attr PSize PFree DevSize PV UUID
/dev/sda3 dev lvm2 a-- 100.00m 100.00m 102.10m K0W4kZ-gqDT-EFXj-sWta-xYG2-Pkp2-2gBpr1
Output:
PV- Partition/Device name of Physical volume.VG- Name of volume group.Fmt- Format of physical volume.Attr- (a) allocatable, (x) exported.PSize- Total physical volume size.PFree- Total physical volume free space available.DevSize- Device/Partion size.PV UUID- Unique identifier for physical volume.
Commonly used options:
-o- Stands for options, it can list many options, seepvs -o -h.--separator- To separate each column.--segments- Shows starting segment and length of segment (unit is physical extends).
Create Volumes:
pvcreate <partion_or_device_name>
pvcreate /dev/sda3
Commonly used options:
--uuid- Provide a unique identifier.-M2- Create a LVM2 format physical volume.- This is displayed by
pvsoutput fieldFmt.
- This is displayed by
--metadatasize- Padding size for each metadata.--pvmetadatacopies- Number of metadata to be set aside on each physical volume.--setphysicalvolumesize- Set a physical volume size.
Remove Volumes:
pvremove <partion_or_device_name>
pvremove /dev/sda3
Resize Volumes:
pvresize <partion_or_device_name>
pvresize /dev/sda3
Scan Volumes:
pvscan
Move Volumes:
pvmove <partion_or_device_name>
pvmove /dev/sda3 /dev/sda4
Volume Groups:
Listing Volumes:
VG Attr Ext #PV #LV #SN VSize VFree VG UUID VProfile
dev wz--n- 4.00m 1 0 0 100.00m 100.00m 5gx2Ug-2TjU-t1YF-eTpe-ruRq-60OL-4Hpn5l
Output:
VG- Name of the volume group.Attr- Attribute options are as follows:- permissions (r)|(w)
- resi(z)eable
- e(x)ported
- (p)artial
- allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
- (c)luster
#PV- Number of physical volumes.#LV- Number of logical volumes.VSize- Total size of volume group.VFree- Total free space on volume group.VG UUID- Unique identifier for volume group.
Commonly used options:
-o- Stands for options, it can list many options, seevgs -o -h.--separator- To separate each column.
Create Volumes:
vgcreate <group_name> <partion_or_device_name>
vgcreate dev /dev/sda3
Commonly used options:
-l- Set maximum logical volumes.-p- Set maximum physical volumes.-s- Set physical extent size (default is 4MB).-A- Autobackup.
Remove Volumes:
vgremove <group_name>
vgremove dev
Extend Volumes:
vgextend <group_name> <partion_or_device_name>
vgextend dev /dev/sda4
Reduce Volumes:
vgreduce <group_name> <partion_or_device_name>
vgreduce dev /dev/sda4
Rename Volumes:
vgrename <group_name> <new_group_name>
vgrename dev devops
Merge Volumes:
vgmerge <new_group> <old_group>
vgmerge devops dev
Split Volumes:
vgsplit <old_group> <new_group>
vgsplit dev devops
Scan Volumes:
vgscan
Logical Volumes:
Listing Volumes:
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
qa dev -wi-a----- 12.00m
Output:
LV- Name of logical volume.VG- Name of volume group.Attr- Attribute options are as follows:- volume type: (m)irrored, (M)irrored without initail sync, (o)rigin, (p)vmove, (s)napshot, invalid (S)napshot, (v)irtual, mirror (i)mage, mirror (I)mage out-of-sync, under (c)onversion
- permissions: (w)rite, (r)ead-only
- allocation policy - (c)ontiguous, c(l)ing, (n)ormal, (a)nywhere, (i)nherited
- fixed (m)inor
- state: (a)ctive, (s)uspended, (I)nvalid snapshot, invalid (S)uspended snapshot, mapped (d)evice present with-out tables, mapped device present with (i)nactive table
- device (o)pen (mounted in other words)
LSize- Total size of logical volume.
Commonly used options:
-o- Stands for options, it can list many options, seelvs -o -h.--separator- To separate each column.--segments- Shows starting segment and length of segment (unit is physical extends).
Create Volumes:
lvcreate <volume_name> <group_name>
lvcreate -L 10M -n qa dev
Commonly used options:
-L- Size of the volume [kKmMgGtT]-l- Number of extents-C- Contiguous [y|n]-i- Stripes-I- Stripe size-m- Mirrors-n- Volume name
Remove Volumes:
lvremove <group_name> <volume_name>
lvremove dev qa
Extend Volumes:
lvextend <group_name> <volume_name>
lvextend -L 10M dev qa
Commonly used options:
-L- Size of the volume [kKmMgGtT]-l- Number of extents-C- Contiguous [y|n]-i- Stripes-I- Stripe size
Reduce Volumes:
lvreduce <group_name> <volume_name>
lvreduce -L 5M dev qa
Resize Volumes:
lvresize <group_name> <volume_name>
lvresize -L 5M dev qa
Scan Volumes:
lvscan
Rename Volumes:
lvrename <old_volume_name> <new_volume_name>
lvrename qa development