Analyzing Android system partitions (Must know)

An Android phone contains a few basic partitions along with other supporting partitions. This knowledge is vital to understanding how and where code is flashed to devices.

Getting ready

On our test device—Samsung Galaxy Nexus (or emulator)—we can view these partitions with the following command executed inside an adb shell. To obtain a shell on the device, you should connect the device via USB and you should make sure that the USB Debugging option is enabled (located at Settings | Developer Options).

Note

If you are using Jellybean or higher, the option is hidden, so you need to go to Settings | About Phone and keep tapping on the build number until a Toast pops up saying that you are now a developer. The Developer Options will appear at the usual location.

Finally, to actually obtain a shell, while the device is connected, fire up a terminal and type in adb shell and press Enter.

Note

Sometimes, Linux does not detect the Android device, and in these cases, you need to edit the USB rules file. Since this is not a systems development issue and is commonly encountered by SDK developers, we will not detail the steps here.

How to do it…

  1. Execute the following command in a terminal with Samsung Galaxy Nexus connected and with debugging enabled. The following output is generated when we list the device's partitions:
    shell@android:/ $ ls -l /dev/block/platform/omap/omap_hsmmc.0/by-name          
    lrwxrwxrwx root     root              2012-06-28 22:03 boot -> /dev/block/mmcblk0p7 
    lrwxrwxrwx root     root              2012-06-28 22:03 cache -> /dev/block/mmcblk0p11 
    lrwxrwxrwx root     root              2012-06-28 22:03 dgs -> /dev/block/mmcblk0p6 
    lrwxrwxrwx root     root              2012-06-28 22:03 efs -> /dev/block/mmcblk0p3 
    lrwxrwxrwx root     root              2012-06-28 22:03 metadata -> /dev/block/mmcblk0p13 
    lrwxrwxrwx root     root              2012-06-28 22:03 misc -> /dev/block/mmcblk0p5 
    lrwxrwxrwx root     root              2012-06-28 22:03 param -> /dev/block/mmcblk0p4 
    lrwxrwxrwx root     root              2012-06-28 22:03 radio -> /dev/block/mmcblk0p9 
    lrwxrwxrwx root     root              2012-06-28 22:03 recovery -> /dev/block/mmcblk0p8 
    lrwxrwxrwx root     root              2012-06-28 22:03 sbl -> /dev/block/mmcblk0p2 
    lrwxrwxrwx root     root              2012-06-28 22:03 system -> /dev/block/mmcblk0p10 
    lrwxrwxrwx root     root              2012-06-28 22:03 userdata -> /dev/block/mmcblk0p12 
    lrwxrwxrwx root     root              2012-06-28 22:03 xloader -> /dev/block/mmcblk0p1 
    
  2. Similarly, on the Nexus S and Nexus One device, we can view the partitions mounted with the command. The following command lists the contents of the mtd proc file:
    cat /proc/mtd
    

    The output looks similar to the following:

    dev:    size   erasesize  name 
    mtd0: 00200000 00040000 "bootloader" 
    mtd1: 00140000 00040000 "misc" 
    mtd2: 00800000 00040000 "boot" 
    mtd3: 00800000 00040000 "recovery" 
    mtd4: 1d580000 00040000 "cache" 
    mtd5: 00d80000 00040000 "radio" 
    mtd6: 006c0000 00040000 "efs"
    
  3. The following output is observed when the same command is executed on Nexus One:
    dev:    size   erasesize  name 
    mtd0: 00040000 00020000 "misc" 
    mtd1: 00500000 00020000 "recovery" 
    mtd2: 00280000 00020000 "boot" 
    mtd3: 04380000 00020000 "system" 
    mtd4: 04380000 00020000 "cache" 
    mtd5: 04ac0000 00020000 "userdata"
    

    Note

    Note the output you see for your device may differ slightly.

How it works…

The main thing to notice here is the existence of a few common partitions which are important to flashing new software. The following are major partitions on most Android devices:

  • /boot: This contains the kernel image and the associated RAM disk. This is executed by the bootloader during the startup process. Any newly built kernel is written to this partition. The phone will not boot if this partition is empty.
  • /system: This contains the Android framework and the related system applications. During system operation, this is mounted as read-only so that critical system files are never modified.
  • /recovery: Is an alternative boot partition used to boot the device into recovery mode. The recovery code is located at ANDROID_SRC/bootable/recovery. There are many custom recovery firmware images available. A notable example is ClockWorkMod.

There's more...

The three partitions just mentioned are the ones involved in flashing a new build of Android on to a device. In addition to these, there are a few other partitions that exist:

  • /data: This contains user data and is sometimes called the user-data partition. All user-installed applications, settings, and personal data are stored in this partition.
  • /cache: Will contain frequently accessed applications.
  • /sdcard: This is the SD card attached to the phone. It is not a partition on the internal device memory.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.252.8