Why I keep a gigabyte-sized file on my file system
More and more often these days I find myself approaching the limit of available space on my laptop’s solid-state drive. With only a gigabyte left and a lot of development activity ongoing, it is not uncommon for my system to run out of space every now and then.
On Linux systems having no storage left is far from fatal. The kernel resides in memory, swapping relies on a dedicated partition, and any self-respecting I/O activities can be expected to fail gracefully. That being said, there are indirect effects that are annoying as hell. For instance, my shell maintains a history file containing recent commands. If this file cannot be modified for some reason, an error message is printed every single time I execute a command; even worse, in some cases new shells cannot even be opened. For that reason alone, having no free space for extended periods of time can be viewed as potentially dangerous, as it can effectively lock me out of my shell.
At some point in the future, my current situation will inevitably trigger a spring cleanup, a storage upgrade, or ideally both. Until such time, however, I found1 a low-effort mitigation method: on my root file system I created a dummy file filled with one gigabyte of zeros. Most of the time this file just sits there, but whenever I run out of space I can alleviate the problem by removing it. This immediately restores some stability to my system, and usually buys me enough time to diagnose the issue and find a longer-term solution. I am aware that this approach is rather primitive. However, thus far it has proven surprisingly effective in making my work life bearable even though I am living on the edge.
If you would like to try it, here are some instructions. Inside my root shell, I
create the dummy file at
/opt/gigabyte using the following command:2
# dd if=/dev/zero of=/opt/gigabyte bs=1M count=1024
I remember having read about this technique somewhere online in the past. Unfortunately, at the time of writing this I was unable to track it down. If I ever re-discover it, I will update this post with a link. ↩︎
ddcan wreck your system if used without caution. Please stay safe by thinking twice and dd’ing once! ↩︎