4

so me and my friend are having a contest. He says he has a way to fill up a LOT of HDD space on a linux server without being root. Obviously if you are root you can use DD to do this, but our contest is without root. Any good ways to do it?

1
  • 6
    You don't need root to use dd. – Dan D. Apr 7 '13 at 4:39
10

As normal user, run:

dd if=/dev/zero of=~/foo bs=1M

That makes an empty (but still space-consuming file) at ~/foo. On my computer, it swelled the file at a rate of 39.9 MB/s (my processor is a 3.0 GHz 64-bit Pentium 4,) although I imagine you could open several terminals and have them all running at once...

If it's command-line only, and you can only have one terminal open at once, do this:

dd if=/dev/zero of=~/foo0 & dd if=/dev/zero of=~/foo1 & dd if=/dev/zero of=~/foo2 & dd if=/dev/zero of=~/foo3

..that oughta fill that hard drive up in a flash.

3
  • 3
    Why do you think that writing several files at the same time is faster? ON many machines just running one dd will already max out the HDD. Adding more just adds overhead and even might slow things down. – Hennes Apr 7 '13 at 8:56
  • @Hennes Well, it was only going at ~40 MBps - that sounded a little slow for HD access. I figured it was probably the system throttling output of /dev/zero for some reason or another. For example, /dev/random gives like 2 Bytes/seconds, and my processor wasn't even whirring. I thought it might be throttling the output. However, I'm no expert on hard drives, and I think mine's getting old anyway, so I could be wrong - the hard drive could actually be the chokepoint. – JamesTheAwesomeDude Apr 8 '13 at 4:35
  • 1
    You might get better performance when you play with the block size. Leaving it at the default 512 bytes and running it for a minute I got 81 MB/sec, 60 MB/sec and 78 MB/sec on three consecutive runs on a used server. When setting block size to 1 MB I got 61753786368 bytes transferred in 634.595759 secs (97312006 bytes/sec) (92 MB/sec). – Hennes Apr 8 '13 at 11:37
5

You do not need root to run dd.

You can do this in many ways. Using /dev/zero as an infinite source of zeros is something which seems to occur to all of us, allowing things like:

  • cat /dev/zero > ~/my_huge_partition_filling_file.
  • cp /dev/zero ~/my_huge_partition_filling_file.
  • Or, needlessly complex using dd as a user:
    dd if=/dev/zero of=~/my_huge_partition_filling_file bs=512K. (The block size part is optional, but setting it to a value larger than 512 bytes may speed things up do to less overhead).
  • Or you can create your own file. Take any file, concattenate it with itself to create a second file of double the size, then repeat that. This is what Terdon's answer does.
  • Or you can write a program to write endlessly to a file. This is probably needlessly complex and the standard tools are often faster. Also, it feels 'un-unix-like').

You can also fake a huge file by creating a sparse file. dd if=/dev/zero of=~/my_seemingly_huge_file skip=99999G will instantly create a very small file, which will seem to be 99999 GB. If you want you can read 99999 GB from it. However in practice it consumes almost no space.

Compare it with a book with removable pages. Usually you have page 1,2,3,4,5,6 .... (end of book). With skip you have page 1,2,3, 99999. (pages 4,5,6,... etc will be inserted when written to, but until that time the book will be very thin).

Finally, before you try any of these: Check where you are writing.

If this is on /home (e.g. to /home/myusername) and /home is mounted on its own partition then all you can do is fill up the space for the homedirs. If someone did something silly like putting /home on the root filesystem then you can fill that to 95%. Most admins will not like that.

(95%, or actually 92.2% because the default settings on most filesystems seem to reserve 5% for root. That means it can be filled to 105%, and as a user filling it would use (100/105)%, or 95.2%)

3
  • Need a couple of > in your first commands; a sparse file uses next to no space. – vonbrand Apr 7 '13 at 20:52
  • I am missing the > part. As to sparse, aye, that is why you are faking a huge file. – Hennes Apr 7 '13 at 22:09
  • Ah. In the cat command. I blame copy and pasting the cp command combined insufficient caffeine. – Hennes Apr 8 '13 at 12:03
3

You can take up all the space in a hard disk by doing something as simple as

echo foo > f1.txt; 
while true; do 
    cat f1.txt >> f2.txt && 
    cat f2.txt >> f1.txt; 
done

The files will grow exponentially and will occupy all available space if you let the loop run for a while.

The dd solution is much more efficient of course, just pointing out that you most certainly do not need root access.

2

You can fill a disk by "yes" command:

yes garrbage > ~/junk

To prevent, it is better to define quota for users or use ulimit -f to prevent creating large file..

See man page of quota for more information.

2
  • Would this be faster than This: cp /dev/zero ~/my_huge_partition_filling_file – user1947236 Apr 7 '13 at 19:20
  • No, yes is more resource-intensive approach. It might be the same, but it won't be faster. – Olli Oct 11 '18 at 13:28
1

First: You do not need to be root to use dd or other tools to create big or many files.

But second: You cannot fill up the disk if its formatted with default options, because the most used linux filesystems keep 5% of diskspace reserved for root, so no dumb user can fill up the disk and crash the system, because really important processes cannot write their files (think of sshd, syslogd, etc.)

1
  • Even though 5% is reserved for root, in root partition that 5% is long gone, and normal user can still exhaust available disk space. – Olli Oct 11 '18 at 13:29

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