Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to simulate no free disk space situation?

I need to test my web app in a scenario where there’s no disk space remaining, i.e. I cannot write any more files. But I don’t want to fill my hard drive with junk just to make sure there’s really no space left. What I want is to simulate this situation withing a particular process (actually, a PHP app).

Indeed, temporarily prohibiting disk writes to a process must be enough.

What’s the easiest way to do this? I’m using Mac OS X 10.6.2 with built-in Apache/PHP bundle. Thanks.

Edit: Disk free space check is not going to be reliable since it can change any moment. Many pages are being served simultaneously. There can be enough free space when checking, but none by the moment you actually write something. Also, checking for disk free space will require changing the code everywhere I write a file, which is not what I want :-) Finally, this solution is exactly the opposite of what I’m trying to test: how my app will behave when it cannot write any more.

like image 981
Ilya Birman Avatar asked Jan 11 '10 18:01

Ilya Birman


People also ask

How do I fill disk space in Linux?

If you like use dd, usually you can try it with seek. Just set seek=file_size_what_you_need and set count=0 . That will tell the system there is a file, and its size is what you set, but the system will not create it actually. And used this way, you can create a file which is bigger than the partition size.


1 Answers

I bet you could also create your own .dmg file with file system of size ... say 2Mb and write to it. If this works, then it is super-easy for testing - you just mount it and switch the path for testing. If the dmg is small enough, you could probably even upload it to the source control.

like image 92
Hamish Grubijan Avatar answered Sep 23 '22 10:09

Hamish Grubijan