EROFS

EROFS is a read-only file system introduced in Linux 4.19. It supports compression and deduplication, and is optimized for read performance.

The primary difference between EROFS and other compressed file systems is that it supports in-place decompression. Compressed data is stored at the end of blocks, so that it can be uncompressed into the same page. In an EROFS image, more than 99% of blocks are able to use this scheme, thus eliminating the need to allocate extra pages during read operations.

EROFS images don't have to be compressed. When using compression, however, images are around 25% smaller on average. At the highest levels of compression, images can be up to 45% smaller.

Whether using compression or not, EROFS has been shown to outperform other file systems in both random and sequential access times.

Build changes

To enable EROFS, use the file system type erofs in BoardConfig.mk. For example:

BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := erofs
BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := erofs
BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE := erofs
BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE := erofs
BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE := erofs
BOARD_SYSTEM_DLKMIMAGE_FILE_SYSTEM_TYPE := erofs

fstab changes

The fstab type is erofs, and the only mount option needed is ro. To keep the ability to test EXT4-based GSI images, you can use two fstab entries for /system.

For example:

system    /system    erofs   ro              wait,slotselect,avb=vbmeta_system,logical,first_stage_mount
system    /system    ext4    ro,barrier=1    wait,slotselect,avb=vbmeta_system,logical,first_stage_mount

Compression tuning

By default, EROFS compresses into fixed-size blocks. Compression efficacy can be increased significantly by enabling variable-length blocks. This can be configured by the following flag:

BOARD_EROFS_PCLUSTER_SIZE := 262144

This sets the maximum PCLUSTER, or variable length block size, to 262144 bytes. The number must be a multiple of 4096. There are diminishing returns at higher values, and higher values can decrease read performance depending on the device hardware.

Disable compression

By default, the compression scheme is lz4hc. To disable compression, use:

BOARD_EROFS_COMPRESSOR := none

This can be changed on a per-partition basis as well, for example:

BOARD_SYSTEMIMAGE_EROFS_COMPRESSOR := none

Deduplication

EROFS can share duplicate blocks with the following flag:

BOARD_EROFS_SHARE_DUP_BLOCKS := true

As of Android 13, compression must be disabled to use this flag.

Impact on OTAs

As of Android 13, EROFS is fully supported with Virtual A/B. The OTA package generator can generate deltas by intelligently decompressing the LZ4 streams within the file system. As long as both the source and target builds use the same LZ4 library, the OTA package is comparable in size to an EXT4-based OTA. Even if the src or dst builds don't use the same LZ4 library, it should only have a minor impact on OTA size.