Logical Volume Manager
From Christoph's Personal Wiki
This article will explain how to use the Logical Volume Manager (LVM) in Linux.
Note: This article will cover how to use LVM under RedHat-style distros. Everything was tested using CentOS 6.5.
Logical volume stack
I like to think of logical volumes as a stack, with the physical part on the bottom and you are stacking each element on top:
filesystem (FS) Logical volume (LV) Volume group (VG) Physical volume (PV)
Another way to visualize this is like so (adapted {and inverted} from Erik Bågfors' diagram):
ext4 ext4 (filesystems) | | rootlv homelv (LVs) \ / \ / diskvg (VG) / \ / \ xvdb1 xvdb2 (PVs; on partitions or whole disks)
Examples
Creating a logical volume
- Prepare a physical volume:
$ fdisk -cu /dev/xvde $ pvcreate /dev/xvde1 $ pvdisplay /dev/xvde1 $ pvs
- Create a volume group:
$ vgcreate vgname /dev/xvde1 $ vgdisplay vgname $ vgs
- Create and use a new logical volume:
$ lvcreate -n lvname -L 1G vgname $ lvdisplay /dev/vgname/lvname $ lvs $ ls -l /dev/vgname/lvname $ #~OR~ $ ls -l /dev/mapper/vgname-lvname
- Make a filesystem (
ext4
in this example) inside the above logical volume:
$ mkfs.ext4 /dev/vgname/lvname
- Test mount it:
$ mkdir /data $ mount /dev/vgname/lvname /data $ umount /data # un-mount it before proceeding
- Make it persistent by adding the following line to your
/etc/fstab
file and test mount it (again):
/dev/mapper/vgname-lvname /data ext4 defaults 1 2 $ mount -a
External links
- LVM HOWTO — by The Linux Documentation Project (TLDP)