Surviving the limited memory of the Nexus One


I bought the Nexus One pretty much as soon as it became available, and have been loving the pure Google Android nature of the phone since, with one (perhaps 2 - the 1400mAh battery) exceptions. The internal system memory available for applications, and application data is fine for a few apps, but once you start to rely on a suite of applications, and install some of Google’s own memory hogs (Google+, Maps, etc) you rapidly run into issues.

The device has 512MB of flash, of which 190M can be used for application and data storage, plus a microSDHC card slot which can support up to 32GB - however some applications can’t be installed to this SD memory in the native build. 

Updated: 23rd Nov with info on A2SD+ from Lance.

Finding out what’s burning the space

There are 2 apps I’ve used to discover where all of your space is going.

  • 1Tap Cleaner will let you clear your app cache to give you more space + also allows you to sort apps by data size (or app size, total size etc). 
  • DiskUsage is a really nice graphical viewer that will let you visualize what’s using which areas. It will show you for each app how the space is being used for data, apk (the app itself), and dalvikCache

App2SD

The simplest and safest initial tactic is to use App2SD to help identify the apps that have allowed themselves to be moved to SD. App2SD will scan your whole system for apps that can be moved, and keeps an eye on any new installs, helpfully offering to move the apps right after you’ve installed them. I think this is sometimes referred to as the F-A2SD or Froyo Apps2SD method - because apps are able to run from the native fat32 partition on the SD card.

There are 2 things that limit the gain from this technique

  • Some apps are flagged as ‘don’t move me to SD’. This can be mitigated by rooting your phone - which I think allows you to move more of the flagged don’t move apps to flash.
  • App data remains in internal memory while the program itself is moved to SD.

That said, this method served me well for the first year of using the device.

Root + CyanogenMod

The next level of complexity (and benefit) comes from unlocking the bootloader, rooting, and then installing a 3rd party build of Android - in my case the CyanogenMod nightly builds. This gives you access to more tools that can help free up even more room (and offers the ability to move some of the previously stubborn apps to flash).

As part of the process of installing ROM Manager + CyanogenMod, you’ll find an option to perform a backup of your phone (known as a nandroid backup). Don’t skip this step, and don’t forget that you’re backing up to the SD card - so take a copy of this backup on your PC.

Uninstall Android system apps that you don’t need

You can’t uninstall system applications from the system menu, but they can be removed using a file-manager with root permissions. The most popular is Root Explorer ($3.95), but there are free alternatives. Personally I’m happy to pay for a 5* application when it is messing with my system on this level.

Install the app, open the setup menu, and enable root function, then grant superuser privileges.

Now you can browse to /system/app, set R/W (for read-write), and delete the apk files for the system-apps you no longer need. Note that you won’t be able to reinstall these from the market - so you should take a backup of the apk first.

Convert system apps to user apps, and move to SD

If you still want to keep a few system apps, but would prefer to move them to the slower (but larger) SD card, you can simply convert them to normal apps by moving the APKs from /system/app to /data/app. After rebooting and if they still work, you can try to move them to the SD card with App2SD (or the applications preferences screen as usual). 

Not all apps will work in this manner - so make sure you’ve got a full backup first, and don’t try moving key parts of the system (such as the keyboard!).

Create an ext partition on the SD card for apps

This step provides you with the greatest gain, however it also comes with the greatest pain - because the act of re-partitioning the card will erase everything on it - so start by taking a making backup copy of the SD card (and your phone using a nandroid backup as described above) to your PC. 

This process let you create a partition on the SD card that acts like internal memory, not external memory. By default, your SD card is formatted to fat32 - which makes it easy to read/write on a PC, and Android can read/write files to it, but most apps won’t run from it or store their data on it. An ext (ext2, ext3 or ext4) partition on the other hand is a standard UNIX partition, and can be treated as internal memory.

I used ClockworkMod recovery (from ROM Manager) to partition my SD because I already had that from the CyanogenMod installation. This let me create a 512M (or smaller) partition, which should be enough for most users. Either Armon Ra recovery or a Linux boot disk will let you customize the size of the ext partition (but don’t go larger than 2G).

I then used an app called S2E to mount the ext partition as ext4 on reboot, and set read-buffer to 2MB as recommended. I believe you can also use Link2SD to mount the partition. This lets you get access to the partition from the phone.

I understand from Lance Robson that a script known as A2SD+ is available within some custom ROMs or as an after-the-fact install that automates much of this process, however I think moves your whole /apps folder over to the SD card. If you want to try this route - search for Darktremor Apps2SD or FroYo a2sdext.

What to move to the ext partition?

Then you need to move things to the sd-ext partition. This is where I get a little less clear about what to move to maintain good performance.

You can ask S2E to relocate the whole /data/app and /data/private-app folders to the sd-ext folder, and then any app you install to “Internal memory” will automatically get shifted to the ext partition (and hence the SD card).

However after reading Roy True’s post on G+ indicating that some apps don’t perform too well from an ext partition, I decided to start with the dalvik cache and download areas. The dalvik cache is an area that stores optimized bytecode versions of your apps to make execution faster than if they had to unpack the APK every time. S2E let me move these into the sd-ext partition with no trouble.

Moving app data files

Now at this point I’ve already got around 70 MB of space on internal memory - so I’m doing well, but when I next run out of head-room, I’m going to need MORE. I can already shift apps individually over to the SD card using App2SD as usual, however this only moves the app, not the data associated with the app - which in the case of some apps (Google+ I’m looking at you! ) can be huge.

Thankfully there’s a trick using symbolic links (a bit like a pointer or redirect). You can shift the app’s data directory into /sd-ext, and create a symbolic link back to the app’s native folder. You could probably do this by hand - but an app called Titanium Backup will do it for you.

To enable this, according to the FAQ you need to create a folder called app in your sd-ext folder (although I’m not 100% sure this is necessary… ), then run Titanium Backup and long-click the app in question and select move app-data to SD.  On my system this created a folder in sd-ext called data2, and moved the data there, linking back to the app’s main data directory.

Conclusions…

Here are the key folders now on my phone…

Internal system user-space - limited to 190M 

  • /data/app - Applications - apk
  • /data/data - Data for those applications

Internal system area - 120M on my phone 

  • /system
  • /system/app - System Applications

Ext folder 433M = a mount point for the ext folder on the SD card (pretending to be internal memory)

  • /sd-ext/app - not used
  • /sd-ext/dalvik-cache
  • /sd-ext/data2 - the app data files that have been moved over from internal memory
  • /sd-ext/download - download folder

The main SD partition is mounted as /sdcard. Note that you won’t be able to see the ext folder from here as this is a separate partition.

  •  /sdcard/Android/data - Applications that have been moved to the SD card

Ok - so I’m not 100% sure that I’ve found the best path here, but my phone is certainly running faster, and I’ve got a lot more headroom than I had before, plus nothing has crashed on me (yet). 

Let me know if you spot a gap in my method above - or a way to simplify the task.