What do I do when my root filesystem is full?

Just to share a magic command to know where all your disk space goes:

sudo du -hsx /* | sort -rh | head -n 40

You end up with a pretty neat report like this:

16G     /home
5.3G    /var
2.6G    /usr
840M    /run
277M    /root
171M    /lib
59M     /tmp
25M     /sbin
19M     /boot
16M     /bin
9.6M    /etc
136K    /ngx_pagespeed-latest-stable.zip
24K     /DEBIAN
16K     /lost+found
8.0K    /media
4.0K    /srv
4.0K    /opt
4.0K    /mnt
4.0K    /lib64

Then you can start again from another folder:

sudo du -hsx /home/* | sort -rh | head -n 35

Remove what's not necessary and you should be fine. It's part of my linux cheat sheet


Some likely measures for an overflowing root partition are (based on cases):

1. Core dumps filling up the disk.

Check with:

find / -xdev -name core -ls -o  -path "/lib*" -prune

2. Unnecessary packages filling up the space.

The following command will remove all automatically installed packages, which aren't required any more. (Because the dependency which force the installation in the past has been removed.)

apt-get autoremove --purge 

3. Outdated kernel packages

Check how many kernel packages are installed, and remove outdated kernel versions. You may investigate the current situation with:

dpkg -l "linux*{tools}*" |grep ^.i

Remove any kernel versions you doesn't need any more

4. Hidden storage

Other mounted partitions may hide used storage. To investigate this mount the root file system temporary on a second location:

mkdir /tmp/2ndRoot
mount /dev/sda1 /tmp/2ndRoot

Now look on every directory, that is normally hidden by another mount, e.g.:

  • tmp
  • home
  • run
  • var
  • usr/local

    and in your case also:

  • sites

Caveat

Don`t forget to control at the end the consistency of your installation with:

apt-get install -f

Notes

Reserved storage

/dev/sda1       5.7G  5.4G     0 100% /

The output shows that you have still some space, but it seems to be reserved for root. The good point is that your system functionality is currently still be given.

But you should fix the problem soon.

Space consumption of ubuntu 12.04

To have only 5.7 Gb for an ubuntu installation seems to be a bit too little. You should remove some unessential software packages.

My current installations have 10-14 Gb for the root and binary (aka /usr) partitions.


Another solution would be to use ncdu, eg:

sudo ncdu -x /

Where / is the partition/drive you wanna check. For my example, the result is

    4,0GiB [##########] /usr
  579,3MiB [#         ] /root
  487,4MiB [#         ] /opt
   41,7MiB [          ] /lib
   22,7MiB [          ] /sbin
   21,2MiB [          ] /boot
   18,6MiB [          ] /etc
    9,1MiB [          ] /bin
    3,6MiB [          ]  core
  260,0KiB [          ] /build
   88,0KiB [          ] /tmp
e  16,0KiB [          ] /lost+found
    8,0KiB [          ] /media
    4,0KiB [          ] /lib64
e   4,0KiB [          ] /srv
e   4,0KiB [          ] /mnt
>   0,0  B [          ] /var
>   0,0  B [          ] /sys
>   0,0  B [          ] /run
>   0,0  B [          ] /proc
>   0,0  B [          ] /ovhbackup
>   0,0  B [          ] /home
>   0,0  B [          ] /dev

Then you can navigate through the folders using your keyboard arrows and simply press the D key to delete a folder/file.

ncdu can be installed from the apt packaging tool on Debian based systems:

sudo apt install ncdu