How to create a Linux LVM partition

In Linux, Logical Volume Manager (LVM) manages physical disk drives by using the notion of "logical" volumes. A "volume" could be a partition or an entire disk drive. Among other things, LVM allows you to create one or more logical volumes out of one or more physical volumes, resize logical volumes on-the-fly, and move logical volumes across different physical volumes. Such flexible disk management of LVM is a great advantage as re-partitioning is often necessary while you are running your system. If you would like to try out LVM, here is a 3-minute guide on how to create a Linux LVM partition.

Typically LVM comes with most Linux distros, but to make sure to install a necessary tool for LVM:

$ sudo apt-get install lvm2

First, prepare a physical LVM partition using fdisk. After creating a new partition, make sure to set its partition type to 8e (LVM). Assume that the drive to create a physical LVM partition on is /dev/sdb.

$ sudo fdisk /dev/sdb
[create a LVM partition: /dev/sdb1]

Next, create a LVM physical volume on the prepared partition /dev/sdb1:

$ sudo pvcreate /dev/sdb1

Inside the LVM physical volume, create a LVM volume group called "my_vol" with a physical extent (PE) size of 16MB. Note that PE size needs to be a power of 2.

$ sudo vgcreate -s 16M my_vol /dev/sdb1

Create a 1GB logical volume called drive0 on volume group my_vol:

$ sudo lvcreate -L 1G -n drive0 my_vol

At this point, you will see /dev/my_vol/drive0 which is the device name of the LVM volume you've just created. Finally, proceed to create a filesystem and mount it as follows.

$ sudo mkfs -t ext3 /dev/my_vol/drive0
$ sudo mount -t ext3 /dev/my_vol/drive0 /mnt

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of Xmodulo.com. He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.
Your name can also be listed here. Write for us as a freelancer.

Leave a comment

Your email address will not be published. Required fields are marked *

Current ye@r *