Reclaiming Proxmox Storage Disk Space via Linux CLI

Managing storage in Proxmox VE can be challenging, especially when disk space usage doesn’t match expectations. This guide provides practical commands to analyze Proxmox storage from the Linux command line, identify space usage by virtual machines and containers, detect unaccounted storage space, and troubleshoot common storage issues to help optimize your Proxmox environment.

In This Tutorial, You Will Learn:

  • How to identify and examine Proxmox storage configurations
  • How to check storage usage by virtual machines and LXC containers
  • How to detect “lost” or unaccounted storage space
  • How to find and manage VM snapshots that may be consuming space
  • How to identify large backups and ISO images
  • How to reclaim space in your Proxmox environment
Reclaiming Proxmox Storage Disk Space via Linux CLI
Reclaiming Proxmox Storage Disk Space via Linux CLI

Software Requirements and Linux Command Line Conventions

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions, or Software Version Used
System Proxmox VE 8.x (commands may work on older versions)
Software Standard Linux command line tools (df, du, find), Proxmox CLI tools
Other Root or sudo access to the Proxmox host
Conventions # – Requires commands to be executed with root privileges, either directly as root or using sudo.
$ – Requires commands to be executed as a regular non-privileged user.

Understanding Proxmox Storage Architecture

STORAGE ARCHITECTURE OVERVIEW
Proxmox VE uses different storage backends, each with specific commands for analysis. Common storage types include local directories, LVM-thin, ZFS, Ceph, and network storage. Being familiar with your specific storage configuration is essential for accurate analysis.

Before diving into commands, it’s important to understand how Proxmox typically organizes storage. Depending on your Proxmox version, storage may be located in several key locations:

  • /var/lib/vz/images/ – Contains VM disk images (qcow2, raw), organized by VM ID
  • /var/lib/lxc/ – Contains LXC container data, organized by container ID
  • /var/lib/vz/template/iso/ – Stores ISO images
  • /var/lib/vz/template/cache/ – Stores container templates
  • /var/lib/vz/dump/ – Contains VM and container backups

The storage configuration can be viewed using the Proxmox storage manager command:

# pvesm status

