How to create a Linux LVM partition

Last updated on July 6, 2020 by Dan Nanni

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. If you are interested, you can always read a more detailed tutorial on LVM.

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

If you want to have the LVM partition mounted permanently across reboots, refer to this tutorial.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean