How to Fix 'No Space Left on Device” on Root (/) Partition
One of the most common problems with Linux systems, especially those with limited disk space, is the exhaustion of root partition (/) space.
When this problem occurs, you may encounter the following error:
<code>No space left on device</code>
Don’t panic! This just means that your root directory (/partition) is full, which is a common problem, especially on systems with limited disk space or servers running 24/7.
When this happens, you may encounter the following problems:
- The package cannot be installed or upgraded.
- System startup failed.
- The service cannot be started.
- Unable to write to logs or temporary files.
This article walks you through practical steps to identify problems, clean up space safely, and prevent them from happening again. These instructions are for beginners and intermediate users.
Step 1: Check disk usage in Linux
The first step is to confirm the problem using the df
command, which will show the used and available space on the root partition. If the usage rate is 100% , then measures need to be taken.
<code>df -h /</code>
Now let's find which folders take up the most space.
<code>sudo du -h --max-depth=1 / | sort -hr</code>
This will display /
under top-level directories sorted by size.
<code>/var /usr /home /tmp /opt</code>
Once you have determined the largest directory, you can check it further, for example, if /var
is large:
<code>sudo du -h --max-depth=1 /var | sort -hr</code>
Step 2: Clean up the package cache in Linux
When software is installed or updated, Linux stores the downloaded package files in a local cache. This cache can become very large over time, especially if your system performs frequent updates or installations.
Cleaning this cache is a safe and efficient way to free up space.
<code>sudo apt clean # Debian/Ubuntu系统sudo dnf clean all # RHEL系列系统</code>
These commands delete all cached package files in /var/cache/apt/archives/
(for APT) and /var/cache/dnf/
(for DNF) that accumulate over time and take up a lot of space.
Step 3: Delete the old kernel in Linux
When your system installs kernel updates, it usually retains the old version to allow recovery if the new version fails. This can take up a lot of space over time, especially in limited capacity /boot
.
To free up space on Linux systems, it is best to delete old, unused kernels. However, do not delete the currently running kernel, as this is necessary for system startup and normal operation.
First, check the currently running kernel version.
<code>uname -r</code>
Then list all installed kernels:
<code>dpkg --list | grep linux-image # Debian/Ubuntu系统rpm -q kernel # RHEL系列系统</code>
Once you've determined which kernel versions are no longer needed, you can delete them. For example, to remove version 5.15.0-88-generic on Ubuntu.
<code>sudo apt remove --purge linux-image-5.15.0-88-generic</code>
On RHEL-based systems:
<code>sudo dnf remove kernel-4.18.0-305.el8.x86_64</code>
After deletion, update the bootloader.
<code>sudo update-grub</code>
After removing the old kernel, run this command to clean up the remaining packages and dependencies:
<code>sudo apt autoremove # Debian/Ubuntu系统sudo dnf autoremove # RHEL系列系统</code>
Step 4: Clean up log files in Linux
Linux records system activity and events in log files in the /var/log
directory. These logs help system administrators troubleshoot issues, track user activity, and understand system performance.
But over time, they can become very large, especially if:
- Service crashes repeatedly
- The system keeps recording debugging or error messages
- Your disk space is insufficient and the logs are constantly accumulating
If your root partition /
full, it is very likely that the logs are taking up a lot of space. Cleaning or shrinking these log files can immediately free up some space and restore your system to normal.
First, run the following command to see how much space is used for each log file or folder:
<code>sudo du -sh /var/log/*</code>
Once you know which log files are the culprit, you can truncate the log files, which means clearing their contents without deleting the actual files.
<code>sudo truncate -s 0 /var/log/syslog sudo truncate -s 0 /var/log/kern.log sudo truncate -s 0 /var/log/auth.log</code>
If your system uses journalctl (common in systemd), use the following command to clean the logs:
<code>sudo journalctl --vacuum-time=7d</code>
This will only keep logs for the past 7 days.
Step 5: Clean Docker in Linux (if installed)
If you are using Docker , it may use a lot of space due to mirrors, containers, and volumes.
Check Docker space usage:
<code>docker system df</code>
Delete unused Docker data:
<code>docker system prune -a</code>
Caution: This will delete all unused images, containers, and volumes.
Step 6: Live USB Rescue Method with Root Partition Full
If the system is completely full and unresponsive, you can boot to the Live Linux environment and mount the root partition using Live USB.
<code>sudo fdisk -l sudo mount /dev/sda1 /mnt # 将sda1替换为您实际的根分区</code>
Browse the file system and delete large files that you don't need.
<code>cd /mnt sudo du -sh var/* sudo rm -rf var/log/*</code>
Be cautious when deleting files – Avoid deleting critical system files.
Prevent this problem from happening again
Here are some best practices to avoid filling up the root partition:
- Use separate partitions – Create separate partitions for
/var
,/home
, and/tmp
during installation. - Monitor Disk Usage – Set up simple monitoring tools such as monit , cron jobs, or email alerts to notify you when disk usage is too high.
- Schedule a regular cleanup – Create a cron job to clean up logs and caches regularly.
- Avoid storing large files in / – Store backup files, download files, and media files on mounted external drives or on separate data partitions.
Summarize
When your root partition is full, it can cause serious problems, ranging from package installation failures and service crashes to log errors and even system startup failures. Fortunately, with the correct set of commands and some careful cleaning, you can restore the space and restore the system to normal without reinstalling it.
Have you ever encountered a situation where the root partition (/) is full on your Linux system? What steps have you taken to solve it? Share your experience in the comments below – your tips may help others in the community!
The above is the detailed content of How to Fix 'No Space Left on Device” on Root (/) Partition. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Linux is best used as server management, embedded systems and desktop environments. 1) In server management, Linux is used to host websites, databases, and applications, providing stability and reliability. 2) In embedded systems, Linux is widely used in smart home and automotive electronic systems because of its flexibility and stability. 3) In the desktop environment, Linux provides rich applications and efficient performance.

The five basic components of Linux are: 1. The kernel, managing hardware resources; 2. The system library, providing functions and services; 3. Shell, the interface for users to interact with the system; 4. The file system, storing and organizing data; 5. Applications, using system resources to implement functions.

Linux system management ensures the system stability, efficiency and security through configuration, monitoring and maintenance. 1. Master shell commands such as top and systemctl. 2. Use apt or yum to manage the software package. 3. Write automated scripts to improve efficiency. 4. Common debugging errors such as permission problems. 5. Optimize performance through monitoring tools.

The methods for basic Linux learning from scratch include: 1. Understand the file system and command line interface, 2. Master basic commands such as ls, cd, mkdir, 3. Learn file operations, such as creating and editing files, 4. Explore advanced usage such as pipelines and grep commands, 5. Master debugging skills and performance optimization, 6. Continuously improve skills through practice and exploration.

Linux is widely used in servers, embedded systems and desktop environments. 1) In the server field, Linux has become an ideal choice for hosting websites, databases and applications due to its stability and security. 2) In embedded systems, Linux is popular for its high customization and efficiency. 3) In the desktop environment, Linux provides a variety of desktop environments to meet the needs of different users.

Linux devices are hardware devices running Linux operating systems, including servers, personal computers, smartphones and embedded systems. They take advantage of the power of Linux to perform various tasks such as website hosting and big data analytics.

The disadvantages of Linux include user experience, software compatibility, hardware support, and learning curve. 1. The user experience is not as friendly as Windows or macOS, and it relies on the command line interface. 2. The software compatibility is not as good as other systems and lacks native versions of many commercial software. 3. Hardware support is not as comprehensive as Windows, and drivers may be compiled manually. 4. The learning curve is steep, and mastering command line operations requires time and patience.

Linuxisfundamentallyfree,embodying"freeasinfreedom"whichallowsuserstorun,study,share,andmodifythesoftware.However,costsmayarisefromprofessionalsupport,commercialdistributions,proprietaryhardwaredrivers,andlearningresources.Despitethesepoten
