LVM series continues. If you want to start from the beginning, check our first post. You can check our last post about VG Management.
Let’s start working with logical volumes. From the sysadmin point of view, it’s quite similar to work with logical volumes or with physical volumes.
It is important to point out that you need to be careful if you want to increase or decrease a LV that you are using. Please, keep going on LVM series to learn how to accomplish that depending on your filesystem.
Creating a Logical Volume (LV)
First, we need to decide the Volume Group where we are going to create the LV. You can check your VG info as seen in the previous post.
Once you have decided the VG where you are creating this LV, use “lvcreate” to make in happen.
In this example, we are creating a lv_database in vg_storage1 and with 3 GB size.
lvcreate -L3G -n lv_database vg_storage1
Info about LVs
To review the information about LV we have “lvdisplay” tool.
To gather the info about a concrete LV, for instance lv_database:
lvdisplay /dev/vg_storage1/lv_database
Increasing the size of a LV
To increase the size of a LV we use “lvextend“.
Let me remind you that if you want to increase a LV, you probably are already using it, so it is really important to know how to do this in the correct order. Please, follow up with the LVM series to learn how to do this.
Increasing LV size up to a given total
In this case we want LV to increase up to the given total. For instance, we are raising lv_database up to 12 GB.
lvextend -L12G /dev/vg_storage1/lv_database
Increasing LV size a concrete amount.
Now we want LV to increase the given amount of space.
We are raising the size of lv_database in 2 GB.
lvextend -L+2G /dev/vg_storage1/lv_database
Anyway, you must check if there is enough space available in the VG, check VG Management post for more info.
Decreasing LV size
To decrease a LV we will use “lvreduce“.
Don’t forget that if you want to decrease a LV, you probably are already using it, so it is really important to know how to do this in the correct order. Please, follow up with the LVM series to learn how to do this.
Decreasing LV size up to a given total
As seen in the last section, we want to reduce up to the given total.
Let’s reduce lv_database up to 8 GB.
lvreduce -L8GB /dev/vg_storage1/lv_database
Decreasing LV size a given amount.
Now, we want to reduce LV size in a concrete amount of space.
Let’s reduce lv_database by 2 GB.
lvreduce -L-2G /dev/vg_storage1/lvdatabase
Removing a LV
If we want to remove a LV, we need “lvremove” command.
Let’s remove vg_database from vg_storage1.
lvremove /dev/vg_storage1/lv_database
We will continue our LVM series with EXT2/EXT3/EXT4 filesystem management.