What is LVM?
- LVM (Logical Volume Manager) is a tool on Linux operating system that allows to manage drives and partitions more flexibly. Instead of dividing the drive into fixed partitions, LVM allows the creation of resizable virtual partitions, creating many smaller storage volumes to make the most of the free space.
- With LVM, you can perform operations such as creating, resizing or moving virtual partitions dynamically, without having to change or move the files on that partition. This makes managing storage on the system easier and more flexible.
- LVM is commonly used on server systems or large storage systems where managing storage space is a big challenge.
The concept
- Physical Volumes (PVs): are the physical partitions on the drive. PVs can be physical drives, partitions on drives, or other storage devices.
- Volume Groups (VGs): is a group of PVs that have been combined together. All PVs in that VG are managed as a single entity. With VG, users can create virtual partitions (LVs) of flexible sizes using the storage space on the PVs.
- Logical Volumes (LVs): are virtual partitions created from VG’s storage space. LVs are managed like partitions on regular physical drives, and can be created, deleted, resized, and formatted similar to regular partitions.
Practice
For the server configuration as follows
IP | Hostname | vCPU | RAM | DISK |
---|---|---|---|---|
192.168.56.2 | microk8s-master-1 | 8 cores | 16G | 100G |
After creating the ubuntu server successfully, I use the command
1 2 3 | sudo su df -h |
then we use the command fdisk -l to check the entire hard drive space
So my total hard drive capacity is 100G as I just received 50G, so we need to Extend another 50G
To extend LVM drive on Linux Ubuntu, please follow these steps:
1. Check the current status of the LVM partitions on the system with the following command
1 2 | lvdisplay |
This command will display a list of existing LVM partitions on your system.
2. Check the available space on the physical partition (PV) with the following command
1 2 | pvdisplay |
This command will display information about the available and used capacity on the PV.
3. Check the location of the LVM partition you want to extend with the following command
1 2 | df -h |
This command will display the list of partitions on your system.
then I choose the name partition named
1 2 | /dev/mapper/ubuntu--vg-ubuntu--lv |
4.So the LVM partition is already there, now I just need to add the logical volume with the following command
1 2 | sudo lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv |
Continue command
1 2 | sudo resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv |
After running successfully, use the df -h command to check if the hard drive has been added
1 2 | df -h |
So we have successfully extended 50G to the LVM partition