• Home
Name Date Size #Lines LOC

..--

include/03-May-2024-427165

include_fstab/fstab/03-May-2024-13083

libdm/03-May-2024-3,2082,176

libfiemap/03-May-2024-4,2202,976

libfs_avb/03-May-2024-6,0184,219

liblp/03-May-2024-7,0864,874

libsnapshot/03-May-2024-24,12217,333

libstorage_literals/03-May-2024-9564

libvbmeta/03-May-2024-1,172690

tests/03-May-2024-3,3422,791

tools/03-May-2024-950806

.clang-formatD03-May-2024291

Android.bpD03-May-20246.4 KiB258248

OWNERSD03-May-202440 32

README.overlayfs.mdD03-May-20245.5 KiB129106

TEST_MAPPINGD03-May-2024344 2625

clean_scratch_files.cppD03-May-2024728 235

clean_scratch_files.rcD03-May-2024111 32

file_wait.cppD03-May-20247.2 KiB236174

fs_mgr.cppD03-May-202489.4 KiB2,3461,861

fs_mgr_boot_config.cppD03-May-20246 KiB174120

fs_mgr_dm_linear.cppD03-May-202410 KiB280211

fs_mgr_format.cppD03-May-20246 KiB184127

fs_mgr_fstab.cppD03-May-202434.5 KiB955734

fs_mgr_overlayfs.cppD03-May-202457.3 KiB1,6811,350

fs_mgr_priv.hD03-May-20244.1 KiB10733

fs_mgr_priv_boot_config.hD03-May-20241.6 KiB3817

fs_mgr_remount.cppD03-May-202417.9 KiB490404

fs_mgr_roots.cppD03-May-20245.6 KiB193146

fs_mgr_slotselect.cppD03-May-20242.6 KiB7739

fs_mgr_vendor_overlay.cppD03-May-20245.1 KiB13894

fs_mgr_verity.cppD03-May-202416.6 KiB558403

README.overlayfs.md

1Android OverlayFS Integration with adb Remount
2==============================================
3
4Introduction
5------------
6
7Users working with userdebug or eng builds expect to be able to remount the
8system partition as read-write and then add or modify any number of files
9without reflashing the system image, which is efficient for a development cycle.
10
11Limited memory systems use read-only types of file systems or dynamic
12Android partitions (DAPs). These file systems land system partition images
13right-sized, and have been deduped at the block level to compress the content.
14This means that a remount either isn’t possible, or isn't useful because of
15space limitations or support logistics.
16
17OverlayFS resolves these debug scenarios with the _adb disable-verity_ and
18_adb remount_ commands, which set up backing storage for a writable file
19system as an upper reference, and mount the lower reference on top.
20
21Performing a remount
22--------------------
23
24Use the following sequence to perform the remount.
25
26    $ adb root
27    $ adb disable-verity
28    $ adb reboot
29    $ adb wait-for-device
30    $ adb root
31    $ adb remount
32
33Then enter one of the following sequences:
34
35    $ adb shell stop
36    $ adb sync
37    $ adb shell start
38    $ adb reboot
39
40*or*
41
42    $ adb push <source> <destination>
43    $ adb reboot
44
45Note that you can replace these two lines in the above sequence:
46
47    $ adb disable-verity
48    $ adb reboot
49
50with this line:
51
52    $ adb remount -R
53
54**Note:** _adb remount -R_ won’t reboot if the device is already in the adb remount state.
55
56None of this changes if OverlayFS needs to be engaged.
57The decisions whether to use traditional direct file-system remount,
58or one wrapped by OverlayFS is automatically determined based on
59a probe of the file-system types and space remaining.
60
61### Backing Storage
62
63When *OverlayFS* logic is feasible, it uses either the
64**/cache/overlay/** directory for non-A/B devices, or the
65**/mnt/scratch/overlay** directory for A/B devices that have
66access to *LRAP*.
67It is also possible for an A/B device to use the system_<other> partition
68for backing storage. eg: if booting off system_a+vendor_a, use system_b.
69The backing store is used as soon as possible in the boot
70process and can occur at first stage init, or when the
71*mount_all* commands are run in init RC scripts.
72
73By attaching OverlayFS early, SEpolicy or init can be pushed and used after the exec phases of each stage.
74
75Caveats
76-------
77
78- Backing storage requires more space than immutable storage, as backing is
79  done file by file. Be mindful of wasted space. For example, defining
80  **BOARD_IMAGE_PARTITION_RESERVED_SIZE** has a negative impact on the
81  right-sizing of images and requires more free dynamic partition space.
82- The kernel requires **CONFIG_OVERLAY_FS=y**. If the kernel version is higher
83  than 4.4, it requires source to be in line with android-common kernels. 
84  The patch series is available on the upstream mailing list and the latest as
85  of Sep 5 2019 is https://www.spinics.net/lists/linux-mtd/msg08331.html
86  This patch adds an override_creds _mount_ option to OverlayFS that
87  permits legacy behavior for systems that do not have overlapping
88  sepolicy rules, principals of least privilege, which is how Android behaves.
89  For 4.19 and higher a rework of the xattr handling to deal with recursion
90  is required. https://patchwork.kernel.org/patch/11117145/ is a start of that
91  adjustment.
92- _adb enable-verity_ frees up OverlayFS and reverts the device to the state
93  prior to content updates. The update engine performs a full OTA.
94- _adb remount_ overrides are incompatible with OTA resources, so the update
95  engine may not run if fs_mgr_overlayfs_is_setup() returns true.
96- If a dynamic partition runs out of space, making a logical partition larger
97  may fail because of the scratch partition. If this happens, clear the scratch
98  storage by running either either _fastboot flashall_ or _adb enable-verity_.
99  Then reinstate the overrides and continue.
100- For implementation simplicity on retrofit dynamic partition devices,
101  take the whole alternate super (eg: if "*a*" slot, then the whole of
102  "*system_b*").
103  Since landing a filesystem on the alternate super physical device
104  without differentiating if it is setup to support logical or physical,
105  the alternate slot metadata and previous content will be lost.
106- There are other subtle caveats requiring complex logic to solve.
107  Have evaluated them as too complex or not worth the trouble, please
108  File a bug if a use case needs to be covered.
109  - The backing storage is treated fragile, if anything else has
110    issue with the space taken, the backing storage will be cleared
111    out and we reserve the right to not inform, if the layering
112    does not prevent any messaging.
113  - Space remaining threshold is hard coded.  If 1% or more space
114    still remains, OverlayFS will not be used, yet that amount of
115    space remaining is problematic.
116  - Flashing a partition via bootloader fastboot, as opposed to user
117    space fastbootd, is not detected, thus a partition may have
118    override content remaining.  adb enable-verity to wipe.
119  - Space is limited, there is near unlimited space on userdata,
120    we have made an architectural decision to not utilize
121    /data/overlay/ at this time.  Acquiring space to use for
122    backing remains an ongoing battle.
123  - First stage init, or ramdisk, can not be overriden.
124  - Backing storage will be discarded or ignored on errors, leading
125    to confusion.  When debugging using **adb remount** it is
126    currently advised to confirm update is present after a reboot
127    to develop confidence.
128- File bugs or submit fixes for review.
129