Monday, July 26, 2010

LVM Notes (LVM cheat sheet)

Sequence of commands

vgcreate or vgextend


Make a primary partition on the disk with a “partition's system id” of 8e.
Command (m for help): p

Disk /dev/sdi: 36.4 GB, 36420075008 bytes
255 heads, 63 sectors/track, 4427 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdi1               1        4427    35559846   8e  Linux LVM

Physical Volumes

To list physical volumes and associated info…
To prepare partitions for LVM
pvcreate /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
To prepare a single drive to “add” to an LVM
pvcreate /dev/sdi1
To remove a volume(s)…
pvremove /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1

Volume Group

To list volume groups…
To list volume groups and associated info…
To create a new volume group…
vgcreate VolGroup00 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
To add physical volumes to an existing volume group…
vgextend VolGroup00 /dev/sdh1 /dev/sdi1
To remove a physical volume from a volume group…
vgreduce VolGoup00 /dev/sdi1
To rename a volume group…
vgrename VolGroup00 MeaningfulName
To remove a volume group…
vgremove MeaningfulName

Logical Volumes

To list logical volumes…
To list logical volumes and associated info…
To create a logical volume…
lvcreate --name backup --size 40G VolGroup00
To rename a logical volume…
lvrename VolGroup00 backup webspace
To delete a logical volume…
lvremove /dev/VolGroup00/webspace
To enlarge a logical volume (to 50G)…
lvextend -L50G /dev/VolGroup00/webspace
To shrink a logical volume (to 40G)…
lvreduce -L40G /dev/VolGroup00/webspace