As a developer, you will inevitably encounter situations where you need to expand the disk space on your Linux servers. If you’re running Ubuntu as a virtual machine in a Proxmox environment, knowing how to efficiently resize its disk partitions is a crucial skill. This guide will walk you through the process, from increasing the disk size directly in Proxmox to extending the logical volume and resizing the filesystem within your Ubuntu VM.
This guide is specifically tailored for Ubuntu servers using Logical Volume Management (LVM), which is a common setup in many virtualized environments.
Step 1: Increase the Disk Size in Proxmox #
The very first step is to increase the size of the virtual disk for your Ubuntu VM. This is done directly within the Proxmox Web UI.
- Access Proxmox UI: Log in to your Proxmox Virtual Environment web interface.
- Navigate to Your VM: In the left-hand panel, select your target Ubuntu Virtual Machine.
- Go to Hardware: Click on the “Hardware” tab for your selected VM.
- Resize the Disk: Locate the entry for your virtual hard disk (e.g.,
scsi0,ide0,sata0). Select it and then click the “Resize Disk” button in the menu above the hardware list. - Enter New Size: A dialog box will appear. Enter the additional space you want to add to the disk (e.g.,
50Gfor 50 Gigabytes) and click “Resize”.
This action expands the virtual disk that Proxmox presents to your Ubuntu VM.
Step 2: Extend the Physical Drive Partition #
Once you’ve increased the disk size in Proxmox, you need to make the Linux operating system inside your Ubuntu VM aware of the new space.
-
Connect to Your Ubuntu VM: Log into your Ubuntu VM, either through the Proxmox console or via SSH.
-
Check Disk Layout: First, let’s check the current disk layout. You can do this with the
fdiskcommand:sudo fdisk -lYou should see that the main disk device (e.g.,
/dev/sda) now reports a larger total size, but its partitions may not yet reflect this. -
Extend the Partition: Next, we’ll use the
growpartutility to extend the partition. In a typical LVM setup on Ubuntu, your root filesystem is often on the third partition (e.g.,/dev/sda3). Adjust the partition number if yours is different.sudo growpart /dev/sda 3 -
Inform LVM of the Change: Now, we need to inform LVM that the physical volume has been resized. We can check the physical volume details before and after the change with
pvdisplay.pvdisplayRun the
pvresizecommand to instruct LVM that the disk size has changed. Point it to the device you just grew (e.g.,/dev/sda3):sudo pvresize /dev/sda3You can now run
pvdisplayagain to confirm that the physical volume has been extended and you have more “Free PE” (Physical Extents) available.pvdisplay
Step 3: Extend the Logical Volume #
With the physical volume extended and LVM aware of the new space, we can now extend the logical volume to use this newly available space.
-
View Logical Volumes: First, let’s view the current state of our logical volumes with
lvdisplay:lvdisplayTake note of the “LV Path” for the logical volume you want to extend. In a standard Ubuntu LVM setup, this is often
/dev/ubuntu-vg/ubuntu-lv. -
Extend the Logical Volume: Now, we’ll use the
lvextendcommand to extend the logical volume to use 100% of the free space available in its volume group:sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lvYou can run
lvdisplayagain to see the changes. You’ll notice that the logical volume is now larger, and “LV Size” reflects the expanded size.lvdisplay
Step 4: Resize the Filesystem #
The final step is to resize the filesystem itself to make the new space available for use by the operating system. This is a critical step; without it, the additional space will not be usable.
-
Resize the Filesystem: We’ll use the
resize2fscommand for this. This command works forext2,ext3, andext4filesystems, which are commonly used in Ubuntu.sudo resize2fs /dev/ubuntu-vg/ubuntu-lv -
Confirm the Results: Finally, you can confirm that the filesystem has been resized and the new space is available by checking the disk usage:
df -hYou should now see that the mount point for your root filesystem (usually
/) reflects the increased size.
And that’s it! You have successfully resized your Ubuntu VM’s disk partition within your Proxmox environment. This process, while technical, is straightforward when you follow these steps carefully. By understanding how to manage your disk space effectively, you can ensure your virtual machines continue to run smoothly.