Howto save a lot of disk space on nokia N810

The Nokia N810 is an internet tablet (not a phone though it can communicate with cellular phone via bluetooth). It’s a nice small device which run the Maemo Distribution which seems to be based on Debian since it uses the Debian Package Manager. But the distribution’s structure really feels like an embedded device and this is quite annoying when you try to optimize this device.
One thing which is really boring is the lack of disk space on the device. Actually the device use two miniSD (MMC) cards for personnal documents, images, videos and so on and a 256MB MTD using a JFFS2 compressed file system to store the whole distribution which means every package and their data files which takes a large amount of disk space and even so much that the MTD can easily be completely filled with a few apps.
The basic idea to save some disk space is to move some part of the MTD on the MMC primarely reformated from vfat to ext2. Many articles explain how to move stuff like /var/cache and others using symlinks which can save you about 20MB. But they also explain that you can’t do that with /usr/share/ for example since it will break the boot process. Indeed the boot process depends on many stuff located in /usr/share and thus if the MMC are not mounted while boot occurs the system will just stall waiting for an hard reset to get everything right and clean again. Here comes a way to go around this :

As root we check the run level :

Nokia-N810-43-7:~# runlevel
N 2

We see we are in runlevel 2. Let’s check how the boot process arranges itself in that runlevel :

Nokia-N810-43-7:~# ls /etc/rc2.d
K00zzinitdone
S12fb-progress.sh
S20dbus
S20hal
S20osso-applet-display
S21mce
(…)

It looks like fb-progress.sh is the first script executed in the boot process. So we edit this script (/etc/init.d/fb-progress.sh) and add the following line at the beginning of the script (line 19 or so):

/usr/sbin/osso-mmc-mount.sh /dev/mmcblk0p1 /media/mmc2
/usr/sbin/osso-mmc-mount.sh /dev/mmcblk1p1 /media/mmc1

So we know that MMC will be mounted at first in the boot process. After that scripts which need share stuff or other may look on the MMC since we know they were already mounted. Then we move things like /usr/share on the MMC :

Nokia-N810-43-7:~# mkdir /media/mmc1/.usr
Nokia-N810-43-7:~# cp -aR /usr/share /media/mmc1/.usr
Nokia-N810-43-7:~# rm -rf /usr/share
Nokia-N810-43-7:~# ln -s /media/mmc1/.usr/share /usr/share

Of course the same could be done for other directory. Here is the list of directory that I switched from MTD to MMC without breaking the boot process :

  • /var/backups
  • /var/cache
  • /usr/local
  • /usr/share
  • /usr/bin
  • /usr/games
  • /usr/lib
  • /home/user

The df entry for the MTD follow :

Filesystem Size Used Available Use% Mounted on
/dev/mtdblock4 249.5M 16.8M 232.7M 7% /

And it almost never grow when apps are installed.