Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 6 down vote accepted

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.

share|improve this answer
    
Good call. Loopback filesystems are underappreciated for learning, experimenting and testing. –  pboin Dec 12 '09 at 11:45

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%5Fdevice).

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

share|improve this answer

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.