Mounting an Android system.img on Mac OS X

Building your custom version of Android is sometimes quite tricky, especially on new hardware. It is then often handy to be able to mount the Android system.img directly on your laptop, so that you can modify it without needing to rebuild it. This is especially useful if you don’t have working source, as often is the case.

In June, while busy breaking our then new NVIDIA Tegra X1 Shield Android TV through building a custom Android on it, using the NVIDIA provider source code, I encountered a bug that crashed the Surface Flinger.

I’ve seen that before; usually it is a result of missing proprietary EGL HAL drivers. This time it wasn’t that, well, almost. The EGL HAL drivers were readily there, no problem. However, one of the shared libraries the EGL drivers depend upon, libnvcpl.so, was missing from the licensed binary file distribution. (I reported the problem to NVIDIA and hope that it is fixed by the time you read this.) After some thinking, I decided to fish the library out from the official NVIDIA NVIDIA SHIELD ANDROID TV Recovery OS Image.

On Mac OS X, using the Linux version of the image, it was easy enough to unpack the constituents, boot.img, system.img, etc. Furthermore, based on my earlier experience with other modern Androids, I correctly suspected that system.img is actually a Linux ext4 system image. Now, the question was how to mount or otherwise inspect such an image on Mac OS X.

The answer was, of course, FUSE, or more specifically, OS X Fuse and ext4fuse from Homebrew. The latter, using ext4fuse was the harder part — I tried several options before drilling down to it.

In the end of the day, the process was easy:

  1. Install the latest version of OS X Fuse, using the binary installer. This was the easiest option, as Fuse requires a kernel module, and Yosemite allows only officially signed kernel modules.
  2. Install ext4fuse simply with brew install ext4fuse.

One more non-obvious step was needed. The Android system.img is actually not a direct ext4 file system image, but an Android specific wrapper around it. As I had built the open source Android for the console, I also had the required simg2img around, (in $TOP/out/host/darwin-x86/bin/simg2img).

With these settings, I was finally able to mount the system.img:

   $ sudo mkdir /mnt
   $ sudo chown `whoami` /mnt
   $ out/host/darwin-x86/bin/simg2img system.img system.ext4.imt
   $ ext4fuse system.ext4.img /mnt

Pekka Nikander

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s