How to Expand Disk and Partition with LVM on Linux Servers?
After increasing the disk size of your Linux server in virtualization infrastructures (VMware, Proxmox, KVM, etc.), this new space is not automatically used by the operating system. To expand the disk without losing the data on the server (without risk of data loss) LVM (Logical Volume Manager) architecture is used. In this guide, you will learn the disk expansion commands step by step.
Step 1: Detecting New Disk or Space
Connect to your server as root via Putty and check the new domain added to the system:
- To list physical disks:
fdisk -lorlsblktype the command. - If your main disk (Ex:
/dev/sda) is expanded but not reflected on the logical partition, continue to the next step.
Step 2: Resize the Physical Partition
In order for LVM to see the new disk space, we need to scan and expand the Physical Volume:
- Run the parpart command to update the disk table:
partprobe - Extend the relevant physical disk on LVM (Depending on the name of your disk, it may change to sda2, sdb1, etc.):
pvresize /dev/sda2 - To verify the volume group and see the free space
vgdisplaywrite.
Step 3: Extending the Logical Partition and File System
In the final step, we will transfer the free space directly to your root (/) directory or the desired partition:
- Expand the Logical Volume to take all available free space:
lvextend -l +100%FREE /dev/mapper/almalinux-root
*(Note: `/dev/mapper/...` path varies depending on your server, you can see your own root path with the `df -h` command).* - Processing the file system to the operating system:
- If your server XFS if using file system (AlmaLinux, CentOS, RHEL):
xfs_growfs /dev/mapper/almalinux-root - If your server EXT4 if using file system (Ubuntu, Debian):
resize2fs /dev/mapper/almalinux-root
- If your server XFS if using file system (AlmaLinux, CentOS, RHEL):
- The process is complete!
df -hYou can verify your new disk size by typing .
This article is specially prepared for PvPServer.