Logical Volume manager (LVM) creates an abstraction layer over physical storage, that allows us to create logical storage volumes. This provides much greater flexibility than using physical storage directly. A logical volume provides storage virtualization. With a logical volumes, you are not restricted to physical disk sizes. In addition, the hardware storage configuration is hidden from the software so it can be resized and moved without stopping applications.
This tutorial has info on how to create Logical volumes & snapshots using LVM commands.
LVM components: This diagram shows the components of LVM.
Initialize physical disks:
To make physical disks as part of LVM, the disks should be initialized first. “pvcreate” command is used to initialize physical disks. Let us say, you have 3 disks (/dev/sdb, /dev/sdc, /dev/sdd) and they are to be added to LVM. Use the pvcreate command as below to initialize the disks.
To list all the physical disks in LVM, you can use “pvdisplay” or “pvs” command.
“vgcreate” command is used to create volume group out of the physical volumes. The vgcreate command creates a new volume group by name and adds at least one physical volume to it. The below command creates a volume group named “vg0” that contains physical volumes /dev/sdb, /dev/sdc and /dev/sdd.
To list all the volume groups created , use “vgdisplay” or “vgs” command.
[root@linux23 ~]# vgdisplay vg0
— Volume group —
VG Name vg0
Metadata Areas 3
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 0
Max PV 0
Cur PV 3
Act PV 3
VG Size 99.84 GB
PE Size 4.00 MB
Logical Volume creation:
To create a logical volume, use the “lvcreate”command. You can create linear volumes, striped volumes, and mirrored volumes. This unixfoo example shows you only the linear logical volumes. Say, let us create a 40G volume of name “myvol01”. The command to create is ..
[root@linux23 ~]# lvcreate -L 40G -n myvol01 vg0
This creates logical volume of name “myvol01” of size “40G” on the volume group vg0. The logical volume can be accessed on device path “/dev/vg0/myvol01”. You can display the properties of this logical volume using “lvdisplay” or “lvs” command. Now this volume is ready for filesystem creation – you can create ext2 or ext3 or any other linux filesystems on this using mkfs comamnd.
Snapshot of a Logical volume:
Snapshots are point-in-time or instantaneous copy of a logical volume. This is very helpful in cases like – instant backup of volume, online and accessible backup of volume, read-only copy of the volume, read-write copy of the volume. If you have a database or application that is running on the volume, the snapshot copy can be even used to debug and replicate the issues that occur on the application.
Snapshot is created using the same “lvcreate” command with “-s” flag. You have to specify the size of snapshot, the snapshot name, parent volume name and volume group. Here is how we create ..
[root@linux23 ~]# lvcreate -s -L 2GB -n myvol_snap /dev/vg0/myvol01.
This creates snapshot volume named “myvol_snap” , and the device path is /dev/vg0/myvol_snap. This is a read-write snapshot copy and you can mount it and read/write/modify the data in it. The data changed in snapshot volume or the parent volume doesnt affect one-other. You can monitor the percentage of snapshot change using “lvdisplay” and “lvs” commands.
Checkout the LVM overview presentation below