VMmanager Knowledge Base
en En
es Es

VM disk size is not decreasing

Problem

After deleting data on a virtual machine (VM) via the web interface, the platform shows the actual amount of used file space, but the VM’s disk size on the cluster node does not change. For example, the actual disk usage is 7.9 GB, but the web interface shows 3.1 GB.

Note
This guide applies to file-based storage only.

Cause

Dynamic allocation of space for virtual disks in file-based storage only works to increase disk size. Automatic shrinking of the disk after file deletion does not occur. This is a limitation of the libguestfs library.

Diagnosis

To confirm the cause:

  1. Connect to the cluster node via SSH. For more information about connecting via SSH, see Workstation setup.
  2. Check the actual disk size of the VM:
    du -sh /path/to/VM_disk
    Example output
    du -sh /vm/8_test-alma8
    7,9G	/vm/8_test-alma8
    Comment:
    • /vm/8_test-alma8 — the path to the VM disk on the node.
  3. Compare the obtained value with what is shown in the platform:
    1. Go to Virtual Machines → select the VM → Settings button.
    2. In the Information section, open the Storage, GB tab and check the value.

If the output of du shows a larger value than the web interface, the issue is confirmed. The VM disk is actually using more space than the web interface shows.

Solution

You can manually reduce the VM disk file size using the virt-sparsify utility. For more details, see the official libguestfs documentation. For more details, see official libguestfs documentation.

Caution!
Before proceeding, create a backup of the VM. For more information, see Creating backups manually.

To resolve the issue:

  1. Switch off the VM. Go to Virtual Machines → select the VM → menu Stop
    Important
    This is necessary because virt-sparsify requires exclusive access to the disk file. If the VM remains running, it will keep modifying data on the disk while the utility is running. This could corrupt the file system inside the VM and lead to data loss.
  2. Connect to the cluster node via SSH. For more information about connecting via SSH, see Workstation setup.
  3. Rename the virtual disk file:

    mv /vm/8_test-alma8 /vm/8_test-alma8.bak

    Comment:

    • /vm/8_test-alma8 — original virtual disk file;
    • /vm/8_test-alma8.bak — new backup copy of the original file.
  4. Run the optimization to create a compacted disk file:
    virt-sparsify /vm/8_test-alma8.bak /vm/8_test-alma8

    virt-sparsify reads the backup test-1.bak and creates a new compacted file test-1.

    Comment:
    • /vm/8_test-alma8.bak — original virtual disk file;
    • /vm/8_test-alma8 — new backup copy of the original file.
  5. Start the VM. Go to Virtual Machines → select the VM → menu Start.
  6. Verify the result. Make sure the VM starts without errors and that du shows the correct VM disk size:
    Example command and output
    du -sh /vm/8_test-alma8
    3,1G   /vm/8_test-alma8
    

    Comment:

    • /vm/8_test-alma8 — the path to the VM disk on the node.
  7. After successful verification, remove the backup:
    rm /vm/8_test-alma8.bak