Whats using all my disk space up?


Often we get asked by customers ‘What is using up all my disk space on my VPS?’. Usually we track it down to log files not being rotated or email etc.

Here are a few of the commands we use to do that.

You can find what’s using space using du -sh as root ie

du -sh /*

Gives you an idea on what directories are using space – this may take a bit. Then from there you can cd into those directories and again du -sh to find more. If you drop the -h (human readable) then you can do –max-depth 5 i think it is and get 5 levels deep then see the larger numbers as to what taking up the space.

Here is a command I often use to do it in one go. This will return the largest 20 subdirectories

du -m --max-depth=5 /  | sort -g | awk '{if($1 > 102400) print $1/1024 "MB" " " $2 }' | tail -n 20

From here you can find the 15 largest files with

find /path -printf "%k %p\n" | sort -g -k 1,1 | awk '{if($1 > 102400) print $1/1024 "MB" " " $2 }' |tail -n 15

A couple of quick easy fixes are

Debian package caches
apt-get clean # this removes all your downloaded packages no longer needed

btmp
rm /var/log/btmp # This file can safely be removed. Its used by the command ‘lastb’ which lists failed login attempts by users. It can get rather large if there are automated attacks on your VPS.

tmp
rm -r /tmp/* # double check what’s in here first, there may be valid session cookies etc you don’t want removing. Rebooting often clears this out automatically anyway

mysql
/var/lib/mysql/ibdata1 – this is a tricky one. Its well documented bug/feature if you are using INNODB style databases. You can read about it here http://bugs.mysql.com/bug.php?id=1341
There are several suggested fixes, however they all involve dumping the databases, removing it, then re-importing them all.
Whilst you are doing it adding in the option into the my.cnf for mysql
innodb_file_per_table
This will prevent it coming back.

Summary

Nine times out of ten most (possibly reclaimable) space is used up under /var or /home. /usr will typically be largeish (a GB or two) but its contents are typically required to run your server. Don’t mess with /proc. Don’t delete things you are unsure about, best check (via google or email us) before deleting anything. Often it pays to move something elsewhere (trash folder?) to see if it breaks things, if it does then move it back. If it doesn’t break things, then you can rm it next week when you are sure.

If you need more disk space and you are on a RimuHosting VPS, you can add more space from your control panel.