2

I know I can use quota to limit the amount of disk space per user. However I'm wondering if there's some way in Linux to limit the disk usage of a directory? Ideally I'd like something like

limit_space -n 100M ./path/to/directory

And any attempts to create a file or write to a file that would make it more than 100MB would fail with a similar error as if you tried to write to a full disk.

I know it gets complicated because of symlinks and hardlinks and block sizes and stuff.

The reason I'm asking is that I have a programme that downloads files to a temporary directory, and I want to test that that it does the right thing if it can't write the file. Simulating a full disk would be one of the ways. If there's a quick one-liner like this, then I can test this easily.

3 Answers 3

6

If this is just for testing purposes, I suggest you create a smallish loopback filesystem and mount it at the place you want test full disks.

1
  • Good call. Loopback filesystems are underappreciated for learning, experimenting and testing.
    – pboin
    Dec 12, 2009 at 11:45
3

You can crate separate partition for this directory. If You don't want repartitioning your hard drive you can crate virtual partition with loop device (http://en.wikipedia.org/wiki/Loop_device).

//edit: this topic may interest You: https://superuser.com/questions/82025/linux-how-to-create-a-folder-that-behaves-like-a-file/)

2

Have you considered using lvm for flexibility in having several virtual volumes (with the added bonus of hot backups, etc)?

(loopback filesystems are limited in number)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .