Wednesday 24 March 2010

What's clogging up the root file system

The file system layout of the N900 is arguably not the easiest when it comes to maintenance: The root directory / and a whole bunch of important directories (e.g., /usr/bin/ and /usr/lib/) are stored together on a fast flash memory chip which is, unfortunately, rather tiny with its 256 MByte capacity. When you add and add new software, especially from the extras-devel repository, it may easily happen that you don't have any free space left on that device.

While there are various ways how to free up disk space by moving the disk hogs, you may ask yourself what these may actually be. Here's how I do that:


  1. Install the packages rootsh, findutils-gnu and coreutils-gnu, if you haven't done yet.
  2. Open a root shell.
  3. mkdir /home/user/MyDocs/tmp
  4. gfind / -type f -fstype rootfs -printf "%T+ %k %s %h/%f %n\n" | perl -ne 's/\.0000000000//; print;' > /home/user/MyDocs/tmp/files-on-rootfs.txt
    This command will take about a minute or so.
  5. Now you have a file of all files occupying precious space on the root file system (actually, some more, since /proc will also appear in there), but without any symlinks or files in symlinked directories. The file list will look like this:
    2009-04-15+12:14:52 600 612764 /bin/bash 1
    2010-02-11+00:52:24 124 125124 /bin/less 1
    2009-07-01+12:16:27 4 1167 /bin/tempfile 1
    2009-08-24+14:20:35 4 4012 /bin/lsmod 1
    2009-04-02+10:54:09 8 5364 /bin/devlocktool 1
    2010-02-11+00:52:24 12 10500 /bin/lesskey 1
    2010-02-11+00:52:24 8 5188 /bin/lessecho 1
    2010-02-11+00:52:23 8 6947 /bin/lesspipe 1
    2009-07-01+12:16:28 348 355592 /bin/busybox 1
    2009-02-26+08:24:27 4 45 /etc/hildon-welcome.d/default.conf 1
    More precisely, the format is like this:
    • Timestamp (which is sortable with alphanumeric or numeric sort due to the clever GNU date format),
    • then the number of blocks,
    • then the file size (somewhat redundant, but perhaps there are sparse files),
    • then the file name,
    • then the number of hardlinks (usually 1).
  6. Now you could simply load that file into your PC via USB or scp and analyse it there with external tools such as OpenOffice Calc, Excel, or the likes.
    Or you can analyse it right away on the N900:
  7. Most certainly, you don't want to go over all these entries by hand. Let's sort the file list by the file sizes:
    gsort -k 2 -n /home/user/MyDocs/tmp/files-on-rootfs.txt
    The largest files will be conveniently placed by hand. Now this gives you a good opportunity for finding candidates to be moved to /opt/ and symlinked from there.
  8. If you are interested what files were recently modified (probably the culprit that filled up / is a rather new file), then you can simply do
    gsort /home/user/MyDocs/tmp/files-on-rootfs.txt
    to sort by time stamp.
  9. Probably there's a lot of small files involved, so you may want to filter them out:
    awk '($3 > 500000){print}' /opt/tmp/files-on-rootfs | gsort
    This will only print files that occupy more than 500,000 Bytes and sort them by modification time.

By now you should have found out candidate files for "optifying", as it is usually called.

No comments:

Post a Comment