When you create a file or start an application on your Linux simple application server, a No space left on device error indicates the disk space is exhausted. If the disk should not be full given your expected usage, use this topic to identify the cause and resolve the issue.
If the disk is full as expected and you simply need more capacity, upgrade your server, attach a data disk, or extend an existing data disk. See Upgrade a simple application server, Attach a data disk, and Extend the data disk.
Symptom
When you create a file or run an application on the Linux simple application server, the following error message appears, indicating that storage resources are exhausted: No space left on device.
Diagnosis and solutions
Before you make any changes, create a snapshot to back up your data and prevent data loss caused by mis-operations that could interrupt your services.
Cause 1: Disk partition space is exhausted
-
Connect to the Linux server by using the rescue feature. For more information, see Connect to a Linux server by using the rescue feature.
-
Check disk usage.
Run
sudo df -hto view the disk usage of each mount point. IfUse%shows 100%, the corresponding space is full. -
Clean up unnecessary files or directories.
Run
sudo du -sh <directory>/*to check the size of files and subdirectories in the specified directory. If needed, enter the directory and drill down level by level to identify which files or directories consume the most space, and then decide which ones can be deleted or moved.For example, run
sudo du -sh /mnt/*to view the size of files and subdirectories in the/mntdirectory. -
If space is still insufficient after cleanup, resolve the issue by upgrading the server, attaching a data disk, or extending the data disk.
Cause 2: Inode resources are exhausted
Every file consumes one inode. If a large number of small files exist on the disk, inodes may be exhausted even when disk space remains, which prevents you from creating new files.
-
Connect to the Linux server by using the rescue feature. For more information, see Connect to a Linux server by using the rescue feature.
-
Check inode usage.
Run
sudo df -i. IfIUse%reaches 100%, inode resources are exhausted. -
Clean up unnecessary files or directories.
Run
sudo du -sh --inodes <directory>/*to view the number of inodes consumed by files and subdirectories in the specified directory. If needed, enter the directory and drill down level by level.For example, run
sudo du -sh --inodes /mnt/*to view the number of inodes consumed by files and subdirectories in the/mntdirectory. -
If inodes are still insufficient after cleanup, upgrade the server, attach a data disk, or extend the data disk.
Cause 3: Deleted files still hold disk space
Even after a file is deleted, as long as a process is still using it (that is, holding an open file handle), the system does not release the disk space it occupied. The space is reclaimed only after the process terminates or actively closes the file.
-
Connect to the Linux server by using the rescue feature. For more information, see Connect to a Linux server by using the rescue feature.
-
Install the
lsoftool.Deleted files that still hold space cannot be observed by using
dfordu. Use thelsoftool to list them.Alibaba Cloud Linux, CentOS
sudo yum install -y lsofDebian, Ubuntu
sudo apt install -y lsof -
List deleted files whose disk space has not been released.
sudo lsof | grep delete | sort -k7 -rn | moreThe 7th column of the output shows the file size in bytes. Sum the sizes to calculate the total amount of space that has not been released.
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 name and PID of the process that holds the file.
Run
sudo lsof | grep delete. Get the process name from theCOMMANDcolumn and the process ID from thePIDcolumn. -
Restart or stop the related service.
Run
sudo ps -ef | grep <PID>to confirm the purpose of the process. After evaluating the impact, restart or stop the related service.ImportantRestarting or stopping the service may affect your business. Evaluate the impact carefully and choose an appropriate time to perform the operation.
Cause 4: A mount point is overwritten
When another device is mounted on a non-empty directory, the data under that directory is hidden, but processes that have already opened the directory can still write to and consume the underlying space. This "hidden" space usage cannot be observed by using the df command, and can easily cause unexpected space exhaustion.
-
Connect to the Linux server by using the rescue feature. For more information, see Connect to a Linux server by using the rescue feature.
-
Check for duplicate mount point information.
Run
sudo lsblk, view the MOUNTPOINT column, and record any duplicate mount point 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
vdb1andvdc1are mounted on/mnt, which indicates a risk of mount point overwriting. -
Unmount the file system.
ImportantUnmounting the file system may interrupt services that depend on the path. Evaluate the risk and choose an appropriate time to perform the operation.
Obtain
<duplicate mount point>from the previous step.sudo umount <duplicate mount point>In this example,
/mntis the duplicate mount point. Runsudo umount /mntto unmount the most recently mounted devicevdc1. -
Identify the device name of the overwritten mount point.
Run
sudo df -hto locate the device name of the overwritten 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 at
/mntisvdb1, so the device name of the overwritten mount point isvdb1. -
Resolve the disk space issue.
-
Clean up unnecessary files or directories in the overwritten space.
In this example, clean up the
/mntdirectory that is mounted byvdb1. -
If space is still insufficient after cleanup, extend the data disk and mount it on another empty directory.
In this example, the target device to extend is
vdb1.
-
Do not mount multiple devices on the same directory.
When multiple devices are mounted on the same directory, the space of the earlier-mounted device is hidden and data may be written to the wrong device. Make sure that different devices are mounted on different empty directories.
Cause 5: Docker-related files occupy large amounts of disk space
During Docker operation, a large number of intermediate images, stopped containers, and build cache are generated. These objects accumulate over time and occupy disk space.
-
Check the disk space usage of Docker files.
Run
sudo df -h. IfUse%of the entry whoseFilesystemisoverlayreaches 100%, Docker is the source of the pressure. -
Determine the resource usage inside Docker.
Run
sudo docker system dfand check theSizeandRECLAIMABLEcolumns to determine which files occupy the most space.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 this example,
Dockerimages occupy 13.94 GB, of which 10.66 GB is reclaimable. Give priority to cleaning up unused images. -
Clean up unnecessary files.
If Docker files cannot be cleaned up, follow Cause 1: Disk partition space is exhausted to resolve the issue.
-
Remove all stopped containers: run
sudo docker container prune. -
Remove all dangling images (images without tags): run
sudo docker image prune. -
Remove unused build cache: run
sudo docker builder prune.
-
Cause 6: The inotify watches limit is reached
When you run a command similar to sudo tail -f and receive the message tail: cannot watch '...': No space left on device, the disk is not full. Instead, the inotify watches limit — which is used to track file and directory changes — has been reached and must be raised.
-
Check the current inotify watches limit.
Run
sudo cat /proc/sys/fs/inotify/max_user_watchesto view the current upper limit ofinotify watches. -
Increase the inotify watches limit.
Raising the limit may cause inotify to consume more system memory. Evaluate carefully before modifying. In general, a
<new limit>higher than 524288 is not recommended.sudo sh -c "echo fs.inotify.max_user_watches=<new limit> >> /etc/sysctl.conf" -
Reload the configuration.
Run
sudo sysctl --systemto reload the configuration and apply it. -
Verify the configuration.
Run
sudo cat /proc/sys/fs/inotify/max_user_watchesagain to confirm that the value is updated to your expectedinotify watcheslimit.