LVM - Logical Volume Management
If you've ever wondered how you could rebuild the filesystem and disk parts of your computer without having to redo everything, LVM is the answer.
Explained most simply, LVM is what is used to allow your Linux operating system to access the hard drive partitions through a layer that is flexible enough to be changed without requiring changes to the structures actually stored on the disk.
You can do the following things with LVM:
- Add more drive space to an existing system
- Reapportion space when necessary, taking away from one and giving to another.
- Protect your data with RAID
- Combine multiple physical drives into a single system
This topic deserves more discussion which I will be adding shortly -BMC
Logical Volume Management is one way of virtualizing resources. See the discussion on Virtualization for more general information.
How LVM works
LVM consists of three manageable sections:
- Physical Extents - resources allowed for use with LVM
- Volume Groups - groupings of physical extents to create virtual drives
- Logical Volumes - virtual partitions
It is possible to combine drives and partitions in pretty much any way imaginable and treat them as a single drive or split them into virtual drives. The Physical Extents create managed sections that can be managed at the most basic layer. Think of it as virtual drive blocks. The Volume Groups create what are best thought of as virtual hard drives and at the last layer, the Logical Volumes are virtual partitions.
These separations give administrators the ability with Physical Volumes to move data between sets of blocks and to optimize those blocks without requiring modifications to the systems using them. Further with Volume Groups, the system can combine, do basic RAID, or split the physical extents into virtual drives. Finally, the Logical Volumes can be used as virtual partitions, but expanded or contracted to match the changing layer below.
Carving off some free space
Evaluating available space
# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 74.43 GB / not usable 22.62 MB Allocatable yes PE Size (KByte) 32768 Total PE 2381 Free PE 1688 Allocated PE 693 PV UUID iWzGoN-N7de-wkxA-HhLf-cqy3-8l73-jr4l05
Note the PE Size. This is the size of the "Physical Extents" or physical sections assigned to this volume group. The Free PE are the physical extents that are available to be assigned to something new and by multiplying the space per extent by the numbers of extents, you can determine how much space is available to be assigned.
In this example, there are 52GB of unassigned space.
To create a logical volume of 10GB carved out of volume group VG00 with a name of mylv:
lvcreate -L 10G -n mylv VG00
Don't forget to activate the LVMs with lvchange -a y /dev/LogVol/whatever
Really short cut
Shrinking
- mount device to be resized from an inactive state (alt os) and take measurements of free space, multiply space used by 120% for space needed. Compare space needed to space available, and shrink only if the resulting size will be smaller than the current size
- consider the physical space, make sure that there is plenty of available space
- umount the device, and if ext3, run:
- fsck -n /dev/path
- tune2fs -O ^has_journal /dev/path
- e2fsck -f /dev/path
- resize2fs /dev/path 10G
''Where you want the resulting partition to be slightly larger than 10G
- resize the LVM with lvresize to larger than the current file system
- * resize again with resize2fs if using ext3