As applications and services run continuously on a Linux instance, logs, cache, and business data accumulate over time and gradually consume available disk space. When the disk becomes full, new data cannot be written, which directly causes service interruption or abnormal behavior.
Symptoms
When creating files or running applications on a Linux instance, you see the error message No space left on device, indicating that storage resources are exhausted.
Diagnosis and solutions
Before making changes, create a manual snapshot to back up your data and prevent accidental data loss that could affect your business.
Scenario 1: Disk space is exhausted
-
Check disk usage.
Run
sudo df -hto view disk usage for each mount point. If theUse%value is 100%, the corresponding space is full. -
Clean up unnecessary files or folders.
Use
sudo du -sh <folder name>/*to check the size of files and subfolders in a specified directory. If needed, navigate into the directory and repeat this command level by level to identify large items.For example, use
sudo du -sh /mnt/*to check the disk space used by files and subfolders under the/mntdirectory. -
If space remains insufficient after cleanup, scale out your disk.
Scenario 2: Inode resources are exhausted
Each file consumes one inode. If your disk contains many small files, inodes can be exhausted even when disk space remains available, preventing new files from being created.
-
Check inode usage.
Run
sudo df -i. If theIUse%value reaches 100%, inode resources are exhausted. -
Clean up unnecessary files or folders.
Use
sudo du -sh --inodes <folder name>/*to view the number of inodes used by files and subfolders in a specified directory. If needed, navigate into the directory and use this command recursively to locate high inode usage.For example, use
sudo du -sh --inodes /mnt/*to check the number of inodes used by files and subdirectories in the/mntdirectory. -
If inode count remains insufficient after cleanup, scale out your disk.
Scenario 3: Deleted files still occupy space
Even after a file is deleted, the system does not release its disk space if a process is still using it (i.e., holds an open file handle). The space is only freed when the process terminates or explicitly closes the file.
-
Install the
lsoftool.Files that are deleted but still hold space cannot be seen with
dfordu. Use thelsoftool to list them.Alibaba Cloud Linux, CentOS
sudo yum install -y lsofDebian, Ubuntu
sudo apt install -y lsof -
View storage space held by deleted files.
sudo lsof | grep delete | sort -k7 -rn | moreThe seventh column in the output shows file size in bytes. Sum these values to calculate total unreleased space.
tail 619544 root 3r REG 253,1 50000000 136507 /home/test_file (deleted) aliyun-se 347980 root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347997 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347996 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347995 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347994 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347983 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347982 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) aliyun-se 347980 347981 aliyun-se root 7uW REG 253,1 0 262160 /tmp/AliyunAssistClientSingleLock.lock (deleted) -
Record the process name and PID.
Run
sudo lsof | grep deleteand note theCOMMANDandPIDfields to identify the process name and process ID. -
Restart or stop the relevant service.
Run
sudo ps -ef | grep <PID>to confirm the process purpose. After evaluating the impact, restart or stop the service.ImportantRestarting or stopping a service may affect your business. Evaluate carefully and perform this action during an appropriate maintenance window.
Scenario 4: Mount point is overlaid
When a non-empty directory is used as a mount point for another device, its existing contents become hidden. However, processes that already have the directory open can still write to the underlying space. This “hidden” space consumption cannot be observed with the df command and can unexpectedly exhaust disk space.
-
View information about duplicate folders.
Run
sudo lsblkand check the MOUNTPOINT column for repeated directory names.sudo lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 253:0 0 40G 0 disk ├─vda1 253:1 0 2M 0 part ├─vda2 253:2 0 200M 0 part /boot/efi └─vda3 253:3 0 39.8G 0 part / vdb 253:16 0 40G 0 disk └─vdb1 253:17 0 40G 0 part /mnt vdc 253:32 0 40G 0 disk └─vdc1 253:33 0 40G 0 part /mntIn this example, both partitions
vdb1andvdc1are mounted to/mnt, indicating a risk of mount point overlay. -
Unmount the file system.
ImportantUnmounting a file system may interrupt services that depend on the path. Assess the risk and choose an appropriate time to perform this operation.
You can obtain the
<duplicate mount directory>from the previous step.sudo umount <duplicate mount directory>In this example,
/mntis the duplicate mount directory. Runningsudo umount /mntunmounts the most recently mounted device,vdc1. -
Identify the device name of the overlaid mount point.
Run
sudo df -hto locate the device name associated with the currently active mount point.sudo df -hFilesystem Size Used Avail Use% Mounted on devtmpfs 3.7G 0 3.7G 0% /dev tmpfs 3.7G 0 3.7G 0% /dev/shm tmpfs 3.7G 524K 3.7G 1% /run tmpfs 3.7G 0 3.7G 0% /sys/fs/cgroup /dev/vda3 40G 4.5G 33G 12% / /dev/vda2 200M 5.8M 194M 3% /boot/efi /dev/vdb1 40G 40G 0 100% /mnt tmpfs 747M 0 747M 0% /run/user/0In this example, the partition currently mounted to
/mntisvdb1. Therefore, the device name of the overlaid mount point isvdb1. -
Resolve the full disk space issue.
-
Clean up unnecessary files or folders in the overlaid space.
In this example, clean up the
/mntdirectory mounted byvdb1. -
If space remains insufficient after cleanup, scale out your disk and mount it to a different empty directory.
In this example, the target device to scale out is
vdb1.
-
Do not mount multiple devices to the same directory.
Mounting multiple devices to the same directory hides the space of the first-mounted device and may cause data to be written to the wrong device. Always mount different devices to separate empty directories.
Scenario 5: Docker-related files consume significant space
Docker generates many intermediate images, stopped containers, and build caches during operation. Over time, these accumulate and consume disk space.
-
Check Docker disk space usage.
Run
sudo df -h. If theUse%for aFilesystemof typeoverlayreaches 100%, Docker storage is full. -
Assess Docker resource usage.
Run
sudo docker system dfand examine theSizeandRECLAIMABLEfields to understand space consumption.sudo docker system dfTYPE TOTAL ACTIVE SIZE RECLAIMABLE Images 21 9 13.94GB 10.66GB(76%) Containers 9 5 30.09MB 0B(0%) Local volumes 6 6 259.9MB 0B(0%) Build Cache 0 0 0B 0BIn the example,
Dockerimages occupy 13.94 GB, of which 10.66 GB is reclaimable, and we recommend that you prioritize cleaning up unused images. -
Clean up unnecessary files.
If Docker files cannot be cleaned, follow the steps in Scenario 1: Disk space is exhausted.
-
Remove all stopped containers: run
sudo docker container prune. -
Remove all dangling images (untagged images): run
sudo docker image prune. -
Remove unused build cache: run
sudo docker builder prune.
-
Scenario 6: Inotify watches limit reached
When running commands like sudo tail -f, you might see the error tail: cannot watch '...': No space left on device. This does not mean disk space is full. Instead, the system has reached the maximum number of inotify watches used to monitor file and directory changes. You must increase this limit.
-
Check the current inotify watches limit.
Run
sudo cat /proc/sys/fs/inotify/max_user_watchesto view the current limit forinotify watches. -
Increase the inotify watches limit.
Raising this limit increases memory usage. Evaluate carefully before changing. The
<new limit>should generally not exceed 524288.sudo sh -c "echo fs.inotify.max_user_watches=<new limit> >> /etc/sysctl.conf" -
Load the new configuration.
Run
sudo sysctl --systemto apply the updated configuration. -
Verify the result.
Run
sudo cat /proc/sys/fs/inotify/max_user_watchesagain to confirm theinotify watcheslimit has been updated as expected.
References
-
For storing massive amounts of static files such as images, videos, or archives, use Object Storage Service (OSS).
-
For high-performance, high-concurrency file sharing, store files using File Storage NAS.
-
For large-scale log collection and analysis, store logs in Simple Log Service (SLS) to simplify querying and reduce local storage usage.