Mount / Unmount Android System images

There are many reasons for wanting to unpack Android’s system image. The most obvious is modifying it. System.img is in the end an ext4 loop file system (such as the Linux system image), that can be mounted, modified and repacked in order to be burned afterwards in an embedded system. Android’s system image can be obtained from the google factory images.

Unfortunately, unmounting and re-mounting an Android system image requires a bit more effort than doing it for a Linux system image. We will describe the process on how to do it here.

  1. Get the simg2img and make_ext4fs binaries. They can be obtained in $ANDROID_SOURCE_DIR/system/extras/ext4_utils. They can be downloaded here.
  2. Place your system.img and the simg2img and make_ext4fs binaries in the same directory. (You can also place them somewhere else and modify your $PATH to point at the folder they are at.
  3. Create a folder where the root filesystem will be mounted. (e.g. sys). mkdir sys
  4. Type the following commands to mount the root filesystem:
      • simg2img system.img sys,raw
      • sudo mount -t ext4 -o loop sys.raw sys/
  5. The Android root files system is mounted in the sys folder. You can modify it as you please. (e.g. install busybox)
  6. Now, we need to repack the root file system and create a flashable system image
    • sudo make_ext4fs -s -l 512M -a system mysystem.img sys/
    • sudo umount sys
    • rm -rf sys

Now we have an Android system image, modified by ourselves that we can flash in an Android compatible device. In order to flash it we can use:

  • fastboot flash system mysystem.img

Hope this to be useful 🙂

One thought on “Mount / Unmount Android System images

  1. Pingback: Android – Understanding, Modifying, Building and Installing « My Cellar Door

Comments are closed.