No space left on device磁盘空间不足解决方法

2025-11-20 07:22:04

1、模拟测试环境


系统:centos 7.2,磁盘空间8G,CPU 4核,内存4G(最好给大点,创建文件需要大内存)

[root@xm ~]# mkdir /test

[root@xm ~]# echo /test/{1..6000000}.txt |xargs touch #创建的文件太多了,只能用这种方式创建。

2、当进入编辑cronta或者创建文件时,直接报错,提示磁盘空间不足

[root@xm ~]# crontab -e

/tmp/crontab.MApBTV: No space left on device

[root@xm ~]# touch xmh.txt

touch: cannot touch ‘xmh.txt’: No space left on device

2.查看磁盘空间

[root@xm ~]# df -h

Filesystem      Size  Used Avail Use% Mounted on

/dev/sda1       8.0G  3.2G  4.9G  39% /      ##可以发现磁盘容量是空闲很多的

devtmpfs        1.7G     0  1.7G   0% /dev

tmpfs           1.7G     0  1.7G   0% /dev/shm

tmpfs           1.7G  8.7M  1.7G   1% /run

tmpfs           1.7G     0  1.7G   0% /sys/fs/cgroup

tmpfs           332M     0  332M   0% /run/user/0

3.查看inode空间

[root@xmh ~]# df -i

Filesystem      Inodes   IUsed  IFree IUse% Mounted on

/dev/sda1      4193792 4193792      0  100% /       #但是inode空间已满了

devtmpfs        422466     395 422071    1% /dev

tmpfs           424923       1 424922    1% /dev/shm

tmpfs           424923     473 424450    1% /run

tmpfs           424923      16 424907    1% /sys/fs/cgroup

tmpfs           424923       1 424922    1% /run/user/0

3、解决方法:使用find命令查找大于10M的目录,可以从df -i看出是在 根 /下容量不足,那么就从 / 下开始排查。

[root@xm ~]# find / -type d  -size +10M |xargs  ls -lhd  #find查找

drwxr-xr-x. 2 root root 97M Feb 15 14:00 /test

[root@xm ~]# ls /test/ |wc -l  #对该目录文件数量统计

4168011

#定位好目录后删除小文件

[root@xm /]# rm -rf /test/*  #直接 rm -rf * 的话是删除不了大量的小文件

-bash: /usr/bin/rm: Argument list too long

[root@xm /]# cd /test/

[root@xm test]# ls |xargs rm -f#删除大量的小文件,使用该命令删除

[root@xm /]# ls /test/ |wc -l #小文件已经删除了

#再次查看inode容量

[root@xm ~]# df -i

Filesystem      Inodes IUsed   IFree IUse% Mounted on

/dev/sda1      4193792 25973 4167819    1% /    #inode容量已恢复正常

devtmpfs        422466   395  422071    1% /dev

tmpfs           424923     1  424922    1% /dev/shm

tmpfs           424923   473  424450    1% /run

tmpfs           424923    16  424907    1% /sys/fs/cgroup

tmpfs           424923     1  424922    1% /run/user/0

#最后删除小文件所在的目录(删除时注意记录该目录的所属用户和权限)

[root@xm /]# rm -rf /test/

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