Linux--No space left on device

http://www.ivankuznetsov.com/2010/02/no-space-left-on-device-running-out-of-inodes.html

No space left on device – running out of Inodes

One of our development servers went down today. Problems started with deployment script that claimed that claimed “No space left on device”, although partition was not nearly full. If you ever run into such trouble – most likely you have too many small or 0-sized files on your disk, and while you have enough disk space, you have exhausted all available Inodes . Below is the solution for this problem.

 

1. check available disk space to ensure that you still have some

$ df

Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/xvda             33030016  10407780  22622236  32% /
tmpfs                   368748         0    368748   0% /lib/init/rw
varrun                  368748        56    368692   1% /var/run
varlock                 368748         0    368748   0% /var/lock
udev                    368748       108    368640   1% /dev
tmpfs                   368748         0    368748   0% /dev/shm

2. check available Inodes

$ df -i

Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/xvda            2080768 2080768   0  100% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm
If you have IUse% at 100 or near, then huge number of small files is the reason for “No space left on device” errors.

3. find those little bastards

$ for i in /*; do echo $i; find $i |wc -l; done

This command will list directories and number of files in them. Once you see a directory with unusually high number of files (or command just hangs over calculation for a long time), repeat the command for that directory to see where exactly the small files are.

$ for i in /home/*; do echo $i; find $i |wc -l; done

4. once you found the suspect – just delete the files

$ sudo rm -rf /home/bad_user/directory_with_lots_of_empty_files

You’re done. Check the results with df -i command again. You should see something like this:

Filesystem            Inodes   IUsed   IFree IUse% Mounted on

/dev/xvda            2080768  284431 1796337   14% /
tmpfs                  92187       3   92184    1% /lib/init/rw
varrun                 92187      38   92149    1% /var/run
varlock                92187       4   92183    1% /var/lock
udev                   92187    4404   87783    5% /dev
tmpfs                  92187       1   92186    1% /dev/shm
### 解决方案概述 操作系统错误 `errno 28` 表示磁盘空间不足 (`No space left on device`)。此问题可能影响数据库服务(如 MySQL 或 Oracle GoldenGate),以及其他依赖于文件系统的应用程序。以下是针对该问题的具体分析和解决方案。 --- #### **1. 检查磁盘空间** 首先,确认设备上的可用磁盘空间是否耗尽。可以使用以下命令来检查: ```bash df -h ``` 上述命令会显示各个挂载点的磁盘使用情况以及剩余空间。如果某个分区接近满负荷,则可能是引发 `errno 28` 的原因[^1]。 对于特定目录的空间占用情况,可运行以下命令查看大文件或目录: ```bash du -sh /path/to/directory/* ``` 通过以上方法定位到占用了大量存储空间的文件或日志。 --- #### **2. 清理不必要的文件** 一旦发现某些文件或日志占据了过多空间,可以选择清理这些数据。常见的操作包括但不限于: - 删除旧的日志文件: ```bash rm -rf /var/log/*.log* ``` - 压缩历史日志以减少体积: ```bash gzip /var/log/*.log ``` - 调整日志轮转策略,防止其无限增长。编辑 `/etc/logrotate.conf` 文件并配置合理的保留周期[^2]。 --- #### **3. 扩展磁盘容量** 当物理磁盘确实已达到上限时,考虑扩展存储资源。具体措施如下: - 对虚拟机环境中的硬盘进行扩容; - 添加新的存储卷并与现有文件系统合并; - 将部分数据迁移到其他位置释放当前分区的压力。 执行 LVM(Linux Logical Volume Manager) 扩展流程为例说明如何动态增加逻辑卷大小: ```bash # 查看现有的 PV/VG/LV 结构 pvdisplay; vgdisplay; lvdisplay; # 如果有未分配空间则直接调整 LV 大小 lvextend -L +10G /dev/vg_name/lv_name # 更新文件系统尺寸使之匹配新LV规模 resize2fs /dev/vg_name/lv_name ``` 注意替换命令里的路径参数为实际环境中对应的名称[^3]。 --- #### **4. 修改程序行为降低磁盘消耗** 除了外部干预外,还可以优化应用本身的行为模式从而减轻对本地储存的需求压力。比如修改 MySQL 配置项禁用慢查询记录功能或者更改缓存保存地址等设置避免因频繁写入而导致快速填满驱动器状况发生。 在 my.cnf 中添加或修改下面几行关闭不需要的功能: ```ini slow_query_log=OFF general_log=OFF tmp_table_size=64M max_heap_table_size=64M innodb_buffer_pool_size=4G ``` 重启 mysqld 生效变更后的设定值^. --- ### 总结 综上所述,处理 `errno 28` 错误需从多方面入手——先诊断根本原因是由于哪一部分导致缺乏足够的磁盘余量;接着采取相应手段解决问题,无论是简单删除冗余资料还是深入改造基础设施架构都取决于具体情况而定。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值