This post describes what is LVM (Logical Volume Manager) in Linux and how to create Logical volumes.
LVM is a higher level layer of abstraction then traditional linux disk and partitions. This allows for greater flexibility in allocating storage. Logical volumes can be resized and moved between physical devices easily. Physical devices can be added and removed with relative ease. LVM managed volumes can also have sensible names like “database” or “home” rather then somewhat cryptic “sda” or “hda” device names.
As shown in above figure,
Devices are designated as Physical Volume
One or more physical volumes are used to create volume group
Physical volumes are defined with Physical extents of a fixed size
Logical volumes are created on volume group and are composed of physical extents
File system may be created on Logical Volume
Creating Logical Volume
Creating Logical volume is a 6 step process
1) Create a partitions of the type Linux LVM. The code for this is 8e. For details about creating partitions check the previous post Creating Partition and Filesystem in Linux.
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 123 987966 8e Linux LVM
/dev/sdb2 124 246 987997+ 8e Linux LVM
/dev/sdb3 247 369 987997+ 8e Linux LVM
/dev/sdb4 370 652 2273197+ 5 Extended
/dev/sdb5 370 492 987966 8e Linux LVM
/dev/sdb6 493 615 987966 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
run partprobe command for kernel to read the partition table
[root@localhost ~]# partprobe
Warning: Unable to open /dev/hdc read-write (Read-only file system). /dev/hdc has been opened read-only. [root@localhost ~]# cat /proc/partitions
major minor #blocks name
2) Create a phyical volume out of these partitions
[root@localhost ~]# pvcreate /dev/sdb1
Physical volume “/dev/sdb1″ successfully created [root@localhost ~]# pvcreate /dev/sdb2
Wiping software RAID md superblock on /dev/sdb2
Physical volume “/dev/sdb2″ successfully created [root@localhost ~]# pvcreate /dev/sdb3
Wiping software RAID md superblock on /dev/sdb3
Physical volume “/dev/sdb3″ successfully created
3) Create a volume group using these physical volumes
[root@localhost ~]# vgcreate vg0 /dev/sdb1 /dev/sdb2
Volume group “vg0″ successfully created
4) Create a logical volume from this volume group
[root@localhost ~]# lvcreate -L 512M -n data vg0
Logical volume “data” created
5) Formatting the logical volume
[root@localhost ~]# mkfs.ext3 /dev/vg0/data
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
131072 inodes, 524288 blocks
26214 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67633152
64 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409
It would have been better if youu explain the parameters used in the command like L and n
“”lvcreate -L 512M -n data vg0 “”"
4) Create a logical volume from this volume group
[root@localhost ~]# lvcreate -L 512M -n data vg0
Logical volume “data” created
Thanks a lot for your post.. It was very useful for me.. It’s in my bookmarks now.
Best Regards