Some tips when the disk is filled with large files

In the production environment, the disk will be filled with some large files, but the large files cannot be deleted immediately because they are open...
Simulation environment
Here's how to do it

In the production environment, the disk will be filled with some large files, but the large files cannot be deleted immediately because they are opened. The following tips are one way to solve this kind of problem

Simulation environment

First fill the / boot partition with / dev/zero

[root@centos7 boot]# cp /dev/zero /boot/bigfile cp: error writing '/boot/bigfile': No space left on device cp: failed to extend '/boot/bigfile': No space left on device [root@centos7 boot]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708520 101097880 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10144 745864 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 1038296 40 100% /boot tmpfs 151204 0 151204 0% /run/user/0

Then open the / boot/bigfile file file, open a new terminal, and use df to check the partition utilization

[root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708664 101097736 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10184 745824 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 1038300 36 100% /boot tmpfs 151204 0 151204 0% /run/user/0

Using rm to delete bigfile file

[root@centos7 ~]# rm /boot/bigfile rm: remove regular file '/boot/bigfile'? y [root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708584 101097816 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10184 745824 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 1038300 36 100% /boot tmpfs 151204 0 151204 0% /run/user/0

However, the utilization rate of the / boot partition is still 100%, but the bigfile file file in the directory has been deleted.

[root@centos7 ~]# ls /boot config-3.10.0-957.el7.x86_64 efi grub grub2 initramfs-0-rescue-30905c0f8bf344f4af5b53a826370629.img initramfs-3.10.0-957.el7.x86_64.img symvers-3.10.0-957.el7.x86_64.gz System.map-3.10.0-957.el7.x86_64 vmlinuz-0-rescue-30905c0f8bf344f4af5b53a826370629 vmlinuz-3.10.0-957.el7.x86_64 [root@centos7 ~]#

When the bigfile file file is released, the utilization of the / boot partition is set to zero.
Conclusion: when the disk file is written, deleting the file directly will not free disk space, but the file has been deleted. The space is freed only when the file is closed.

Here's how to do it

Fill the disk first

[root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708604 101097796 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10144 745864 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 167000 871336 17% /boot tmpfs 151204 0 151204 0% /run/user/0 [root@centos7 ~]# cp /etc/zero /boot cp: cannot stat '/etc/zero': No such file or directory [root@centos7 ~]# cp /dev/zero /boot/bigfile cp: overwrite '/boot/bigfile'? y cp: error writing '/boot/bigfile': No space left on device cp: failed to extend '/boot/bigfile': No space left on device [root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708584 101097816 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10144 745864 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 1038296 40 100% /boot tmpfs 151204 0 151204 0% /run/user/0

Open the bigfile file file and start another terminal to check the boot partition utilization

[root@centos7 ~]# df /boot Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 1038336 1038300 36 100% /boot

Then execute the redirection command to empty the bigfile file file. At this time, the boot disk space has been released

[root@centos7 ~]# > /boot/bigfile [root@centos7 ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda2 104806400 3708588 101097812 4% / devtmpfs 740168 0 740168 0% /dev tmpfs 756008 0 756008 0% /dev/shm tmpfs 756008 10184 745824 2% /run tmpfs 756008 0 756008 0% /sys/fs/cgroup /dev/sda3 52403200 33140 52370060 1% /data /dev/sda1 1038336 167004 871332 17% /boot tmpfs 151204 0 151204 0% /run/user/0 [root@centos7 ~]# ls /boot bigfile config-3.10.0-957.el7.x86_64 efi grub grub2 initramfs-0-rescue-30905c0f8bf344f4af5b53a826370629.img initramfs-3.10.0-957.el7.x86_64.img symvers-3.10.0-957.el7.x86_64.gz System.map-3.10.0-957.el7.x86_64 vmlinuz-0-rescue-30905c0f8bf344f4af5b53a826370629 vmlinuz-3.10.0-957.el7.x86_64

Then delete the bigfile file file

[root@centos7 ~]# rm -rf /boot/bigfile

When the bigfile file file is closed, the file is deleted.

2 December 2019, 11:27 | Views: 1257

Add new comment

For adding a comment, please log in
or create account

0 comments