Friday, November 16, 2007

Using Up All of a Disk Partition And Still Having 98% Free Space!

Yes, the title is somewhat misleading. You can't really use up all of any given disk partition and actually have 98% of that space still available for use. Not technically, anyway. This is something fun to try on anyone you like (or like playing pranks on) if you've got the time and the spare machine to do it.

You'd be surprised at how many Solaris admin's don't consider what's actually filling up the disk when you throw them a humdinger like this one. Even the one's who do still have to go an extra step. Here are the ingredients for the recipe:

1. Write a simple script to just make directories. You can write an infinite loop that executes "mkdir a;cd a" or get more complicated (to speed up the process) and write a little script that will cd into multiple subdirectories, exec itself and then re-run, ad infinitum. In any event, do this until your computer complains that there is no space left on the partition.

2. Check "df -k" to be sure, you should see something like:

Filesystem kbytes used avail capacity Mounted on
/dev/md/dsk/d5 8388608 119296 8269312 2% /mydir

that "2%" is the capacity it's at, so you have 98% of your disk free :) Too bad there's none left.

3. Now, since most admin's will figure this out (after using lsof, which doesn't really help), just confirm with "/usr/ucb/df -i" that the disk is, indeed, full to the brim.

Filesystem iused ifree %iused Mounted on
/dev/md/dsk/d5 494592 0 100% /mydir

I'm sure the astute observer has noticed that I'm simulating this information. I can't afford to do this for real right now ;)

So, this is the gist of it. You've used up all the available inodes, by creating a bunch of empty directories, but you've barely used up any disk space in process!

4. Now, to take it one step further (and further your enjoyment in the process), run this little Perl command line (assuming the top level directory you created on the /mydir partition was /mydir/newdir):

perl -e "unlink '/mydir/newdir';"

Now the top level directory, and just the top level directory, has been removed. The link to the inode no longer exists, making it impossible to cd into the directories below it, which still exist. To the naked eye it appears that there is nothing on /mydir that could possibly be causing the problem. Even utilities like "du" will report the correct total size (which is misleading) but not list the disk space usage for your non-existent directory when run as, say, "du -sk /mydir/*"

Eventually your co-worker and/or friend (maybe not anymore ;) will figure out, after doing an fsck, that the directory inode needs to be relinked and, if he's seen this before, will look in the /mydir/lost+found directory to find the missing "inode number" pointer and relink it manually.

That is why I highly recommend you remove this directory as well!

Enjoy your weekend. Remember - Please only do this in fun and, for your own safety, only to someone with a good sense of humor :)

, Mike