Step-by-step Instructions

  1. View Proxmox storage configuration: Get an overview of storage pools.
    # pvesm status

    This command displays all configured storage pools in your Proxmox environment, showing their types, status, total capacity, used space, available space, and usage percentage. Example output:

    View Proxmox storage configuration
    View Proxmox storage configuration

    This example shows directory-based storage at 87% capacity, while LVM thin-provisioned storage is at 33% capacity. High percentages (over 80%) warrant investigation.

  2. Check overall disk space usage: View filesystem usage.
    # df -h

    This command shows disk space usage for all mounted filesystems in a human-readable format. Example output might show:

    Filesystem            Size  Used Avail Use% Mounted on
    /dev/mapper/pve-root   94G   82G  7.4G  92% /

    High usage percentages (above 85%) indicate filesystems that need attention. For optimal performance, most filesystems should have at least 10-15% free space.

  3. List all virtual machines: See all VMs on the system.
    # qm list

    This command lists all virtual machines with their IDs, names, status, memory allocation, and disk size. Here’s an example output:

    VMID NAME                 STATUS     MEM(MB)    BOOTDISK(GB) PID       
    100 VM1                  stopped    2048              32.00 0         
    101 VM2                  running    1024              15.00 1119524   
    102 VM3                  running    8192             150.00 309833    
    106 VM4                  running    2048              32.00 3812960   
    107 VM5                  running    6000              32.00 3839516   
    108 VM6                  running    4000              50.00 1743913   
    109 VM7                  stopped    8192              60.00 0

    This output shows all VMs with their allocated disk sizes, helping you identify which VMs have large storage allocations that might be candidates for optimization.

  4. List all containers: View LXC containers.
    # pct list

    This command shows all LXC containers on the system. Example output:

    VMID       Status     Lock         Name                
    103        running                 CT1

    This displays container IDs, status, and names, which is useful for identifying which containers to examine for storage usage.

  5. Find large VM disk images: Locate VM images by size.
    # find /var/lib/vz/images -type f -name "*.qcow2" -o -name "*.raw" | xargs du -h | sort -hr

    This command finds all QCOW2 and RAW disk images in the VM storage location and sorts them by size (largest first). Based on the earlier output, you might find something like:

    62G     /var/lib/vz/images/109/vm-109-disk-0.qcow2

    This indicates that VM7 (ID 109) has a 62GB disk image, which is a significant portion of your storage.

  6. Check LXC container storage: Find container disk usage.
    # du -sh /var/lib/lxc/*

    This command checks the disk space used by all LXC containers. Most Proxmox installations store containers in the /var/lib/lxc/ directory.

  7. Examine VM snapshots: Find space-consuming snapshots.
    # for VM in $(qm list | tail -n +2 | awk '{print $1}'); do
        echo "VM $VM:";
        qm listsnapshot $VM 2>/dev/null;
    done

    This command lists snapshots for all VMs. Example output for a specific VM might look like:

    `-> fresh-install               2025-01-23 11:28:52     no-description
     `-> LXready                    2025-03-28 11:45:52     no-description
      `-> current                                           You are here!

    Multiple snapshots in a chain can consume significant space, especially for VMs with high disk activity. Snapshots should be regularly reviewed and unnecessary ones removed.

  8. Check for backups: Find large backup files.
    # find /var/lib/vz/dump -type f -name "*.tar" -o -name "*.vma" | xargs du -h | sort -hr

    This command locates backup files in the standard backup location and sorts them by size. Backups can consume significant space and might be candidates for cleanup if they’re old or no longer needed.

  9. Check ISO images: Find large ISO files.
    # find /var/lib/vz/template/iso -type f -name "*.iso" | xargs du -h | sort -hr

    This command lists all ISO images sorted by size. ISO images can be quite large and are often forgotten after VM installation, taking up valuable space.

  10. Check container templates: Find unused templates.
    # find /var/lib/vz/template/cache -type f | xargs du -h | sort -hr

    This command lists container templates by size. Templates that are no longer needed can be removed to reclaim space.

  11. Compare filesystem and directory sizes: Find “ghost space”.
    # df -h /
    # du -sh --exclude=/proc --exclude=/sys --exclude=/run --exclude=/dev /

    Compare these outputs to identify discrepancies. If df shows significantly more used space than du reports, there might be files that are deleted but still held open by processes or other filesystem metadata consuming space.

  12. Check for open but deleted files: Find hidden space consumption.
    # lsof | grep deleted | grep -E '(vz|lxc)'

    This command shows files that have been deleted but are still held open by processes, which can cause “ghost space” not visible through normal directory listings.

STORAGE TYPES AND ANALYSIS APPROACH
Different Proxmox storage types require different analysis approaches. For directory-based storage, standard Linux commands like df and du work well. For LVM thin provisioning, you’ll need specific LVM commands. ZFS storage requires ZFS-specific commands, while Ceph storage uses Ceph tools. Always identify your storage type with pvesm status before proceeding with analysis.

Reclaiming Storage Space in Proxmox

IMPORTANT WARNING
Always create backups before performing operations to reclaim space. Some actions like removing snapshots or deleting disk images cannot be undone and may result in data loss if performed incorrectly.

After analyzing your Proxmox environment with the commands above, here are effective methods to reclaim space that apply to most Proxmox installations:

  1. Remove unnecessary VM snapshots: Delete snapshots that are no longer needed.
    # qm listsnapshot VMID
    # qm delsnapshot VMID SNAPNAME

    The first command lists snapshots for a specific VM, and the second command deletes a named snapshot. Snapshots can consume significant space, especially for large VMs or those with high disk write activity. Multiple snapshots in a chain can accumulate substantial disk usage over time.

  2. Clean up ISO storage: Remove unused ISO images.
    # find /var/lib/vz/template/iso -type f -name "*.iso" | xargs du -h | sort -hr
    # rm /var/lib/vz/template/iso/unused-iso.iso

    First list the ISOs by size, then remove those that are no longer needed. ISO images are often forgotten after VM installation and can consume gigabytes of space. Always verify that an ISO is not in use by any VM before removing it.

  3. Delete old backups: Remove backups that are no longer required.
    # find /var/lib/vz/dump -type f -mtime +30 | xargs du -h | sort -hr
    # rm /var/lib/vz/dump/old-backup.vma

    The first command finds backup files older than 30 days and displays their sizes. Regular backups are essential, but older backups can often be safely removed according to your retention policy. Consider keeping monthly backups for longer periods while removing more frequent backups after a certain age.

  4. Remove unused container templates: Delete templates you no longer need.
    # find /var/lib/vz/template/cache -type f | xargs du -h | sort -hr
    # rm /var/lib/vz/template/cache/unused-template.tar.xz

    Container templates are downloaded when creating new containers but rarely removed afterwards. If you don’t plan to create containers of the same type again, these templates can be safely removed to reclaim space.

  5. Compact qcow2 images: Reclaim space within VM disk images.
    # qm stop VMID
    # cd /var/lib/vz/images/VMID/
    # cp vm-VMID-disk-0.qcow2 vm-VMID-disk-0.qcow2.bak
    # qemu-img convert -O qcow2 vm-VMID-disk-0.qcow2 vm-VMID-disk-0-new.qcow2
    # mv vm-VMID-disk-0-new.qcow2 vm-VMID-disk-0.qcow2
    # qm start VMID

    This procedure compacts a qcow2 image to reclaim space from deleted files within the VM. When files are deleted inside a VM, the disk image doesn’t automatically shrink. This conversion process rebuilds the image, omitting the unused blocks. Always stop the VM first and make a backup before attempting this operation.

  6. Clean up log files: Remove or rotate large log files.
    # find /var/log -type f -name "*.log" -o -name "*.gz" | xargs du -h | sort -hr | head -n 20
    # journalctl --vacuum-time=30d

    The first command finds large log files, while the second limits systemd journal logs to the last 30 days. Log files can accumulate over time and consume significant space, especially on busy systems or if log rotation is not configured properly.

  7. Remove unused virtual machines: Delete VMs that are no longer needed.
    # qm list
    # qm destroy VMID --purge

    First list all VMs to identify candidates for removal, then use the destroy command with the purge option to completely remove a VM and its associated disks. Only do this for VMs that are truly no longer needed.

  8. Optimize ZFS storage: Reclaim space on ZFS pools if applicable.
    # zpool list
    # zfs list
    # zpool trim poolname

    If your Proxmox system uses ZFS storage, the trim command helps reclaim space from deleted files on SSDs. Additionally, consider adjusting compression settings or running a scrub operation to verify data integrity.

Conclusion

Monitoring and managing storage in Proxmox environments requires understanding both the Proxmox-specific storage mechanisms and general Linux file management concepts. The commands in this guide help you identify where your storage is being used, detect anomalies, and reclaim space to keep your Proxmox system running efficiently.

Regular maintenance practices should include:

  • VM disk image optimization for large virtual machines
  • Regular snapshot management and consolidation
  • Periodic review of ISO images and container templates
  • Implementing a backup retention policy to automatically manage old backups
  • Monitoring actual disk usage vs. allocated space, especially with thin provisioning

By incorporating these commands into your routine maintenance procedures, you’ll maintain optimal storage usage and prevent disk space emergencies in your Proxmox environment.

Frequently Asked Questions (FAQ)

  1. Why does the Proxmox web interface show different disk usage than CLI commands?

    The Proxmox web interface may report different values than CLI commands for several reasons: thin provisioning may show allocated space rather than actual usage, the web interface might use cached data that doesn’t reflect recent changes, and the web UI might include overhead calculations that CLI tools don’t show. For the most accurate data, rely on the CLI commands provided in this guide.

  2. How do VM snapshots affect disk space usage?

    VM snapshots create delta files that track changes from the base image or previous snapshot. While they appear small initially, they can grow substantially as more changes occur in the VM. Multiple snapshots can lead to significant space usage, especially for VMs with high disk activity. Your VM 101 has multiple snapshots that could be consuming more space than expected.

  3. What causes “ghost space” where disk usage doesn’t match visible files?

    Ghost space typically occurs when: 1) Files are deleted but still held open by running processes, 2) Journal or log files are using space in filesystem metadata, 3) Snapshot or LVM metadata is consuming space, or 4) File system corruption. Use the lsof | grep deleted command to identify open deleted files, which are a common cause of ghost space.

  4. How can I reduce the size of VM disk images without data loss?

    To shrink VM disk images, first clean up within the guest OS by removing unnecessary files, running disk cleanup utilities, and zeroing free space using tools like zerofree (Linux) or SDelete (Windows). Then, for qcow2 images, stop the VM and use qemu-img convert -O qcow2 source.qcow2 optimized.qcow2 to create a more compact image. This can be particularly effective for your 62GB Windows11 VM image.

  5. Is thin provisioning in LVM-based storage risky for storage management?

    Thin provisioning allows you to allocate more storage than physically available, which can be efficient but requires careful monitoring. A typical system might show LVM thin storage at a low usage percentage while the underlying physical storage could be nearly full. This discrepancy is common with thin provisioning and shows why monitoring actual physical disk usage (with df -h) is critical. Always set up alerts for high physical disk usage to prevent unexpected out-of-space conditions, as these can cause VM crashes or data corruption.

 



Comments and Discussions
Linux Forum