LVM Setup
LVM (Linux's Logical Volume Manager) is an abstraction layer between your physical disks and your partition mapping. It allows you to do things such as resize partitions, migrate partitions between disks, create snapshots of partitions, and much more. This page documents some of the common tasks which I do with LVM.
Create a physical volume on the specified partition. One or more physical volumes are used to host a volume group.
pvcreate /dev/sda1
Create a volume group named 'vgfoo' on the physical volume '/dev/sda1'.
vgcreate vgfoo /dev/sda1
Create a logical volume of size 10 GB, named 'lvbar', on the volume group 'vgfoo'
lvcreate -L 10G -n lvbar vgfoo
Resize (increase in size) by 10GB logical volume lvbar, on volume group vgfoo, which contains an EXT 4 filesystem. You can do this online without the need to unmount the partition.
lvextend -L +10G /dev/vgfoo/lvbar
resize2fs /dev/vgfoo/lvbar
Resize (decrease in size) to 5GB logical volume lvbar, on volume group vgfoo, which contains an EXT 4 filesystem.
umount /dev/vgfoo/lvbar
e2fsck -f /dev/vgfoo/lvbar
resize2fs -p /dev/vgfoo/lvbar 4G #Here I make this smaller than the end result, so that I can shrink the LVM and then grow the file system to fill all available size. This is probably not needed. Ensure that you are not using more space than this amount (use df).
lvreduce -L 5G /dev/vgfoo/lvbar
e2fsck -f /dev/vgfoo/lvbar
resize2fs /dev/vgfoo/lvbar #Without a size argument, the filesystem will grow to fit the logical volume size.
e2fsck -f /dev/vgfoo/lvbar
mount /dev/vgfoo/lvbar