How to clean up the rootfs partition or increase the size

disk-usage

Can't figure out how I should clean up my rootfs partition. It's 95% used, with total of 9.1G in space. Isn't that much for a root partition? This is my ouput of df -h command:

    /# df -h
Filesystem                                              Size  Used Avail Use% Mounted on
rootfs                                                  9.1G  8.2G  471M  95% /
udev                                                     10M     0   10M   0% /dev
tmpfs                                                   1.6G  740K  1.6G   1% /run
/dev/disk/by-uuid/55421528-015b-4bfc-8490-74b4cc25a2b4  9.1G  8.2G  471M  95% /
tmpfs                                                   5.0M     0  5.0M   0% /run/lock
tmpfs                                                   4.9G  536K  4.9G   1% /run/shm
/dev/sdb6                                               203G  647M  192G   1% /home

What is taking so much space because I can't find any large files in /var/cache. I've tried with apt-get clean and apt-get autoremove, with no luck on getting more space. How can I find the files that are taking up so much space? How can I do it securely so I don't mess up some important files? Or do I need to increase the size of the partition instead?

Edit:

The output of du -sh /*

0   /0
7.2M    /bin
26M /boot
0   /dev
12M /etc
4.0K    /example.conf.json
588M    /home
0   /initrd.img
212M    /lib
3.1M    /lib32
4.0K    /lib64
16K /lost+found
24K /media
4.0K    /mnt
1015M   /opt
du: cannot access `/proc/15453/task/15453/fd/4': No such file or directory
du: cannot access `/proc/15453/task/15453/fdinfo/4': No such file or directory
du: cannot access `/proc/15453/fd/4': No such file or directory
du: cannot access `/proc/15453/fdinfo/4': No such file or directory
0   /proc
52M /root
1.3M    /run
9.5M    /sbin
4.0K    /selinux
8.0K    /srv
0   /sys
40K /tmp
6.4G    /usr
350M    /var
0   /vmlinuz

Output of du -sh /usr/* | sort -rh:

4.1G    /usr/share
1.9G    /usr/lib
382M    /usr/bin
39M /usr/include
36M /usr/sbin
6.3M    /usr/lib32
1.9M    /usr/lib64
1.4M    /usr/x86_64-linux-gnu
588K    /usr/local
92K /usr/src
36K /usr/var
12K /usr/man
4.0K    /usr/games

Best Answer

Run du -x / >/tmp/du to generate a breakdown of disk usage per directory on the / filesystem (-x means “don't traverse other filesystems”).

Your biggest consumers are:

  • 588M /home — 0.6GB of user data
  • 1015M /opt — 1GB of software that you installed manually
  • 6.4G /usr — 6.4GB of software installed via packages
  • 350M /var — 0.3GB of data used by system software

None of that is surprising. 9GB is plenty for a typical single-function server but it isn't very large for a desktop computer where users want to install all kinds of programs. You can use the following command to list installed packages sorted by size:

dpkg-query -W -f='${Installed-Size;8}  ${Package}\n' | sort -n

see How do I list installed software with the installed size? for alternatives, including GUI ones. In particular, Synaptic lets you sort packages by size and is more convenient for removing packages on the fly. Of course, don't remove a package if you don't know what it does.

Related Question