1、概述
在做環境問題測試的時候,比如在k8s中測試磁盤壓力的時候,有的時候,需要快速的創建一個超級大的文件,來將磁盤空間占滿,這個時候,該怎么做?
本文檔就是介紹linux中實現的方法。
OK,我們來看下……
2、通過fallocate命令快速創建大文件
2.1、語法
[root@nccztsjb-node-23 ~]# fallocate --help
Usage:
fallocate [options] <filename>
Options:
-n, --keep-size don't modify the length of the file
-p, --punch-hole punch holes in the file
-o, --offset <num> offset of the allocation, in bytes
-l, --length <num> length of the allocation, in bytes
-x, --posix use posix_fallocate(3) instead of fallocate(2)
-h, --help display this help and exit
-V, --version output version information and exit
For more details see fallocate(1).
2.2、示例
[root@nccztsjb-node-24 data]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 200G 768M 200G 1% /data
[root@nccztsjb-node-24 data]#
[root@nccztsjb-node-24 data]# fallocate -l 180G bigfile
[root@nccztsjb-node-24 data]#
[root@nccztsjb-node-24 data]# ls -lh
total 181G
-rw-r--r-- 1 root root 180G Mar 8 16:22 bigfile
drwx--x--- 13 root root 167 Jan 25 11:18 docker
[root@nccztsjb-node-24 data]#
[root@nccztsjb-node-24 data]# df -h /data
Filesystem Size Used Avail Use% Mounted on
/dev/vdb 200G 181G 20G 91% /data
[root@nccztsjb-node-24 data]#
OK,通過fallocate命令就可以瞬間,創建出一個180G大小的文件,將磁盤空間占滿,進行相關的測試。