Resizing the virtual disk on Proxmox

22 Nov 2024 - 3 min read
Resizing the virtual disk on Proxmox

Extending the volume on a virtual machine running Linux on Proxmox involves several steps. The process requires resizing the virtual disk on Proxmox, making the disk space available to the operating system, and then extending the logical volume.

Table of Contents

Overview

  • First, resize disk on Proxmox.
  • On VM, running the commands:
Terminal
# Make the partition see the space (/dev/sda3, Resize, Write, quit)
sudo cfdisk
# Extend the physical volume from the partition
sudo pvresize /dev/sda3
# Extend LV to use up all space from VG
sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
# Resize file system
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
# Check can see the space on filesystem
df -h

Remember change /dev/sda3 to your partition name

Step 1: Resize the Virtual Disk on Proxmox

  1. Log in to the Proxmox web interface.
  2. Navigate to the VM whose disk you want to resize.
  3. Go to the Hardware tab.
  4. Select the virtual disk and click Disk Action > Resize.
  5. Specify the amount of space to add (e.g., 10 for 10 GB) and click Resize.

Step 2: Rescan the Disk in VM

  1. SSH into your Ubuntu VM.

  2. Use the lsblk command to verify the disk structure.

Terminal
lsblk
  1. (Optional) Rescan the disk to detect the new size:
Terminal
echo 1 > /sys/class/block/sda/device/rescan

Replace sda with the correct device name (e.g., vda for VirtIO disks).

  1. Verify the disk size has increased using:
Terminal
fdisk -l

Step 3: Resize the Physical Volume

  1. Check the current volume group and logical volume structure:
Terminal
vgdisplay
lvdisplay
  1. Extend the physical volume to include the newly resized space:
Terminal
pvresize /dev/sdaX

Replace /dev/sdaX with the appropriate partition name.

Step 4: Extend the Logical Volume

  1. Use lvextend to extend the logical volume:
Terminal
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv

This command allocates all available free space to the logical volume.

Step 5: Resize the Filesystem

  1. Resize the filesystem to use the newly allocated space:
  • For ext4:
Terminal
resize2fs /dev/ubuntu-vg/ubuntu-lv
  • For XFS:
Terminal
xfs_growfs /dev/ubuntu-vg/ubuntu-lv
  1. Confirm the new size:
Terminal
df -h

Optional: Verify Everything

  1. Check the logical volume and filesystem size:
Terminal
lvdisplay
df -h
  1. Ensure the system is running without issues.

Summary

This procedure assumes that you are using Logical Volume Manager (LVM). If any step fails, please provide the error message below in the comments section.

ThinhHV

About ThinhHV

DevOps • Fullstack Developer • Amateur Photographer