← Back to Blogs

Understanding Partitions in AOSP

From storage basics to creating your own custom partition

1 min read
Understanding Partitions in AOSP

What is a Partition?

A partition is a logical division of physical storage inside a device. Instead of treating the entire storage as one block, Android divides it into multiple independent sections. Each partition has a specific purpose, stores specific types of data, and has its own size, filesystem, and mount point.

Storage Technologies: eMMC vs UFS

eMMC (embedded MultiMediaCard)

UFS (Universal Flash Storage)

Types of Partitions in AOSP

Core System Partitions

Data and Runtime Partitions

Special Partitions

Dynamic Partitions (Modern AOSP)

The Persist Partition

The persist partition stores critical hardware calibration data that must survive a factory reset. While /data is wiped on reset, /persist is preserved. This ensures hardware continues functioning correctly after the device is reset to factory state.

Key AOSP Files for Partition Management

1. BoardConfig.mk

Defines the partition size and filesystem type. This is where physical dimensions are declared.

BoardConfig.mk - Partition Size Definition

  BOARD_MY_CUSTOMIMAGE_PARTITION_SIZE := 104857600
  BOARD_MY_CUSTOMIMAGE_FILE_SYSTEM_TYPE := ext4

2. Android.bp

Defines how the partition image is built during the Android build process.

Android.bp - Partition Image Build Definition

  android_filesystem {
      name: "my_customimage",
      partition_name: "my_custom",
      mount_point: "/my_custom",
  }

3. fstab (File System Table)

Tells Android where and how to mount each partition at boot time.

fstab - Mount Point Definition

  /dev/block/by-name/my_custom  /my_custom  ext4  defaults  wait

4. sepolicy (SELinux)

Defines SELinux security labels and access rules for the partition contents.

sepolicy - SELinux Label

  /my_custom(/.*)?  u:object_r:my_custom_file:s0

5. super_partition.xml (Dynamic Partitions)

Defines whether a partition exists inside the super partition and its allocated size.

super_partition.xml - Dynamic Partition Entry

  <partition name="my_custom" size="104857600"/>

How to Create a Custom Partition in AOSP

Step 6: Build and Flash

Build and Flash Commands

  m my_customimage
  fastboot flash my_custom my_custom.img

How to Add Content to a Custom Partition

During Build (via PRODUCT_COPY_FILES)

Copying Files at Build Time

  PRODUCT_COPY_FILES += \
    device/<vendor>/<device>/file.txt:my_custom/file.txt

At Runtime (via C/C++ code)

Reading/Writing at Runtime

  FILE *fp = fopen("/my_custom/data.txt", "w");
  fprintf(fp, "Hello");
  fclose(fp);
Key takeaway: Every partition in AOSP has a defined purpose, a size, a filesystem, a mount point, and SELinux rules. Creating a custom partition means touching all five of these configuration layers. Missing any one of them will either prevent the build from compiling, prevent mounting at boot, or cause SELinux denials at runtime.