Lesson 12 - Extend LVM Disk on Linux Ubuntu

26/08/2023 - 2 phút

Follow  on Google News

What is LVM?

  • LVM (Logical Volume Manager) is a tool on the Linux operating system that allows for more flexible management of disk drives and partitions. Instead of dividing the disk into fixed partitions, LVM allows for the creation of virtual partitions (logical volumes) that can change in size, creating smaller storage blocks to maximize unused space.
  • With LVM, you can perform operations such as creating new, resizing, or moving virtual partitions flexibly, without having to change or move files on that partition. This makes storage management on the system easier and more flexible.
  • LVM is widely used on server systems or large storage systems, where managing storage space is a major challenge.

Concepts

  • Physical Volumes (PVs): are physical partitions on the disk. PVs can be physical disks, partitions on the disk, or other storage devices.
  • Volume Groups (VGs): are a group of PVs that have been combined together. All PVs in that VG are managed as a unified whole. With VG, users can create virtual partitions (LVs) with flexible sizes by using storage space on PVs.
  • Logical Volumes (LVs): are virtual partitions created from the storage space of VG. LVs are managed like partitions on regular physical drives, can be created, deleted, resized, and formatted similar to regular partitions.

Practice

Given the server configuration as follows:

IPHostnamevCPURAMDISK
192.168.56.2microk8s-master-18 core16G100G

After successfully creating an Ubuntu server, I use the command

sudo su
df -h

Then we use the command fdisk -l to check the entire hard drive capacity.

So the total hard drive capacity is 100G, as we only received 50G, we need to extend another 50G.

To extend LVM disk on Linux Ubuntu, please follow these steps:

1. Check the current status of LVM partitions on the system with the following command:

lvdisplay

This command will display a list of existing LVM partitions on your system.

2. Check the available capacity on the physical volume (PV) with the following command:

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:

df -h

This command will display a list of partitions on your system.

Then, select the partition with the name:

/dev/mapper/ubuntu--vg-ubuntu--lv

4. So the LVM partition already exists, now I just need to add more logical volume capacity with the following command

sudo lvm lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

Continue command

sudo resize2fs -p /dev/mapper/ubuntu--vg-ubuntu--lv

After running successfully, we use the command df -h to check if the hard drive has been added

df -h

So we have successfully extended 50G to the LVM partition

Thank you for following my article