Search code examples
shellunixmemory-managementbusyboxrm

How can I clear out data which was removed by rm -rf on a BusyBox based system without having to restart the system?


I am trying to create a shell script for easily doing some long commands for a busybox based Unix system.

The system doesn't have commands like lsof but has other basic commands. The issue I am facing is that when a new feature is added, I need to delete certain folders and push new folders into the system using adb push.

When I do that, I get an error saying that there is no space left on the device. So I need to do a power cycle.

I was wondering if there is any way to remove the data after performing rm -rf without having to perform a power cycle i.e shutdown and restart.


Solution

  • On Linux-based system, the spaces occupied by a file is removed when

    1. The file is not referenced by any folder
    2. The file is not opened by any process

    The 'rm' will meet the first condition, however, you will have to kill all processes that have the files open for the space to be cleared, otherwise, it will only happen during reboot (power cycle), when the fsck utility will identify "orphan" i-nodes, not referenced by any folder.

    There is no information about which processes are holding the open handles. Here are few generic alternatives:

    • If there is one (or few) processes that keep the large file open, try to stop/restart those services.
    • Instead of 'rm', you can truncate the larger files BEFORE opening them. 'echo > large-file' will release all the file space. Of course, this might have negative impact on the running processes, but from the question, it looks as if this is not an issue.
    • In theory, you can use 'telinit' to switch busybox from standard mode to different runlevel. If the services are configured for proper shutdown, you can get the system back into post-reboot, without power cycle