Friday, May 22, 2009

Missinig Disk Space

Lately I started worrying about disk space on my external USB disk, that I use for backups. The output of df -h /dev/sda1 clearly shows that I'm getting low on disk space, but it's not too bad:

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 230G 194G 25G 89% /mnt/elements

But there's something weird going on here - can you spot the problem?

It took me quite a while to notice - I've never done the math, and just assumed that Size=Used+Avail. But (surprise!) it doesn't add up.

I checked the disk for bad blocks, after un-mounting it, like this:
e2fsck -f -v -c -C 0 /dev/sda1

This took a few hours to complete, but showed no problem with the disk. I launched gparted and carefully went over the disk properties, in search for a clue. It insisted that I have more free space than that reported by df. This was reassuring, yet puzzling - where did that precious disk space go?

A quick search later and I found both the cause of the problem and its solution. It turns out that some disk space is always reserved for the OS. The default is 5% - quite a bit if you ask me. I verified that with
dumpe2fs /dev/sda1
and then modified it to 1%, like this:
tune2fs -m 1 /dev/sda1

After that df reports that I gained around 9GB:

Filesystem Size Used Avail Use% Mounted on
/dev/sda1 230G 194G 34G 86% /mnt/elements

One thing less to worry about!

2 comments:

  1. The Unix Hater's Handbook pointed out that Used+Available failed to account for inode space or what-not. They didn't mention tune2fs though; perhaps it didn't exist for the file systems they were talking about.

    ReplyDelete
  2. I bet the behavior of df is due to technical laziness and/or carelessness.

    If you're looking for something/someone to hate I propose to take aim at the guys who decided that disk space should be reported in multiples of 1000 bytes instead of 1024 (that USB disk of mine was marketed as having a capacity of 250G).

    Or the laptop manufacturers who sell you a laptop with 80G disk drives, of which 10G is used as a "recovery partition" (erase it and you void your warranty).

    I think malice and greed should be the real whatever-hater's target...

    ReplyDelete