Post

Resizing VM Storage in Proxmox

Resizing VM Storage in Proxmox

Expanding VM Storage

  1. From within Proxmox

    1. Shut down the VM.
    2. Resize the disk in the VM settings.
    3. Boot the VM.
  2. From within the VM

    1. Check for free space

      1
      
       sudo cfdisk
      

      If not, rescan the disk:

      1
      
       echo 1 > /sys/class/block/sda/device/rescan # Replace 'sda' with the appropriate disk
      
    2. Resize the partition

      1. Launch cfdisk:
        1
        
         sudo cfdisk
        
      2. Select the partition to resize. Typically, /dev/sda3.
      3. Select “Resize” from the bottom menu.
      4. Press ENTER to select.
      5. Press ENTER to confirm.
      6. Select “Write” from the bottom menu.
      7. Type yes and press ENTER to confirm.
      8. Press ‘Q’ to quit.
    3. Resize the physical volume

      1. Resize the physical volume:
        1
        
         sudo pvresize /dev/sda3
        
      2. Verify the physical volume has been resized:
        1
        
         sudo pvdisplay
        
    4. Resize the logical volume

      1. Confirm Volume Group free space:
        1
        
         sudo vgdisplay
        
      2. Resize the logical volume:
        1
        
         sudo lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
        
    5. Resize the filesystem

      1. Resize the filesystem:
        1
        
         sudo resize2fs /dev/sda3
        
      2. Verify the filesystem has been resized:
        1
        
         df -h
        

Reducing VM Storage

From the host console, logged in as root:

  1. Shut down the VM

    1
    
     pct stop <vmid>
    
  2. Find the storage path

    1
    
    lvdisplay | grep <vmid>
    

    Path follows “LV Path”

  3. Resize the file system

    1
    
     resize2fs /dev/pve/vm-<vmid>-disk-0 <new_size>
    

    New size can be specified in GB (e.g., 10G) or MB (e.g., 10240M).

  4. Resize the logical volume

    1
    
     lvreduce -L <new_size> /dev/pve/vm-<vmid>-disk-0
    
  5. Edit Container Configuration

    Edit the container configuration file located at /etc/pve/lxc/<vmid>.conf and adjust the rootfs line to reflect the new size.

  6. Start the VM

    1
    
     pct start <vmid>
    
  7. Verify the changes

    Check the disk size from within the VM:

    1
    
    df -h
    
This post is licensed under CC BY 4.0 by the author.