LVM Series – Quick LVM example

LVM series continues. If you want to start from the beginning, check our first post.
In this post we will show you a quick example to begin the series and/or to show you how to quickly mount an EXT4 filesystem with LVM, if that is what you need.
Let’s remind you that you should work on a virtual machine or a test machine to avoid damage on a working computer.
Let’s also remember that all sentences have to be executed as root or with ‘sudo’ as one of the administrator users.

Initializing a Physical volume (PV)

We will start with a physical unit that we are not using, in this example /dev/sdb.
To perform this operation we need to use “pvcreate” tool:

pvcreate /dev/sdb

PV is ready to be added to a VG.

Creating a Volume Group (VG)

Next, we create a Volume Group using the PV we just created. We will need “vgcreate” tool.
This VG will be named vg_lvmseries

vgcreate vg_lvmseries /dev/sdb

Creating a Logical Volume (LV)

Now we are going to prepare a Logical Volume in the previously created VG. We will need “lvcreate” for this.
It will be named lv_test and it will have 1GB size. Note that the storage unit /dev/sdb must have 1GB or more space available.

lvcreate -L1G -n lv_test vg_lvmseries

Formating LV as EXT4 and mounting it

We want to create an EXT4 filesystem in the LV.

mkfs.ext4 /dev/vg_lvmseries/lv_test

Finally, we need to mount it to be able to use it. Let’s do that in /mnt/test.

mount /dev/vg_lvmseries/lv_test /mnt/test

In this screenshot you can find the whole example:

If something is not clear for you, or you just want to go deeper in LVM, you can go further in this series.
We will continue our LVM series with Volume Group Management.

Leave a Reply

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