自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
EROFS
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
EROFS 是 Linux 4.19 中推出的唯讀檔案系統。支援壓縮和去重複功能,並針對讀取效能進行最佳化。
EROFS 與其他壓縮檔案系統的主要差異在於,它支援原地解壓縮。壓縮資料會儲存在區塊結尾,以便解壓縮並儲存到同一頁面。在 EROFS 映像檔中,超過 99% 的區塊都能使用此配置,因此在讀取作業期間不需要分配額外的頁面。
EROFS 圖片不必經過壓縮。不過,使用壓縮功能時,圖片的平均大小會縮小約 25%。在最高壓縮等級下,圖片大小可縮小至原來的 45%。
無論是否使用壓縮功能,EROFS 在隨機和順序存取時間方面都比其他檔案系統表現優異。
版本變更
如要啟用 EROFS,請在 BoardConfig.mk
中使用檔案系統類型 erofs
。例如:
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 變更
fstab 類型為 erofs
,唯一需要的掛載選項為 ro
。如要保留測試以 EXT4 為基礎的 GSI 映像檔的功能,您可以為 /system.
使用兩個 fstab 項目。
例如:
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
壓縮調節
根據預設,EROFS 會壓縮成固定大小的區塊。啟用可變長度區塊可大幅提升壓縮效率。您可以使用下列標記設定此選項:
BOARD_EROFS_PCLUSTER_SIZE := 262144
這會將最大 PCLUSTER
或變數長度區塊大小設為 262144 位元組。該數字必須是 4096 的倍數。較高的值會導致邊際效益遞減,且可能會降低讀取效能,具體取決於裝置硬體。
停用壓縮
根據預設,壓縮方案為 lz4hc
。如要停用壓縮功能,請使用:
BOARD_EROFS_COMPRESSOR := none
您也可以針對個別區隔變更這項設定,例如:
BOARD_SYSTEMIMAGE_EROFS_COMPRESSOR := none
剔除重複資料
EROFS 可透過下列標記共用重複的區塊:
BOARD_EROFS_SHARE_DUP_BLOCKS := true
自 Android 13 起,您必須停用壓縮功能才能使用這個標記。
對網路旅行社的影響
自 Android 13 起,Virtual A/B 全面支援 EROFS。OTA 套件產生器可透過在檔案系統中,以智慧方式解壓縮 LZ4 串流,產生差異。只要來源和目標版本都使用相同的 LZ4 程式庫,OTA 套件的大小就會與以 EXT4 為基礎的 OTA 相近。即使 src
或 dst
版本未使用相同的 LZ4 程式庫,對 OTA 大小的影響也應該很小。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# EROFS is a read-only file system introduced in Linux 4.19. It supports\ncompression and deduplication, and is optimized for read performance.\n\nThe primary difference between EROFS and other compressed file systems is that\nit supports in-place decompression. Compressed data is stored at the end of\nblocks, so that it can be uncompressed into the same page. In an EROFS image,\nmore than 99% of blocks are able to use this scheme, thus eliminating the need\nto allocate extra pages during read operations.\n\nEROFS images don't have to be compressed. When using compression, however,\nimages are around 25% smaller on average. At the highest levels of compression,\nimages can be up to 45% smaller.\n\nWhether using compression or not, EROFS has been shown to outperform other\nfile systems in both random and sequential access times.\n\nBuild changes\n-------------\n\nTo enable EROFS, use the file system type `erofs` in `BoardConfig.mk`.\nFor example: \n\n BOARD_SYSTEMIMAGE_FILE_SYSTEM_TYPE := erofs\n BOARD_VENDORIMAGE_FILE_SYSTEM_TYPE := erofs\n BOARD_PRODUCTIMAGE_FILE_SYSTEM_TYPE := erofs\n BOARD_SYSTEM_EXTIMAGE_FILE_SYSTEM_TYPE := erofs\n BOARD_VENDOR_DLKMIMAGE_FILE_SYSTEM_TYPE := erofs\n BOARD_SYSTEM_DLKMIMAGE_FILE_SYSTEM_TYPE := erofs\n\nfstab changes\n-------------\n\nThe fstab type is `erofs`, and the only mount option needed is `ro`. To keep the\nability to test EXT4-based GSI images, you can use two fstab entries for\n`/system.`\n\nFor example: \n\n system /system erofs ro wait,slotselect,avb=vbmeta_system,logical,first_stage_mount\n system /system ext4 ro,barrier=1 wait,slotselect,avb=vbmeta_system,logical,first_stage_mount\n\nCompression tuning\n------------------\n\nBy default, EROFS compresses into fixed-size blocks. Compression efficacy can be\nincreased significantly by enabling variable-length blocks. This can be\nconfigured by the following flag: \n\n BOARD_EROFS_PCLUSTER_SIZE := 262144\n\nThis sets the maximum `PCLUSTER`, or variable length block size, to 262144\nbytes. The number must be a multiple of 4096. There are diminishing returns at\nhigher values, and higher values can decrease read performance depending on the\ndevice hardware.\n\nDisable compression\n-------------------\n\nBy default, the compression scheme is `lz4hc`. To disable compression, use: \n\n BOARD_EROFS_COMPRESSOR := none\n\nThis can be changed on a per-partition basis as well, for example: \n\n BOARD_SYSTEMIMAGE_EROFS_COMPRESSOR := none\n\nDeduplication\n-------------\n\nEROFS can share duplicate blocks with the following flag: \n\n BOARD_EROFS_SHARE_DUP_BLOCKS := true\n\nAs of Android 13, compression must be disabled to use this flag.\n\nImpact on OTAs\n--------------\n\nAs of Android 13, EROFS is fully supported with Virtual A/B. The OTA package\ngenerator can generate deltas by intelligently decompressing the LZ4\nstreams within the file system. As long as both the source and target builds use\nthe same LZ4 library, the OTA package is comparable in size to an\nEXT4-based OTA. Even if the `src` or `dst` builds don't use the same LZ4\nlibrary, it should only have a minor impact on OTA size."]]