One of the challenging issues that I have encountered is the manipulation of LVM – Logical Volume Management on virtual servers. Whilst writing this article, I noticed that I have to split it into parts as it looks bulky in some sort. Once you have understood the logic of the LVM, things get pretty easy to deal with. I will elaborate some details of LVM, and will surely get into some brief real-life experience that is important to grasp. Let’s take an example of a disk where there are some applications running like MySQL, Apache, some monitoring tools like Atop and Htop which are writing on the disk and we have to shrink that very disk or replace it with another disk. Let’s also assume that the server is running on an ESX host and the operation will be carried out through the VMware VCenter. How do you shrink a disk having its application generating IOs? How do you replace a disk with a smaller one having its data on an LVM?
In brief, here is what I have understood from what is LVM – Logical Volume Management.
We have Physical Volume (PV), Volume Groups (VG) and Logical Volume (LV). These terms are a must to understand before proceeding with Logical Volume Management operations.
PV- These are hard disks or even Hard disk partitions. These PVs have logical unit numbers. Each PV is or can be composed of chunks called PEs (Physical Extents)
VG – The Volume Group is the highest level of abstraction used with the LVM. Does this term look complicated? I would say no. In the field of Software Engineering, there are two terms that are usually used that is modeling and meta-modeling. Just understand it like this if you are not familiar with software engineering. Modeling means one step or one level removed from reality whilst Meta-Modelling means modeling at a higher level of logic. So basically, it looks like some sort of higher modeling happened at the level of the VG.
LV – The logical volume is a product of the VG. They are disks which are not restricted to the physical disk size and it can be resized or even move easily without even having your application to be stopped or having your system unmounted. Of course, I need to do more research to get into a more deeper explanation of the PV, PE, VG, and LV. Lets now see an explanation through my horrible drawing skills.
From the Diagram we conclude that :
- PVs looks like hard disks divided into chunks called PEs
- The VGs are just a high level of abstraction that should look from the above.
- VGs are created by combining PVs.
If you have access to a Linux machine having LVM configured and some VG have already been created, you can start firing these commands to have an overview of the PV, VG, and LV
- pvs – Report information about physical volume
- vgs – Information about volume groups
- lvs – Information about logical volumes
Those physical disks can be picked up from the datastores, where RAID is configured. This act as another layer of security to be able to handle disk failures or loss of data at all cost.
On Linux, if you type vg or lv or pv press tab twice you will have an idea all the commands that exist and possibilities of manipulation. On part2 of this article, I will take an example of the pvmove command and actions that could be done to minimize impact before carrying out a pvmove operation.