Running out of disk space on a VPS is one of the most common operational headaches for site owners, developers and system administrators. On a Hong Kong VPS — or any other location such as a US VPS or US Server — disk problems can cause application failures, degraded performance, and interrupted backups. This article walks through the technical causes of disk depletion, fast fixes you can apply immediately, best practices to prevent recurrence, and practical tips for choosing the right VPS to minimize disk risk.
Why disk space runs out: underlying principles
Understanding the root causes helps you fix issues quickly and design resilient systems. Disk exhaustion can stem from several layers:
- Filesystem-level accumulation: large files (backups, media), many small files (caches, caches of build artifacts), or logs growing without rotation.
- Inode exhaustion: even if df shows free space, the filesystem can run out of inodes when millions of small files exist.
- Temporary directories and package caches filling /, /var, or other mounts — examples include /tmp, /var/cache/apt/archives, /root/.cache, or application-specific caches.
- Containers and VM images: Docker images, layers, and volumes can accumulate and consume gigabytes.
- Snapshots and backups: frequent snapshots by hypervisors or automated backups retained too long.
- Filesystem fragmentation or reserved blocks: some filesystems reserve blocks for root which can hide apparent free space for non-root users.
Key Linux tools to inspect disk usage
Before taking action, inspect thoroughly:
- df -h — shows mount points and free space in human-readable form.
- df -i — check inode usage to detect inode exhaustion.
- du -sh /path/* — summarize per-directory sizes; use du -shx to stay on one filesystem.
- ncdu / — interactive, fast way to find large directories (installable via apt/yum).
- find / -type f -size +100M -exec ls -lh {} ; — locate very large files.
- lsof / | wc -l and lsof +L1 — list open but deleted files that still hold space.
- docker system df and docker system prune — inspect and clean Docker usage.
Fast fixes to reclaim space
When the service is impacted, prioritize quick, reversible steps that free space without risking data loss.
1) Remove orphaned and deleted-but-open files
Processes holding deleted files can keep disk blocks allocated. Identify them with:
lsof | grep “(deleted)”
Restarting the owning service releases space; for long-running processes prefer graceful restart. If you must, stop the process:
systemctl restart apache2 (example)
2) Clean package and OS caches
- Debian/Ubuntu: apt-get clean removes /var/cache/apt/archives.
- CentOS/RHEL: yum clean all or dnf clean all.
- Remove unused kernels (dpkg or package-cleanup –oldkernels).
3) Trim logs and enforce rotation
Check /var/log for large files. Use logrotate to rotate and compress logs; if immediate space is needed, truncate:
truncate -s 0 /var/log/large-log.log
But prefer rotating and archiving to prevent data loss.
4) Clean application caches and temp directories
- Clear web caches (WordPress object cache, static asset caches), artifact repositories, or build caches.
- Clear /tmp and /var/tmp carefully — some apps expect files to persist.
- Use application-specific commands, e.g., for Composer: composer clear-cache.
5) Docker and container cleanup
- docker image prune -a removes unused images.
- docker container prune removes stopped containers.
- docker volume prune reclaims orphaned volumes (beware of losing data).
6) Remove large unused files and old backups
Identify backups and archives older than a retention policy and safely delete them. Example:
find /backups -type f -mtime +30 -delete
Test any deletion patterns carefully to avoid removing needed files.
Expanding storage safely: partitions, LVM, and cloud options
If cleaning is insufficient, you may need to expand the disk. Approach depends on underlying block device and filesystem.
Resizing techniques
- Cloud Block Resize: Many VPS platforms (including Hong Kong Server and US VPS providers) let you resize volumes from the control panel. After increasing the block device, need to grow the partition and filesystem.
- Grow a partition: use growpart (from cloud-utils) to expand partition n on /dev/sda: growpart /dev/sda 1.
- Resize ext4: resize2fs /dev/sda1 after partition grown (can be done online for ext4).
- Resize XFS: use xfs_growfs /mountpoint (must be mounted; can be online).
- LVM: add a new physical volume (pvcreate), extend volume group (vgextend), then lvextend -L +10G /dev/vgname/lvname, and finally grow the filesystem (resize2fs or xfs_growfs).
Important: always snapshot or backup before partitioning or filesystem changes. If you have a Hong Kong VPS with easy snapshotting, create one prior to modifications.
When to move data to separate mounts
Separating /var, /home, /srv, and /tmp onto different partitions or volumes reduces blast radius. For example, put databases on a dedicated volume to prevent logs or uploads from filling the root filesystem. Mount options and fstab entries should be updated and tested.
Preventive measures and best practices
Fixes are temporary without prevention. Implement these measures:
- Monitoring and alerts: integrate disk usage metrics into Prometheus/Grafana, Zabbix, or the provider’s monitoring. Alert at thresholds (e.g., 70%, 85%, 95%).
- Log management: configure logrotate with sensible compression and retention. Forward logs to a centralized log store (ELK, Graylog, or cloud logging) when possible.
- Automated cleanup jobs: scheduled cron jobs that purge old files according to retention policy (backups, caches, temporary build artifacts).
- Quota enforcement: use filesystem quotas (XFS/project quotas or ext4/quota) to prevent runaway users or apps from consuming all space.
- Immutable and append-only policies: for critical logs or write patterns, use append-only mounts or special policies to avoid uncontrolled growth.
- Container best practices: build smaller Docker images, prune CI/CD artifacts, and use ephemeral runners with remote artifact storage.
- Backups and retention policy: have off-host backups and a clear retention policy so on-host backups don’t fill the disk.
Application scenarios and trade-offs
Different workloads demand different strategies:
Web hosting / CMS (WordPress, static sites)
Often dominated by media uploads and caches. Use object storage (S3-compatible endpoints), offload media delivering to a CDN, and configure periodic cache purges. Keep the CMS filesystem tidy and rely on database dumps to external backup storage.
Database servers
Databases require consistent, low-latency storage and usually benefit from a dedicated volume. Monitor transaction log growth and set up log shipping or replication to reduce local storage dependency.
CI/CD and build servers
Artifact accumulation is common. Use artifact repositories (e.g., Nexus, Artifactory) or object storage, and implement automatic cleanup of old builds.
Containerized infrastructure
Containers amplify disk usage via images and volumes. Enforce image pruning policies, keep base images minimal, and mount persistent volumes for long-lived state outside the container host root.
Choosing the right VPS and storage plan
When evaluating VPS providers — whether considering a Hong Kong Server for low-latency local audiences or a US Server / US VPS for different geography — weigh these factors:
- Disk type: local SSDs deliver low latency and high throughput; network-attached block storage offers flexibility to resize and attach between instances.
- Snapshot and backup features: on-demand snapshots and scheduled backups simplify recovery and experimentation when resizing or cleaning.
- Scalability: ability to increase disk size without downtime or with minimal steps (e.g., online resizing and guided tools).
- IOPS and throughput guarantees: database-heavy workloads benefit from guaranteed IOPS.
- Management APIs: support for programmatic resizing, snapshotting, and monitoring for integration into automation pipelines.
- Pricing and retention: consider long-term retention costs for snapshots and backups when sizing and choosing a provider.
For many Hong Kong-based businesses serving local users, a Hong Kong VPS with local SSD and snapshot capabilities reduces latency and improves user experience. For expansion or distributed operations, pairing Hong Kong Server instances with US VPS or US Server instances for redundancy and global coverage can be effective.
Checklist for incident response
- Run df -h and df -i immediately to identify problem mounts.
- Use ncdu or du to locate the largest consumers.
- Check for deleted-but-open files with lsof.
- Temporarily truncate large logs only if necessary and rotate soon after.
- Stop or restart offending services gracefully to release space.
- Create snapshots/backups before resizing or aggressive deletion.
- Plan a permanent fix (resize, move data to dedicated volume, enforce quotas).
Summary
Disk space incidents are common but manageable with the right combination of fast diagnostics, safe cleanup procedures, and long-term prevention: monitoring, quotas, separation of concerns (dedicated volumes for databases and logs), and efficient policies for backups and container images. Whether you operate a Hong Kong VPS for localized services or complement your infrastructure with US VPS or US Server deployments for broader reach, designing storage strategy around expected workloads and growth will minimize downtime and operational overhead.
For teams seeking VPS plans with flexible storage options, snapshotting and reliable SSD performance in Hong Kong, see our Hong Kong VPS offerings at https://server.hk/cloud.php. Additional details about the platform and global options can be found at Server.HK.