Documentation for the script create_overlay_mount.sh

Last Update: 04.11.2026/bs
 

Contents


  1. Documentation for the script create_overlay_mount.sh
    1. Contents
    2. Introduction
    3. Author
    4. License
    5. History
    6. Details
      1. The action mount
      2. The action umount
      3. The action list
      4. The action list_disk
      5. The action delete
      6. The action test
      7. The action get
      8. The action mount_only
      9. The action diff
      10. The action diff_file
      11. The action undo
      12. The action restore
      13. The action remount
      14. The action clean
      15. Environment variables used by the script
      16. Description of the backend directories used for the overlay mounts
      17. Using Magisk and overlay mounts in parallel
      18. How to keep files installed via Magisk module
      19. Creating the overlay mounts early in the boot process
      20. Filesystem structure on a virtual disk
      21. Using multiple virtual disks in parallel
      22. Calculating the size for the file used as virtual disk
      23. Creating an empty virtual disk
      24. Increasing the size of a virtual disk
      25. Using virtual disks created on a non-Android OS
    7. Miscellaneous
      1. Instructions to create an overlay mount manually
        1. Commands to create an overlay mount for cut & paste
    8. Example disk images
      1. Virtual disk with a clang21 toolchain
      2. Virtual disk with a clang19 toolchain
      3. Virtual disk with Perl 5.42 and a minimal clang19 toolchain
    9. Test Environment
    10. Limitations
    11. Trouble Shooting
    12. Additional infos
      1. The Magisk Module magisk_overlayfs
      2. Other Magisk Modules using overlay mounts
    13. Downloads
    14. Links

 

Introduction


Since Android 10 many file systems in the Android OS are only mounted read-only and can no longer be mounted writable even by the root user. This is safe, but extremely unattractive.

One way to circumvent these restrictions is to install Magisk and Magisk modules. Magisk uses bind mounts to change or create files in the read-only file systems. This works very well to create or change binaries in /system/bin, for example. However, when creating the Magisk module you need to know which files are to be added or replaced.

To install new tools directly in Android via “make install”, for example, this does not work

A more flexible solution is the use of overlay mounts. As far as I know, overlay mounts have been supported in Android since Android 10 (at least partially).

No additional tools are required to use overlay mounts in Android.

Therefore, I wrote a little script to create and use overlay mounts in Android on rooted devices:

create_overlay_mount.sh


The usage for the script is:

ASUS_I006D:/data/local/tmp $ /data/local/tmp/create_overlay_mount.sh -h 

 create_overlay_mount.sh v2.0.0 beta - create one or more overlay mounts on a device running a rooted Android OS

 Usage:  create_overlay_mount.sh [-h|--help] [-V|--version] [--verbose|-v] [--noselinux] [--selinux] [--no_relabel|--relabel] [--initdisk|--format] [--no_su] [--sparse]
                                 [--yes|-y] [--no|-n] [--no_rootfs] [--relax] [--details]  [--short] [--active] [--nomagisk] [--patch] [var=value] [--run=script[,..,script#]] [help] [vars]
                                 [list] [list_disk] [delete] [test] [undo] [diff] [diff_file] [get] [restore] [clean] [mount_only] [mount] [mount_existing] [umount] [remount]
ASUS_I006D:/data/local/tmp $


The parameter can be entered in any order. All parameter not starting with a dash (-) or a slash (/) are action parameter. The action parameter defines what the script should do.

The first parameter found in the parameter list for the script not starting with a dash (-) or a slash (/) is the action parameter for this run; all other parameter not starting with a dash (-) must be file or directory names.


All parameter starting with a dash (-) are option parameter. And all other parameter are either filenames or directory names.


To view the detailed usage help use the parameter -v -h or help:


./create_overlay_mount.sh help

ASUS_I006D:/data/local/tmp $ /data/local/tmp/create_overlay_mount.sh help 

 create_overlay_mount.sh v2.0.0 beta - create one or more overlay mounts on a device running a rooted Android OS

 Usage:  create_overlay_mount.sh [-h|--help] [-V|--version] [--verbose|-v] [--noselinux] [--selinux] [--no_relabel|--relabel] [--initdisk|--format] [--no_su] [--sparse]
                                 [--yes|-y] [--no|-n] [--no_rootfs] [--relax] [--details]  [--short] [--active] [--nomagisk] [--patch] [var=value] [--run=script[,..,script#]] [help] [vars]
                                 [list] [list_disk] [delete] [test] [undo] [diff] [diff_file] [get] [restore] [clean] [mount_only] [mount] [mount_existing] [umount] [remount]
                                 [directory0] [... directory#] [default]

 The parameter that neither start with a "-" or "/" nor contain a "=" are the action parameter that determine what is to be done.
 Only one action parameter for a run is allowed.

 Without an action parameter the script prints the short usage help. If one or more directories are found in the parameter the default action is "mount".

 The script needs root access.

 If started as non-root user, the script restarts itself using "su -c $0 $@" if possible; use the parameter "--no-su" to disable this feature.

 All parameter starting with a "/" are considered to be a directory name (or filename for some of the actions)
 The parameter with the directory names are optional.

 The default directory list for the actions "mount", "diff", "get" and "undo" is the list of directories in the environment variable DIRS_TO_OVERLAY.
 The default directory list for the actions "test", "umount", and "remount" is the list of directories currently mounted to an overlay filesystem.

 There are no default values for the action "restore".

 "directory" parameter are not allowed for the actions "mount_only", "mount_existing", and "list". If the parameter "--relax" is used
 these action ignore "directory" parameter.

 The actions "vars" and "help" only print help messages.

 If the variable DIRS_TO_OVERLAY is empty the script uses the hardcoded default value for this variable:

   /system_ext  /product  /odm  /system

 "directory#" must be either "default", "none", or the fully qualified directory name of a directory.
 The value "none" deletes the current list of directories in the variable DIRS_TO_OVERLAY; the value "default" adds the default directories to the list
 of directories. The parameter can be used more than once.

 The known option parameter are:

 --version      print the script version and exit
 --verbose      print more messages
 --noselinux    disable SELinux at start of the script (SELinux is NOT enabled again by the script)
 --selinux      enable SELinux at start of the script (SELinux is NOT disabled again by the script)
 --no_relabel   do not modify the SELinux context for files with unlabeled or default SELinux context in the overlay filesystem
 --relabel      modify the SELinux context for files with unlabeled or default SELinux context in the overlay filesystems
                The default is not to relabel.
 --initdisk     format the virtual disk before creating the overlay mounts; this will undo all previous modifications in the filesystems
                Without this option the script never formats an existing virtual disk.
 --no_su        do not restart the script as user root automatically
 --sparse       create the virtual disk as a sparse file
 --yes          answer all questions with "yes"
 --no           answer all questions with "no"
 --no_rootfs    do not mount the original devices to ${BASEDIR}/rootfs; note that without these mounts the action "diff_file" does not work
 --relax        ignore parameter that are not a directory (e.g. symbolic links); ignore parameter that are not used for an action
 --details      print more details
 --short        print only the important information
 --active       the tasks diff, get, and undo should work only on the currently mounted overlay filesystems
 --nomagisk     do not create temporary bind mounts for the Magisk binaries; without this parameter the script creates temporary
                bind mounts for the executables magisk, su, resetprop, and magiskpolicy if Magisk is installed and an overlay filesystem
                should be created for the directory with these executables.
 --patch        write the output of the diff commmands (action "diff_file") to a file. The directory for the patch files is defined
                in the variable PATCH_DIR. The name of the patch file is the fully qualified filename with blanks and slashes ("/")
                replaced with underscores ("_")
                Existing patch files are renamed to "[filename].$$.bak"
 --run          run the executable "script" if it exists after the overlay mounts are inplace. "script" can be any executable.
                The parameter can be used multiple times; Note that "--script" is an alias for "--run".
                Ths option is only used for the action "mount".

 Options, that are not used for an action, are silently ignored. For example, the option "--patch" is only used for the action "diff_file".

 The known action parameter are:

 help           print verbose usage help
 vars           print only the list of supported environment variables; the script prints the default values and the current values of these variables
 list           list directories mounted on overlay filesystems
 list_disk      list all directories availalbe on the virtual disk mounted to ${BASEDIR}; use the option "--details" to print the details for the directories
 delete         delete the overlay directories for a directory on the virtual disk
 test           test write access to directories mounted on overlay filesystems;
                default is: test write access to all directories currently mounted on an overlay filesystems
 get            print the name of the backend used for a file or directory mounted on an overlay filesystem
 undo           undo all modifications done in a directory with an overlay mount; be aware that there is NO redo action!
                default is: undo all modifications done for all directories in the environment variable DIRS_TO_OVERLAY (regardless of the mount status)
 diff           list the file modifications for directories with overlay mounts
                default is: list the modifciations done for all directories in the environment variable DIRS_TO_OVERLAY (regardless of the mount status)
                Use the option "--active" to list only the files with modifications in the directories with an active overlay mount
                Use the opton "--short" to only print the number of modified or deleted files
                Use the option "--details" for a verbose list of the modified files
 diff_file      compare one or more new files to the existing files using diff; the task parameter can be files or directories
                use a trailing double slash (//) to executed diff for all files in the sub directories of a directory
                set the environment variable DIFF to specifiy the diff executable to use; use the environment variable DIFF_OPTIONS to define the
                options for the diff commmand; use the option "--short" to disable the summary output; use the option "--patch" to write the diff output
                to files (see above for details).
 restore        restore files or directories in a directory mounted on an overlay filesystem

 mount_only     mount the virtual disk and exit (do not create an overlay mount)
                The script does not relabel files if the parameter "mount_only" is used (even if there are relabel files in the overlay filesystems).
                To force relabeling the files when "mount_only" is used, add the option "--relabel"

 mount          mount the overlays for the directories
 mount_existing mount only the existing overlay filesystems on the virtual disk; this action will fail if there are conflicting entries on the virtual disk
                e.g. an entry for "/system" and "/system/etc"
 umount         umount the overlays for the directories; default is to umount all overlay mounts
 remount        remount the overlay mounts

 clean          umount all overlay mounts for the current BASEDIR and umount the virtual disk

 Other supported parameter:

 var=value sets the variable "var" to the value "value"


 The script can create temporary bind mounts for files that will no longer be available after an overlay mount is created for a directory. This
 applies, for example, to files created by a Magisk module.

 To create bind mounts for files before the overlay mounts are created, add the file names to the environment variable FILES_TO_KEEP.

 The number of filenames in the variable FILES_TO_KEEP is not limited; the filenames must be separated by whitespaces or commas.

 The filenames in the variable FILES_TO_KEEP are interpreted by the script using these rules:

 - filenames without a slash are searched in the directory "/system/bin",     Example:  bash -> /system/bin/bash

 - filenames starting with "bin/" are searched in the directory "/system",    Example:  bin/sh -> /system/bin/sh

 - filenames starting with "./" are searched in the directory "/system",      Example:  ./etc/ssh/sshd_config  -> /system/./etc/ssh/sshd_config

 - fully qualified names are searched in "/",                                 Example:  /system_ext/bin/rsync -> /system_ext/bin/rsync

 All files in other directories than /system must be specified with fully qualified filename.

 bind mounts for the Magisk binaries are created automatically (see the description for the parameter "--nomagisk" above)

 bind mounts for directories are not supported.

 The script creates bind mounts only for files in directories for which an overlay mount is requested.
 Other entries in the variable FILES_TO_KEEP are silently ignored

 The bind mounts are created in the directory "/data/local/tmp"; to use another directory for the bind mounts set the environment variable
 BIND_MOUNT_TARGET_DIR="<directory_name>"

 Please note that the bind mounts created by the script are not deleted when the overlay mount is removed.
 To delete the bind mounts, either manually unmount them or simply restart the phone.

 Note:

 The following information is only valid for virtual disks created in an OS other than Android, such as Linux.
 For virtual disks created in Android, the following information can be ignored.

 --------------------------------------------------------------------

 For virtual disks created on operating systems other than Android, the SELinux context for most files and directories on the virtual disk is
 “system_u:object_r:unlabeled_t:s0” or “unconfined_u:object_r:default_t:s0” or something similar. Because of this SELinux context, these files
 cannot be accessed by users without root privileges.
 Therefore, it is essential to correct the SELinux context for these files before they can be used.

 The “--relabel” parameter of the script create_overlay_mount.sh can be used for this purpose:

 If the “--relabel” parameter is specified, the script corrects the SELinux context for all files in the overlay directories for all
 directories specified in the parameters for the script. The SELinux context used for this modification is the SELinux context of the
 target directory for the overlay mount. The script modifies only the files with an SELinux context that matches the expression
 "*:unlabeled*" or "*:default:*"-.

 If the SELinux context of the files is to be corrected only for certain overlay file systems, the file “relabel” can be created in
 those directories. In this case, the “--relabel” parameter must not be specified.
 For the overlay filesystem for /system, this is, for example, the file ./upper/system/relabel. I

 To relabel the files in the overlay filesystem with other SELinux contexts, create a script to modify the SELinux context and
 run it as post install script using the parameter "--run=script". The script can also be located on the overlay filesystem.
 Do not use the parameter "--relabel" in this case.


 If the parameter “--norelabel” is specified, the “relabel” files are ignored.

 To correct the SELinux contexts in all overlay filesystems on the virtual disk, the following script command can also be used:

 create_overlay_mount.sh --relabel mount_only

 Using these parameter, the script mounts the virtual disk and corrects the SELinux context for all overlay filesystems on the
 virtual disk without mounting the overlay file systems.

 The code for correcting the SELinux context is currently implemented only for overlay filesystems for directories in the root directory
 (such as /system, /product, /vendor, etc.)

 Please note that this correction only needs to be performed once for each overlay file system on the virtual hard drive; however,
 it does no harm if the code to modify the SELinux context for the files is executed every time the virtual hard drive is mounted.

 For virtual disks created under Android, no correction is necessary.

 --------------------------------------------------------------------

 Overlay mounts are NOT persistent -- if something goes terrible wrong, simply reboot the phone.

 --------------------------------------------------------------------

 Notes

 Set the variable TRACE to any value before starting the script to execute it with "set -x"

 The detailed documentation for the script can be found here:

     http://bnsmb.de/android/Documentation_for_the_script_create_overlay_mount.sh.html


Supported environment variables:

Name                           Default Value                         Current Value
----                           -------------                         -------------
BASEDIR                        /dev/ov                               /dev/ov
BIND_MOUNT_TARGET_DIR          /data/local/tmp                       /data/local/tmp
DD                             /system/bin/dd                        /system/bin/dd
DIFF                           /system/bin/diff                      /system/bin/diff
DIFF_OPTIONS                   -u                                    -u
DIRS_TO_OVERLAY                /system_ext /product /odm /system     /system_ext /product /odm /system
EXTENSION_FOR_PATCH_FILES      .patch                                .patch
FILESYSTEM_SIZE                100m                                  100m
FILESYSTEM_TO_USE              ext4                                  ext4
FILES_TO_KEEP                                                       
IMAGE_FILE                     /data/local/tmp/image001              /data/local/tmp/image001
LOSETUP                        /system/bin/losetup                   /system/bin/losetup
MKFS                                                                
MKFS_OPTIONS                                                        
MOUNT                          /data/local/tmp/product/bin/mount     /data/local/tmp/product/bin/mount
MOUNT_OPTIONS                                                       
PATCH_DIR                      /data/local/tmp/patches               /data/local/tmp/patches
SELINUX_CONTEXT                u:object_r:system_file:s0             u:object_r:system_file:s0
TMP_MOUNT_OPTIONS                                                   
UMOUNT                         /system/bin/umount                    /system/bin/umount
UMOUNT_WAIT_TIME               0                                     0
USER_RESPONSE                                                       

Use the value "none" for the environment variables "*_OPTIONS" do remove all options


ASUS_I006D:/data/local/tmp $



Note:

The default for the environment variable MKFS is created dynamically based on the filesystem type to use:  mkfs.${FILESYSTEM_TO_USE}
----



The script create_overlay_mount.sh can be used to mount or umount an overlay filesystem for directories like /system , /system_ext, etc.
Overlay mounts for sub directories only, such as /system/priv-app or /system/priv-app/Shell, are also possible (but see the note below).

For directories mounted with an overlay mount the script can be used

- to test the write access (action parameter test)

- to list the files and directories changed or deleted (action parameter diff)

- to execute diff for modified files (action parameter diff_file)

- to undo all changes at once for one or more directories (action parameter undo)

- to restore changed files or deleted files or directories (action parameter restore)

- to print the current backend for each file or directory (action parameter get)


The other supported action parameter for the script are documented below.

Use the action parameter vars to only print the environment variables supported by the script:

/data/local/tmp/create_overlay_mount.sh vars
ASUS_I006D:/data/local/tmp $ /data/local/tmp/create_overlay_mount.sh vars  

Supported environment variables:

Name                           Default Value                         Current Value
----                           -------------                         -------------
BASEDIR                        /dev/ov                               /dev/ov
BIND_MOUNT_TARGET_DIR          /data/local/tmp                       /data/local/tmp
DD                             /system/bin/dd                        /system/bin/dd
DIFF                           /system/bin/diff                      /system/bin/diff
DIFF_OPTIONS                   -u                                    -u
DIRS_TO_OVERLAY                /system_ext /product /odm /system     /system_ext /product /odm /system
EXTENSION_FOR_PATCH_FILES      .patch                                .patch
FILESYSTEM_SIZE                100m                                  100m
FILESYSTEM_TO_USE              ext4                                  ext4
FILES_TO_KEEP                                                       
IMAGE_FILE                     /data/local/tmp/image001              /data/local/tmp/image001
LOSETUP                        /system/bin/losetup                   /system/bin/losetup
MKFS                                                                
MKFS_OPTIONS                                                        
MOUNT                          /data/local/tmp/product/bin/mount     /data/local/tmp/product/bin/mount
MOUNT_OPTIONS                                                       
PATCH_DIR                      /data/local/tmp/patches               /data/local/tmp/patches
SELINUX_CONTEXT                u:object_r:system_file:s0             u:object_r:system_file:s0
TMP_MOUNT_OPTIONS                                                   
UMOUNT                         /system/bin/umount                    /system/bin/umount
UMOUNT_WAIT_TIME               0                                     0
USER_RESPONSE                                                       

Use the value "none" for the environment variables "*_OPTIONS" do remove all options


ASUS_I006D:/data/local/tmp $


ASUS_I006D:/ $


see here for the description for these variables

----


The script only requires binaries that are part of the standard Android OS (e.g. mount, umount, dd, df, losetup, mkfs.ext4 )

Since there might be a "problem" using the umount binary and the sh binary in Android to umount the system directories (see here), I created a statically linked umount binary and a statically linked bash binary -- see the Downloads section below.


Please note that overlay mounts for sub directories, such as /system/priv-app or /system/bin, are not actually intended in the design for overlay mounts and can therefore lead to unexpected problems (see also here)


For first tests, I recommend not to create an overlay mount for the directory /system:

If something fails when creating an overlay for /system, there is no access to any of the executables and files in the directory /system anymore and a reboot via Android GUI is required to fix that



Author


Bernd Schemmer (Bernd.Schemmer@gmx.de)



License


License
                                 Apache License
                           Version 2.0, January 2004
                        http://www.apache.org/licenses/

   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

   1. Definitions.

      "License" shall mean the terms and conditions for use, reproduction,
      and distribution as defined by Sections 1 through 9 of this document.

      "Licensor" shall mean the copyright owner or entity authorized by
      the copyright owner that is granting the License.

      "Legal Entity" shall mean the union of the acting entity and all
      other entities that control, are controlled by, or are under common
      control with that entity. For the purposes of this definition,
      "control" means (i) the power, direct or indirect, to cause the
      direction or management of such entity, whether by contract or
      otherwise, or (ii) ownership of fifty percent (50%) or more of the
      outstanding shares, or (iii) beneficial ownership of such entity.

      "You" (or "Your") shall mean an individual or Legal Entity
      exercising permissions granted by this License.

      "Source" form shall mean the preferred form for making modifications,
      including but not limited to software source code, documentation
      source, and configuration files.

      "Object" form shall mean any form resulting from mechanical
      transformation or translation of a Source form, including but
      not limited to compiled object code, generated documentation,
      and conversions to other media types.

      "Work" shall mean the work of authorship, whether in Source or
      Object form, made available under the License, as indicated by a
      copyright notice that is included in or attached to the work
      (an example is provided in the Appendix below).

      "Derivative Works" shall mean any work, whether in Source or Object
      form, that is based on (or derived from) the Work and for which the
      editorial revisions, annotations, elaborations, or other modifications
      represent, as a whole, an original work of authorship. For the purposes
      of this License, Derivative Works shall not include works that remain
      separable from, or merely link (or bind by name) to the interfaces of,
      the Work and Derivative Works thereof.

      "Contribution" shall mean any work of authorship, including
      the original version of the Work and any modifications or additions
      to that Work or Derivative Works thereof, that is intentionally
      submitted to Licensor for inclusion in the Work by the copyright owner
      or by an individual or Legal Entity authorized to submit on behalf of
      the copyright owner. For the purposes of this definition, "submitted"
      means any form of electronic, verbal, or written communication sent
      to the Licensor or its representatives, including but not limited to
      communication on electronic mailing lists, source code control systems,
      and issue tracking systems that are managed by, or on behalf of, the
      Licensor for the purpose of discussing and improving the Work, but
      excluding communication that is conspicuously marked or otherwise
      designated in writing by the copyright owner as "Not a Contribution."

      "Contributor" shall mean Licensor and any individual or Legal Entity
      on behalf of whom a Contribution has been received by Licensor and
      subsequently incorporated within the Work.

   2. Grant of Copyright License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      copyright license to reproduce, prepare Derivative Works of,
      publicly display, publicly perform, sublicense, and distribute the
      Work and such Derivative Works in Source or Object form.

   3. Grant of Patent License. Subject to the terms and conditions of
      this License, each Contributor hereby grants to You a perpetual,
      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
      (except as stated in this section) patent license to make, have made,
      use, offer to sell, sell, import, and otherwise transfer the Work,
      where such license applies only to those patent claims licensable
      by such Contributor that are necessarily infringed by their
      Contribution(s) alone or by combination of their Contribution(s)
      with the Work to which such Contribution(s) was submitted. If You
      institute patent litigation against any entity (including a
      cross-claim or counterclaim in a lawsuit) alleging that the Work
      or a Contribution incorporated within the Work constitutes direct
      or contributory patent infringement, then any patent licenses
      granted to You under this License for that Work shall terminate
      as of the date such litigation is filed.

   4. Redistribution. You may reproduce and distribute copies of the
      Work or Derivative Works thereof in any medium, with or without
      modifications, and in Source or Object form, provided that You
      meet the following conditions:

      (a) You must give any other recipients of the Work or
          Derivative Works a copy of this License; and

      (b) You must cause any modified files to carry prominent notices
          stating that You changed the files; and

      (c) You must retain, in the Source form of any Derivative Works
          that You distribute, all copyright, patent, trademark, and
          attribution notices from the Source form of the Work,
          excluding those notices that do not pertain to any part of
          the Derivative Works; and

      (d) If the Work includes a "NOTICE" text file as part of its
          distribution, then any Derivative Works that You distribute must
          include a readable copy of the attribution notices contained
          within such NOTICE file, excluding those notices that do not
          pertain to any part of the Derivative Works, in at least one
          of the following places: within a NOTICE text file distributed
          as part of the Derivative Works; within the Source form or
          documentation, if provided along with the Derivative Works; or,
          within a display generated by the Derivative Works, if and
          wherever such third-party notices normally appear. The contents
          of the NOTICE file are for informational purposes only and
          do not modify the License. You may add Your own attribution
          notices within Derivative Works that You distribute, alongside
          or as an addendum to the NOTICE text from the Work, provided
          that such additional attribution notices cannot be construed
          as modifying the License.

      You may add Your own copyright statement to Your modifications and
      may provide additional or different license terms and conditions
      for use, reproduction, or distribution of Your modifications, or
      for any such Derivative Works as a whole, provided Your use,
      reproduction, and distribution of the Work otherwise complies with
      the conditions stated in this License.

   5. Submission of Contributions. Unless You explicitly state otherwise,
      any Contribution intentionally submitted for inclusion in the Work
      by You to the Licensor shall be under the terms and conditions of
      this License, without any additional terms or conditions.
      Notwithstanding the above, nothing herein shall supersede or modify
      the terms of any separate license agreement you may have executed
      with Licensor regarding such Contributions.

   6. Trademarks. This License does not grant permission to use the trade
      names, trademarks, service marks, or product names of the Licensor,
      except as required for reasonable and customary use in describing the
      origin of the Work and reproducing the content of the NOTICE file.

   7. Disclaimer of Warranty. Unless required by applicable law or
      agreed to in writing, Licensor provides the Work (and each
      Contributor provides its Contributions) on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
      implied, including, without limitation, any warranties or conditions
      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
      PARTICULAR PURPOSE. You are solely responsible for determining the
      appropriateness of using or redistributing the Work and assume any
      risks associated with Your exercise of permissions under this License.

   8. Limitation of Liability. In no event and under no legal theory,
      whether in tort (including negligence), contract, or otherwise,
      unless required by applicable law (such as deliberate and grossly
      negligent acts) or agreed to in writing, shall any Contributor be
      liable to You for damages, including any direct, indirect, special,
      incidental, or consequential damages of any character arising as a
      result of this License or out of the use or inability to use the
      Work (including but not limited to damages for loss of goodwill,
      work stoppage, computer failure or malfunction, or any and all
      other commercial damages or losses), even if such Contributor
      has been advised of the possibility of such damages.

   9. Accepting Warranty or Additional Liability. While redistributing
      the Work or Derivative Works thereof, You may choose to offer,
      and charge a fee for, acceptance of support, warranty, indemnity,
      or other liability obligations and/or rights consistent with this
      License. However, in accepting such obligations, You may act only
      on Your own behalf and on Your sole responsibility, not on behalf
      of any other Contributor, and only if You agree to indemnify,
      defend, and hold each Contributor harmless for any liability
      incurred by, or claims asserted against, such Contributor by reason
      of your accepting any such warranty or additional liability.

   END OF TERMS AND CONDITIONS

   APPENDIX: How to apply the Apache License to your work.

      To apply the Apache License to your work, attach the following
      boilerplate notice, with the fields enclosed by brackets "[]"
      replaced with your own identifying information. (Don't include
      the brackets!)  The text should be enclosed in the appropriate
      comment syntax for the file format. We also recommend that a
      file or class name and description of purpose be included on the
      same "printed page" as the copyright notice for easier
      identification within third-party archives.

   Copyright [yyyy] [name of copyright owner]

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.



----


History


ChangeLog


04.11.2026

adapted the documentation to the script version 1.6.0
added the section Miscellaneous 
added the section Instructions to create an overlay mount manually  
added the section Commands to create an overlay mount for cut & paste  
added the section Calculating the size for the file used as virtual disk  
move the description for the various actions to separate sections


30.10.2026

adapted the documentation to the script version 1.6.0
added the section How to keep files installed via Magisk module      


01.08.2026

adapted the documentation to the script version 1.5.0
added the section Using virtual disks created on a non-Android OS 
added the section Filesystem structure on a virtual disk  


29.07.2026

adapted the documentation to the script version 1.4.1


28.07.2026

adapted the documentation to the script version 1.4.0


28.05.2026

added the section Other Magisk Modules using overlay mounts         


31.10.2025

adapted the documentation to the script version 1.3.1


23.10.2025

adapted the documentation to the script version 1.3.0
added the section about using Magisk and overlay mounts in parallel 
moved the infos about the Magisk Module for implementing overlay mounts to a separate section 


20.10.2025 /bs

added the documentation for the virtual disk with clang21 toolchain         
corrected a bug in the section Virtual disk with a clang19 toolchain :  -Wno-int-conversion instead of -Wno-int-conversioni  in the command to define the CFLAGS for compiling nano
added some more info about using overlay mounts and Magisk in parallel 


22.06.2025 /bs

Initial release

23.06.2025 /bs

corrected the infos about how to use the virtual disk from the Magisk Module with overlayfs 
added the hint about "lost" files in mounted sub directories 
added infos about overlay mounts for /vendor
the directory /vendor is not in the default list with directories for overlay mounts anymore.

24.06.2025 /bs

default mount point is now /dev/ov
mount points to sub directories in a directory are now remounted after creating the overlay mount

10.07.2025 /bs

added the documentation about the Example Disk images 


11.07.2025 /bs

minor bug fixes; add the instructions to compile nano.


----


Details


create_overlay_mount.sh requires root privileges. If the script is run by a non-root user, it will restart itself using “su -c $0 $@” if possible (use the parameter --no-su to disable this feature).

Note that root access is also necessary to create or change files or directories in the system directories mounted to overlay mounts.

The filesystem type used for the filesystem mounted on /data does not support overlay mounts. Therefore, the script creates a file, configures that file as virtual disk, formats the virtual disk with the ext4 filesystem and mounts the virtual disk. The filesystem on the virtual disks is than used as backend for the overlay mounts. If the virtual disk already exists, the script uses it again without formatting it.

All changes in the directories mounted via overlay mounts are saved on the virtual disk. Therefore, the changes in the directories that are mounted via the overlay file system are persistent as long as the virtual disk used as the backend for the overlay mounts exists.

Overlay mounts can be created for most of the directories, except for directories in filesystems that do not support overlay mounts and some directories with special meaning (like /dev, /sys, /proc detc.).

To find out whether an overlay mount can be created for a directory, simply test it with the script. If it does not work, the script simply fails, but does not break anything.

Example
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  /oem
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem

Creating and mounting the directories for the overlay mount for "/oem" ...
Creating the directory "/dev/ov/upper/oem" ...
chcon: '/dev/ov/upper/oem' to u:object_r:oemfs:s0: Permission denied
WARNING: Error changing the SELinux context for the directory "/dev/ov/upper/oem" to "u:object_r:oemfs:s0"
ERROR: Error creating the directory "/dev/ov/upper/oem" (RC=50)
50|ASUS_I006D:/data/local/tmp 


----
 
Please note that even though it is possible to create an overlay mount for /data, this is really not a good idea. In most cases, it does not work as intended, and it causes problems with the Android OS itself.
(see the Guide How to use overlay mounts for directories in data for instructions to use an overlay mount for a sub directory in /data)


If the script is executed without a parameter, the script prints the short usage help.

If there are one or more directories in the parameter but no action parameter, the default action is mount .

If the script is executed with an action parameter and one or more directories or files in the parameter, the requested action is done only for the directories or files in the parameter (as long as this is supported by the action).

If the script is executed with an action parameter but without a directory, the action is done for the directories in the default directory list for that action.

The default directory lists used for the different actions of the script are:

Action
Default directories
Comment
mount
directories listed in the environment variable DIRS_TO_OVERLAY
use the action mount_existing to only mount the existing overlay filesystems on a virtual disk

use the action mount_only to only mount the virtual disk without creating the overlay mounts

diff
directories listed in the environment variable DIRS_TO_OVERLAY
the action is done regardless of the mount status of the directories

use the option --active to process only the mounted overlay filesystems
undo
directories listed in the environment variable DIRS_TO_OVERLAY
the action is done regardless of the mount status of the directories

use the option --active to process only the mounted overlay filesystems



test
directories currently mounted with an overlay filesystem

umount
directories currently mounted with an overlay filesystem
remount
directories currently mounted with an overlay filesystem
get
directories listed in the environment variable DIRS_TO_OVERLAY use the option --active to process only the mounted overlay filesystems

This action can also be used for files.





To explicitly request one of the actions only for the directories listed in the variable DIRS_TO_OVERLAY, use the parameter default.


The default value for the variable DIRS_TO_OVERLAY hard-coded in the script is:

/system_ext
/product
/odm
/system
  

(see below for the description of the environment variables supported by the script)

 




Note

Most of the examples below were executed in the OmniROM and in /e/ - the directories may look different in other Android distributions


The action mount


To create the overlay mounts, use the action parameter mount.

When using the action parameter mount, the script will also create the image file for the overlay mounts if it does not yet exist. The environment variables used for creating the image file are:


Name                       Default Value                     
----                       -------------                     
BASEDIR                    /dev/ov                           

DD                         /system/bin/dd                    
FILESYSTEM_SIZE            100m                              
FILESYSTEM_TO_USE          ext4                              
IMAGE_FILE                 /data/local/tmp/image001          
LOSETUP                    /system/bin/losetup               
MKFS                                                            
MKFS_OPTIONS                                                    
MOUNT                      /system/bin/mount                 
MOUNT_OPTIONS 
TMP_MOUNT_OPTIONS                                                 

SELINUX_CONTEXT            u:object_r:system_file:s0         


BASEDIR is the directory used as mount point for the virtual disk for the overlay filesystem; the directory will be created by the script if it does not yet exist. The parent directory for the BASEDIR must have writable and executable permissions for all users.

The default for the variable MKFS is build using the value for FILESYSTEM_TO_USE, e.g. if FILESYSTEM_TO_USE is ext4 the default value for MKFS is mkfs.ext4.

In the default configuration, the script creates a regular file for the virtual disk. To create the file for the virtual disk as a sparse file, add the option --sparse (see also Calculating the size for the file used as virtual disk)

For existing files for virtual disks, the script assumes that they are formatted with a filesystem known by Android and usable for overlay mounts.

To force the creation of a file system on an existing virtual hard disk, use the option --format. (but note that this will destroy all data on the virtual disk)

(see below for the description of the environment variables supported by the script)


Example output of running the script with the parameter mount the first time:


/data/local/tmp/create_overlay_mount.sh mount


ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh mount
Creating the image file "/data/local/tmp/image001" with the size 100m ...
1+0 records in
1+0 records out
104857600 bytes (100 M) copied, 0.084 s, 1.1 G/s
Result:
-rw-r--r-- 1 root root 104857600 2026-11-05 13:17 /data/local/tmp/image001

Creating a "ext4" filesystem on the image file "/data/local/tmp/image001" now ...
mke2fs 1.46.6 (1-Feb-2023)
128-byte inodes cannot handle dates beyond 2038 and are deprecated
Discarding device blocks: done                           
Creating filesystem with 102400 1k blocks and 25688 inodes
Filesystem UUID: 2225c003-0097-481d-a5ed-5b1cd4ebed28
Superblock backups stored on blocks:
    8193, 24577, 40961, 57345, 73729

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Creating the directory "/dev/ov" ...
Mounting the image file "/data/local/tmp/image001" to "/dev/ov" ...
Creating the directory "/dev/ov/upper" ...
Creating the directory "/dev/ov/merged" ...
Creating the directory "/dev/ov/work" ...

Creating and mounting the directories for the overlay mount for "/system_ext" ...

Creating the directory "/dev/ov/upper/system_ext" ...
Creating the directory "/dev/ov/merged/system_ext" ...
Creating the directory "/dev/ov/work/system_ext" ...
Creating the overlay mount for "/system_ext" ...
Creating the directory "/dev/ov/rootfs" ...
Mounting "/dev/ov/rootfs" on "/dev/block/dm-2" ...
Mounting "/dev/ov/rootfs/system_ext" on "/dev/block/dm-3" ...
Creating the bind mount "/system_ext"...
Checking the overlay mount for "/system_ext" ...

Creating and mounting the directories for the overlay mount for "/product" ...

Magisk is installed in /product/bin - creating temporary copies of the Magisk executables ...
Creating the temporary file "/data/local/tmp/product/bin/magisk" ...
Creating the temporary file "/data/local/tmp/product/bin/su" ...
Creating the temporary file "/data/local/tmp/product/bin/resetprop" ...
Creating the temporary file "/data/local/tmp/product/bin/magiskpolicy" ...

Creating the directory "/dev/ov/upper/product" ...
Creating the directory "/dev/ov/merged/product" ...
Creating the directory "/dev/ov/work/product" ...
Creating the overlay mount for "/product" ...
Mounting "/dev/ov/rootfs/product" on "/dev/block/dm-1" ...
Creating the bind mount "/product"...
Checking the overlay mount for "/product" ...

Creating and mounting the directories for the overlay mount for "/odm" ...

Creating the directory "/dev/ov/upper/odm" ...
Creating the directory "/dev/ov/merged/odm" ...
Creating the directory "/dev/ov/work/odm" ...
Creating the overlay mount for "/odm" ...
Mounting "/dev/ov/rootfs/odm" on "/dev/block/dm-0" ...
Creating the bind mount "/odm"...
Checking the overlay mount for "/odm" ...

Creating and mounting the directories for the overlay mount for "/system" ...

Creating the directory "/dev/ov/upper/system" ...
Creating the directory "/dev/ov/merged/system" ...
Creating the directory "/dev/ov/work/system" ...
Creating the overlay mount for "/system" ...
 "/system" is not on a separate device -- no temporary mount is necessary or this directory
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Summary:
--------

4 overlay mount(s) created:

  /system_ext
  /product
  /odm
  /system

ASUS_I006D:/ $

----


To only create an overlay mount for the directory /odm_dlkm the script usage is

/data/local/tmp/create_overlay_mount.sh mount /odm_dlkm

or (mount is the default action if only directory names are found in the parameter):

/data/local/tmp/create_overlay_mount.sh /odm_dlkm

Example:

(in this example the file used as virtual disk already exists):

/data/local/tmp/create_overlay_mount.sh /odm_dlkm
ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh /odm_dlkm
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/odm_dlkm" ...

Creating the directory "/dev/ov/upper/odm_dlkm" ...
Creating the directory "/dev/ov/merged/odm_dlkm" ...
Creating the overlay mount for "/odm_dlkm" ...
Creating the bind mount "/odm_dlkm"...
Checking the overlay mount for "/odm_dlkm" ...

Summary:
--------

1 overlay mount(s) created:

  /odm_dlkm

ASUS_I006D:/ $


----


To create an overlay mount for an additional directory, execute the script again, for example to create an additional overlay mount for the directory /vendor:

/data/local/tmp/create_overlay_mount.sh /vendor

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh /vendor 
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/vendor" ...

Creating the overlay mount for "/vendor" ...
Mounting "/dev/ov/rootfs/vendor" on "/dev/block/dm-4" ...
Creating the bind mount "/vendor"...
Remounting the mount point "/vendor/bt_firmware" ...
Remounting the mount point "/vendor/dsp" ...
Remounting the mount point "/vendor/firmware_mnt" ...
Checking the overlay mount for "/vendor" ...

Summary:
--------

1 overlay mount(s) created:

  /vendor

ASUS_I006D:/ $

----


Directory parameters for the script overwrite the variable DIRS_TO_OVERLAY. To create an overlay mount for the default directories and additional directories, use the parameter default.

For example, to create overlay mounts for the default directories and the directories /vendor/app and /vendor/bin, execute:

/data/local/tmp/create_overlay_mount.sh default /vendor/app /vendor/bin
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh default /vendor/app /vendor/bin
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem

Creating and mounting the directories for the overlay mount for "/system_ext" ...
Creating the overlay mount for "/system_ext" ...
Creating the bind mount "/system_ext"...
Checking the overlay mount for "/system_ext" ...

Creating and mounting the directories for the overlay mount for "/product" ...
Creating the overlay mount for "/product" ...
Creating the bind mount "/product"...
Checking the overlay mount for "/product" ...

Creating and mounting the directories for the overlay mount for "/odm" ...
Creating the overlay mount for "/odm" ...
Creating the bind mount "/odm"...
Checking the overlay mount for "/odm" ...

Creating and mounting the directories for the overlay mount for "/system" ...
Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Creating and mounting the directories for the overlay mount for "/vendor/app" ...
Creating the overlay mount for "/vendor/app" ...
Creating the bind mount "/vendor/app"...
Checking the overlay mount for "/vendor/app" ...

Creating and mounting the directories for the overlay mount for "/vendor/bin" ...
Creating the overlay mount for "/vendor/bin" ...
Creating the bind mount "/vendor/bin"...
Checking the overlay mount for "/vendor/bin" ...

Summary:
--------

6 overlay mount(s) created:

  /system_ext
  /product
  /odm
  /system
  /vendor/app
  /vendor/bin

ASUS_I006D:/data/local/tmp #

----


The script refuses to create an overlay mount if there is already an overlay mount for a directory in place, example:

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh /system_ext 
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/system_ext" ...
There is already an overlay mount for the directory "/system_ext" in place

Summary:
--------

1 directory or files are already on an overlay mount:

  /system_ext

ASUS_I006D:/ $


Note that it is not possible to create an overlay mount for a sub directory if there is already an overlay mount for the parent directory in place.

For example, if an overlay mount for /system already exists, you cannot create an overlay mount for /system/etc. Similarly, you cannot use this script to create an overlay mount for /system if an overlay mount for a sub directory such as /system/etc already exists.

The script automatically creates all the directories required for the overlay mount for a directory on the virtual hard drive, provided they do not already exist.


To only mount the existing overlay mounts on a virtual disk, use the action mount_existing. The action parameter mount_existing is only allowed, if there are no conflicting directories on the virtual disk .

For example, if there are separate directories for /system and for /system/etc on the virtual disk, the action mount_existing is not allowed.

Virtual disks can contain an unlimited number of overlay directories. They can be used as needed.

The script can also be used to create overlay mounts for sub directories, e.g. to create overlay filesystems for the directories /*/etc and the directory /system_ext/framework do

/data/local/tmp/create_overlay_mount.sh --relax /*/etc /system_ext/framework
|ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh --relax /*/etc /system_ext/framework 
WARNING: The parameter "/odm_dlkm/etc" is not a directory - the parameter will be ignored
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/odm/etc" ...
Creating the overlay mount for "/odm/etc" ...
Creating the bind mount "/odm/etc"...
Checking the overlay mount for "/odm/etc" ...

Creating and mounting the directories for the overlay mount for "/product/etc" ...
Creating the overlay mount for "/product/etc" ...
Creating the bind mount "/product/etc"...
Checking the overlay mount for "/product/etc" ...

Creating and mounting the directories for the overlay mount for "/system/etc" ...
Creating the overlay mount for "/system/etc" ...
Creating the bind mount "/system/etc"...
Checking the overlay mount for "/system/etc" ...
WARNING: Seems like the overlay mount for "/system/etc" works only partial -- please check the directory contents

Creating and mounting the directories for the overlay mount for "/system_ext/etc" ...
Creating the overlay mount for "/system_ext/etc" ...
Creating the bind mount "/system_ext/etc"...
Checking the overlay mount for "/system_ext/etc" ...

Creating and mounting the directories for the overlay mount for "/vendor/etc" ...
Creating the overlay mount for "/vendor/etc" ...
Creating the bind mount "/vendor/etc"...
Checking the overlay mount for "/vendor/etc" ...

Creating and mounting the directories for the overlay mount for "/vendor_dlkm/etc" ...
Creating the overlay mount for "/vendor_dlkm/etc" ...
Creating the bind mount "/vendor_dlkm/etc"...
Checking the overlay mount for "/vendor_dlkm/etc" ...

Creating and mounting the directories for the overlay mount for "/system_ext/framework" ...
Creating the overlay mount for "/system_ext/framework" ...
Creating the bind mount "/system_ext/framework"...
Checking the overlay mount for "/system_ext/framework" ...

Summary:
--------

7 overlay mount(s) created:

  /odm/etc
  /product/etc
  /system/etc
  /system_ext/etc
  /vendor/etc
  /vendor_dlkm/etc
  /system_ext/framework

ASUS_I006D:/ $


see below for the reason for the warning message: "WARNING: Seems like the overlay mount for "/system/etc" works only partial -- please check the directory contents"  

To remove the overlay mount for /system/etc execute this command:

/data/local/tmp/create_overlay_mount.sh umount /system/etc  


----


The action list_disk can be used to list all directories on a mounted virtual disk.



The action umount


The action umount can be used to umount overlay mounts. Without a directory parameter, the action umounts all overlay mounts for the current BASEDIR.

Example:

/data/local/tmp/create_overlay_mount.sh umount
ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list
Directories mounted on an overlay filesystem

/system_ext
/odm
/odm_dlkm
/vendor_dlkm


ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh umount
Umounting the bind mounts ...
Umounting the bind mount "/system_ext" ...
Umounting the bind mount "/odm" ...
Umounting the bind mount "/odm_dlkm" ...
Umounting the bind mount "/vendor_dlkm" ...
 ... done
Umounting the overlay mounts ...
Umounting "/dev/ov/merged/system_ext" ...
Umounting "/dev/ov/merged/odm" ...
Umounting "/dev/ov/merged/odm_dlkm" ...
Umounting "/dev/ov/merged/vendor_dlkm" ...
 ... done

Umounting the temporay mounts for the original directories ...
Umounting "/dev/ov/rootfs/system_ext" ...
Umounting "/dev/ov/rootfs/odm" ...
Umounting "/dev/ov/rootfs/vendor_dlkm" ...

ASUS_I006D:/data/local/tmp $


----


Note that umounting an overlay mount for /system may fail -- see below for a workaround for this problem.


To umount only the overlays of the directories /product and /odm use this command:

/data/local/tmp/create_overlay_mount.sh umount /product /odm
ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh umount /product /odm 
Umounting the bind mounts ...
Umounting the bind mount "/product" ...
Umounting the bind mount "/odm" ...
 ... done
Umounting the overlay mounts ...
Umounting "/dev/ov/merged/product" ...
Umounting "/dev/ov/merged/odm" ...
 ... done

Umounting the temporay mounts for the original directories ...
Umounting "/dev/ov/rootfs/product" ...
Umounting "/dev/ov/rootfs/odm" ...

ASUS_I006D:/data/local/tmp $


----


More examples

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list --details 
Directories mounted on an overlay filesystem

Directory         Backend Directory
---------         -----------------

/vendor           /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/vendor_dlkm      /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/odm              /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/odm_dlkm         /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh umount
WARNING: "/vendor" is not mounted on an overlay filesystem for the basedir "/dev/ov"
WARNING: "/vendor_dlkm" is not mounted on an overlay filesystem for the basedir "/dev/ov"
WARNING: "/odm" is not mounted on an overlay filesystem for the basedir "/dev/ov"
WARNING: "/odm_dlkm" is not mounted on an overlay filesystem for the basedir "/dev/ov"

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh BASEDIR=/data/local/tmp/virtualfs002 umount
WARNING: "/vendor" is not mounted on an overlay filesystem for the basedir "/data/local/tmp/virtualfs002"
WARNING: "/vendor_dlkm" is not mounted on an overlay filesystem for the basedir "/data/local/tmp/virtualfs002"
Umounting the bind mounts ...
Umounting the bind mount "/odm" ...
Umounting the bind mount "/odm_dlkm" ...
 ... done
Umounting the overlay mounts ...
Umounting "/data/local/tmp/virtualfs002/merged/odm" ...
Umounting "/data/local/tmp/virtualfs002/merged/odm_dlkm" ...
 ... done

Umounting the temporay mounts for the original directories ...
Umounting "/data/local/tmp/virtualfs002/rootfs/odm" ...

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh  umount /vendor_dlkm
WARNING: "/vendor_dlkm" is not mounted on an overlay filesystem for the basedir "/dev/ov"

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh  umount BASEDIR=/data/local/tmp/virtualfs001 /vendor_dlkm
Umounting the bind mounts ...
Umounting the bind mount "/vendor_dlkm" ...
 ... done
Umounting the overlay mounts ...
Umounting "/data/local/tmp/virtualfs001/merged/vendor_dlkm" ...
 ... done

Umounting the temporay mounts for the original directories ...
Umounting "/data/local/tmp/virtualfs001/rootfs/vendor_dlkm" ...

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $  ./create_overlay_mount.sh list
Directories mounted on an overlay filesystem

/vendor


ASUS_I006D:/data/local/tmp $



----


Use the action clean to umount all overlay mounts independent from the BASEDIR used for the overlay mounts.

 

The action list


To list the overlay mounts created by the script use the action list :

/data/local/tmp/create_overlay_mount.sh list

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh list
Directories mounted on an overlay filesystem

/system_ext
/product
/odm
/system
/vendor/app
/vendor/bin


ASUS_I006D:/data/local/tmp #


----

Use the parameter --details to print also the BASEDIR and the virtual disk used for an overlay mount:

/data/local/tmp/create_overlay_mount.sh list --details
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh list --details
Directories mounted on an overlay filesystem

Directory        Backend Directory
---------        -----------------
/system_ext      /dev/ov (Virtual disk: /data/local/tmp/image001)
/product         /dev/ov (Virtual disk: /data/local/tmp/image001)
/odm             /dev/ov (Virtual disk: /data/local/tmp/image001)
/system          /dev/ov (Virtual disk: /data/local/tmp/image001)
/vendor/app      /dev/ov (Virtual disk: /data/local/tmp/image001)
/vendor/bin      /dev/ov (Virtual disk: /data/local/tmp/image001)

ASUS_I006D:/data/local/tmp #


or, if multiple virtual disks are used:


ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list --details 
Directories mounted on an overlay filesystem

Directory         Backend Directory
---------         -----------------
/vendor           /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/vendor_dlkm      /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/odm              /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/odm_dlkm         /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/system_ext       /dev/ov (Virtual disk: /data/local/tmp/image001)

ASUS_I006D:/data/local/tmp $

----

To get the directories used for new files for the current active overlay mounts use the action get with the option --active:

/data/local/tmp/create_overlay_mount.sh get --active
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh get --active
/dev/ov/upper/system_ext # /system_ext
/dev/ov/upper/product # /product
/dev/ov/upper/odm # /odm
/dev/ov/upper/system # /system
/dev/ov/upper/vendor#app # /vendor/app
/dev/ov/upper/vendor#bin # /vendor/bin

ASUS_I006D:/data/local/tmp #


# or only for specific directories:

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh get --active /system
/dev/ov/upper/system # /system

ASUS_I006D:/data/local/tmp #


----



The action list_disk


To list the directories available on a virtual disk configured for overlay mounts the action list_disk can be used:

/data/local/tmp/create_overlay_mount.sh list_disk

ASUS_I006D:/data/local/tmp $ /data/local/tmp/create_overlay_mount.sh list_disk
Overlay directories in "/dev/ov" (mounted on the virtual disk "/data/local/tmp/image001"):

/data/local/tmp/sysroot
/odm
/odm/etc
/odm_dlkm
/product
/product/etc
/product/usr
/system
/system/etc
/system_ext
/system_ext/etc
/system_ext/framework
/vendor
/vendor/bin
/vendor/etc

ASUS_I006D:/data/local/tmp $

---

To list also some details for the directories, add the parameter --details:

/data/local/tmp/create_overlay_mount.sh list_disk --details
ASUS_I006D:/data/local/tmp $ /data/local/tmp/create_overlay_mount.sh list_disk --details
Overlay directories in "/dev/ov" (mounted on the virtual disk "/data/local/tmp/image001"):

Target Directory           No. of modified files       No. of deleted files       Directory currently mounted?    Overlay Directory
----------------           ---------------------       --------------------       ----------------------------    -----------------
/data/local/tmp/sysroot    1285                        2                          yes                             /dev/ov/upper/data#local#tmp#sysroot
/odm                       0                           0                          yes                             /dev/ov/upper/odm
/odm/etc                   0                           0                          no                              /dev/ov/upper/odm#etc
/odm_dlkm                  2                           1                          yes                             /dev/ov/upper/odm_dlkm
/product                   0                           0                          yes                             /dev/ov/upper/product
/product/etc               0                           0                          no                              /dev/ov/upper/product#etc
/product/usr               0                           0                          no                              /dev/ov/upper/product#usr
/system                    0                           0                          yes                             /dev/ov/upper/system
/system/etc                0                           0                          no                              /dev/ov/upper/system#etc
/system_ext                1                           0                          yes                             /dev/ov/upper/system_ext
/system_ext/etc            0                           0                          no                              /dev/ov/upper/system_ext#etc
/system_ext/framework      0                           0                          no                              /dev/ov/upper/system_ext#framework
/vendor                    10                          0                          no                              /dev/ov/upper/vendor
/vendor/bin                0                           0                          yes                             /dev/ov/upper/vendor#bin
/vendor/etc                5                           1                          yes                             /dev/ov/upper/vendor#etc

ASUS_I006D:/data/local/tmp $

Note that /data/local/tmp/sysroot is mounted to a virtual disk in this example.

----


The action delete


The action delete deletes the directories used for the overlay filesystem for a directory on the virtual disk mounted on BASEDIR.

The scripts asks for confirmation by the user before deleting the data; use the parameter "--yes" to disable this question.




The action test


To test the write access in the directories with overlay mounts use the action test:

/data/local/tmp/create_overlay_mount.sh test
ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh test
Testing the write access for directories mounted on overlay filesystems ...


Testing write access for the directory "/system_ext" ...
  OK, the write access to the directory "/system_ext" works

Testing write access for the directory "/product" ...
  OK, the write access to the directory "/product" works

Testing write access for the directory "/odm" ...
  OK, the write access to the directory "/odm" works

Testing write access for the directory "/system" ...
  OK, the write access to the directory "/system" works

Testing write access for the directory "/odm_dlkm" ...
  OK, the write access to the directory "/odm_dlkm" works

ASUS_I006D:/ #

----



The action get


To list the backend used for a file or directory use the action get

The format of the output of the action get is

backend_file # original_file # comment

e.g.

/data/local/tmp/ov/upper/system_ext/etc/passwd # /system_ext/etc/passwd # the file was changed


Entries for deleted files may be files, directories, or anything else. As long as the overlay mount and the bind mount is in place, this info is not available (see below for a workaround for this problem).



Example output of the script with the parameter get:

/data/local/tmp/create_overlay_mount.sh  get  /system_ext/priv-app/OmniControl/testdir

----
commands to create the test environment
# instructions to create the test env
#
cd /system_ext/
mkdir -p ./priv-app/OmniControl/testdir/testdir2
touch ./priv-app/OmniControl/testdir/testdir2/testfile3
touch  ./priv-app/OmniControl/testdir/testfile2
touch ./priv-app/OmniControl/testfile1
rm ./priv-app/OmniControl/oat/arm64/OmniControl.odex
rm ./priv-app/OmniControl/oat/arm64/OmniControl.vdex
----

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh diff /system_ext
List the changes in the directories ...

 ----------------------------------------------------------------------
List the changes in the directory "/system_ext" ...
There is currently an overlay mounted for the directory "/system_ext"
File changes in the directory "/system_ext" :

./priv-app
./priv-app/OmniControl
./priv-app/OmniControl/oat
./priv-app/OmniControl/oat/arm64
./priv-app/OmniControl/testdir
./priv-app/OmniControl/testdir/testdir2
./priv-app/OmniControl/testdir/testdir2/testfile3
./priv-app/OmniControl/testdir/testfile2
./priv-app/OmniControl/testfile1

Files or directories deleted in the directory "/system_ext" :

./priv-app/OmniControl/oat/arm64/OmniControl.odex
./priv-app/OmniControl/oat/arm64/OmniControl.vdex


ASUS_I006D:/system_ext #                                                                                    

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testdir
/dev/ov/upper/system_ext/priv-app/OmniControl/testdir # /system_ext/priv-app/OmniControl/testdir

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testdir/testdir2      
/dev/ov/upper/system_ext/priv-app/OmniControl/testdir/testdir2 # /system_ext/priv-app/OmniControl/testdir/testdir2

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testdir/testdir2/testfile3
/dev/ov/upper/system_ext/priv-app/OmniControl/testdir/testdir2/testfile3 # /system_ext/priv-app/OmniControl/testdir/testdir2/testfile3 # the file was changed

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testdir/testfile2
/dev/ov/upper/system_ext/priv-app/OmniControl/testdir/testfile2 # /system_ext/priv-app/OmniControl/testdir/testfile2 # the file was changed

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testfile1
/dev/ov/upper/system_ext/priv-app/OmniControl/testfile1 # /system_ext/priv-app/OmniControl/testfile1 # the file was changed

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/testfile5
/dev/ov/upper/system_ext/priv-app/OmniControl/testfile5 # /system_ext/priv-app/OmniControl/testfile5 # the file was not yet changed or deleted

ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/oat/arm64/OmniControl.odex
/dev/ov/upper/system_ext/priv-app/OmniControl/oat/arm64/OmniControl.odex # /system_ext/priv-app/OmniControl/oat/arm64/OmniControl.odex # the file/directory was deleted


ASUS_I006D:/system_ext #

ASUS_I006D:/system_ext # /data/local/tmp/create_overlay_mount.sh get /system_ext/priv-app/OmniControl/oat/arm64/OmniControl.vdex
/dev/ov/upper/system_ext/priv-app/OmniControl/oat/arm64/OmniControl.vdex # /system_ext/priv-app/OmniControl/oat/arm64/OmniControl.vdex # the file/directory was deleted

ASUS_I006D:/system_ext #


----


The options --short and --details can be used to change the information printed by the action get:


Other example for the action get
----
commands to create the test environments
# instructions to create the test env
#
/data/local/tmp/create_overlay_mount.sh umount /odm
/data/local/tmp/create_overlay_mount.sh /odm/etc /vendor

touch /odm/etc/passwd
touch /odm/etc/selinux/precompiled_sepolicy
rm /odm/etc/group
touch /vendor/etc/vmmgr.conf

----

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh list
Directories mounted on an overlay filesystem

/vendor
/odm/etc


ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  diff /odm/etc /vendor
List the changes in the directories ...

 ----------------------------------------------------------------------
List the changes in the directory "/odm/etc" ...
There is currently an overlay mounted for the directory "/odm/etc"
File changes in the directory "/odm/etc" :

./passwd
./selinux
./selinux/precompiled_sepolicy

Files or directories deleted in the directory "/odm/etc" :

./group


 ----------------------------------------------------------------------
List the changes in the directory "/vendor" ...
There is currently an overlay mounted for the directory "/vendor"
File changes in the directory "/vendor" :

./etc
./etc/vmmgr.conf

Files or directories deleted in the directory "/vendor" :



ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor /vendor/etc /vendor/etc/vmmgr.conf  /odm /odm/etc /odm/etc/passwd  /odm/etc/group  /vendor/etc/ueventd.rc /odm/etc/build.prop
/dev/ov/upper/vendor # /vendor
/dev/ov/upper/vendor/etc # /vendor/etc
/dev/ov/upper/vendor/etc/vmmgr.conf # /vendor/etc/vmmgr.conf # the file was changed
# There is no overlay mount active for "/odm" in the backend "/dev/ov"
/dev/ov/upper/odm#etc # /odm/etc
/dev/ov/upper/odm#etc/passwd # /odm/etc/passwd # the file was changed
/dev/ov/upper/odm#etc/group # /odm/etc/group # the file/directory was deleted
/dev/ov/upper/vendor/etc/ueventd.rc # /vendor/etc/ueventd.rc # the file was not yet changed or deleted
/dev/ov/upper/odm#etc/build.prop # /odm/etc/build.prop # the file was not yet changed or deleted

ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor /vendor/etc /vendor/etc/vmmgr.conf  /odm /odm/etc /odm/etc/passwd  /odm/etc/group  /vendor/etc/ueventd.rc /odm/etc/build.prop    --short
/dev/ov/upper/vendor
/dev/ov/upper/vendor/etc
/dev/ov/upper/vendor/etc/vmmgr.conf
# There is no overlay mount active for "/odm" in the backend "/dev/ov"
/dev/ov/upper/odm#etc
/dev/ov/upper/odm#etc/passwd
/dev/ov/upper/odm#etc/group
/dev/ov/upper/vendor/etc/ueventd.rc
/dev/ov/upper/odm#etc/build.prop

ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor /vendor/etc /vendor/etc/vmmgr.conf  /odm /odm/etc /odm/etc/passwd  /odm/etc/group  /vendor/etc/ueventd.rc /odm/etc/build.prop    --details
drwxr-xr-x 3 root shell u:object_r:vendor_file:s0  1024 2025-06-25 10:53 /dev/ov/upper/vendor # /vendor
drwxr-xr-x 2 root shell u:object_r:vendor_configs_file:s0  1024 2009-01-01 01:00 /dev/ov/upper/vendor/etc # /vendor/etc
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  25 2025-06-25 10:55 /dev/ov/upper/vendor/etc/vmmgr.conf # /vendor/etc/vmmgr.conf # the file was changed
# There is no overlay mount active for "/odm" in the backend "/dev/ov"
drwxr-xr-x 3 root root u:object_r:vendor_configs_file:s0  1024 2025-06-25 10:55 /dev/ov/upper/odm#etc # /odm/etc
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  0 2025-06-25 10:55 /dev/ov/upper/odm#etc/passwd # /odm/etc/passwd # the file was changed
c--------- 1 root root u:object_r:vendor_configs_file:s0  0,   0 2025-06-25 10:55 /dev/ov/upper/odm#etc/group # /odm/etc/group # the file/directory was deleted
/dev/ov/upper/vendor/etc/ueventd.rc # /vendor/etc/ueventd.rc # the file was not yet changed or deleted
/dev/ov/upper/odm#etc/build.prop # /odm/etc/build.prop # the file was not yet changed or deleted

ASUS_I006D:/data/local/tmp #

127|ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor /vendor/etc /vendor/etc/vmmgr.conf  /odm /odm/etc /odm/etc/passwd  /odm/etc/group  /vendor/etc/ueventd.rc /odm/etc/build.prop    --details --short
drwxr-xr-x 3 root shell u:object_r:vendor_file:s0  1024 2025-06-25 10:53 /dev/ov/upper/vendor
drwxr-xr-x 2 root shell u:object_r:vendor_configs_file:s0  1024 2009-01-01 01:00 /dev/ov/upper/vendor/etc
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  25 2025-06-25 10:55 /dev/ov/upper/vendor/etc/vmmgr.conf
# There is no overlay mount active for "/odm" in the backend "/dev/ov"
drwxr-xr-x 3 root root u:object_r:vendor_configs_file:s0  1024 2025-06-25 10:55 /dev/ov/upper/odm#etc
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  0 2025-06-25 10:55 /dev/ov/upper/odm#etc/passwd
c--------- 1 root root u:object_r:vendor_configs_file:s0  0,   0 2025-06-25 10:55 /dev/ov/upper/odm#etc/group
/dev/ov/upper/vendor/etc/ueventd.rc
/dev/ov/upper/odm#etc/build.prop

ASUS_I006D:/data/local/tmp #

----



The action mount_only


To check the contents of the virtual disk used as backend without creating the overlay mounts use the action mount_only.

When using the action mount_only the script only mounts the virtual disk to the directory found in the environment variable BASEDIR.

Example:

/data/local/tmp/create_overlay_mount.sh mount_only
# create some test files

ASUS_I006D:/data/local/tmp # for i in /system /system_ext  /product /odm/  ; do touch $i/test.$$ ; ls -l $i/test.$$ ; done
-rw-r--r-- 1 root root 0 2025-06-25 11:01 /system/test.2343
-rw-r--r-- 1 root root 0 2025-06-25 11:01 /system_ext/test.2343
-rw-r--r-- 1 root root 0 2025-06-25 11:01 /product/test.2343
-rw-r--r-- 1 root root 0 2025-06-25 11:01 /odm//test.2343
1|ASUS_I006D:/data/local/tmp #


# and reboot the phone

ASUS_I006D:/ # reboot
...

# execute in an adb shell after the reboot

1|ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh mount_only
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem

The virtual disk is mounted to "/dev/ov"

ASUS_I006D:/data/local/tmp #

1|ASUS_I006D:/data/local/tmp # ls -l /dev/ov/upper/*/*
-rw-r--r-- 1 root root       0 2025-06-25 11:01 /dev/ov/upper/odm/test.2343
-rw-r--r-- 1 root root       0 2025-06-25 11:01 /dev/ov/upper/product/test.2343
-rw-r--r-- 1 root root       0 2025-06-25 11:01 /dev/ov/upper/system/test.2343
-rw-r--r-- 1 root root       0 2025-06-25 11:01 /dev/ov/upper/system_ext/test.2343

ASUS_I006D:/data/local/tmp #

----

This functionality can be done to clean or modify the contents of a virtual disk manually.



The action diff


To list the file changes for a directory with an overlay mount use the action diff

For example, to list all changes for the directories /odm_dlkm :

/data/local/tmp/create_overlay_mount.sh diff /odm_dlkm

----
commands to create the test environment
# instructions to create the test env
#
 mkdir /odm_dlkm/testdir
 touch /odm_dlkm/testdir/testfile1
 touch /odm_dlkm/testdir/testfile2
 touch /odm_dlkm/testfile0
 rm  /odm_dlkm/etc
----

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh  diff /odm_dlkm
List the modifications in the directories ...

 ----------------------------------------------------------------------
List the modifications in the directory "/odm_dlkm" ...
There is currently an overlay mounted for the directory "/odm_dlkm"

There are 3 modified files in the directory tree "/odm_dlkm"
File modifications in the directory "/odm_dlkm" :

./testdir/testfile1
./testdir/testfile2
./testfile0

There is 1 deleted file in the directory tree "/odm_dlkm"
Files or directories deleted in the directory "/odm_dlkm" :

./etc


ASUS_I006D:/ $

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh  diff /odm_dlkm --details
List the modifications in the directories ...

 ----------------------------------------------------------------------
List the modifications in the directory "/odm_dlkm" ...
There is currently an overlay mounted for the directory "/odm_dlkm"

There are 3 modified files in the directory tree "/odm_dlkm"
File modifications in the directory "/odm_dlkm" :

-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2026-11-02 17:56 ./testdir/testfile1
-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2026-11-02 17:56 ./testdir/testfile2
-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2026-11-02 17:56 ./testfile0

There is 1 deleted file in the directory tree "/odm_dlkm"
Files or directories deleted in the directory "/odm_dlkm" :

./etc


ASUS_I006D:/ $


----

The default directory list for the action diff is the list of directories in the variable DIRS_TO_OVERLAY.  Use the option --active to list only the changes in all mounted overlay filesystems


/data/local/tmp/create_overlay_mount.sh diff --active
ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh list
Directories mounted on an overlay filesystem

/vendor
/odm_dlkm


ASUS_I006D:/ $

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff --active 
List the modifications in the directories ...

 ----------------------------------------------------------------------
List the modifications in the directory "/vendor" ...
There is currently an overlay mounted for the directory "/vendor"

There are 10 modified files in the directory tree "/vendor"
File modifications in the directory "/vendor" :

./etc/apdr.conf
./etc/flp.conf
./etc/gnss_antenna_info.conf
./etc/gps.conf
./etc/izat.conf
./etc/libese-nxp.conf
./etc/libnfc-nci.conf
./etc/libnfc-nxp.conf
./etc/libnfc-nxp_RF.conf
./etc/lowi.conf

There are 0 deleted files in the directory tree "/vendor"


 ----------------------------------------------------------------------
List the modifications in the directory "/odm_dlkm" ...
There is currently an overlay mounted for the directory "/odm_dlkm"

There are 2 modified files in the directory tree "/odm_dlkm"
File modifications in the directory "/odm_dlkm" :

./testdir/testfile1
./testdir/testfile2

There is 1 deleted file in the directory tree "/odm_dlkm"
Files or directories deleted in the directory "/odm_dlkm" :

./etc


ASUS_I006D:/ $

----


The action diff_file


To compare a file in a directory with an overlay mount with the original file using the executable diff the action diff_file can be used.

Example:

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff_file  /vendor/etc/libnfc-nxp_RF.conf                                                                                                                                        
Searching modified files ...
Found 1 modified file(s) matching the script parameter.
..

Now executing "/system/bin/diff" for 1 file(s) ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp_RF.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/libnfc-nxp_RF.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libnfc-nxp_RF.conf    2026-11-01 16:05:03.000000000 +0100
@@ -1,4 +1,7 @@
 ###############################################################################
+#
+# Test Comment
+#
 # NXP RF configuration ALM/PLM settings
 # This section needs to be updated with the correct values based on the platform
 NXP_RF_CONF_BLK_1={

1|ASUS_I006D:/ $
1|ASUS_I006D:/ $


To write the output of the diff command to a file add the option --patch:

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff_file  /vendor/etc/libnfc-nxp_RF.conf --patch
Searching modified files ...
Found 1 modified file(s) matching the script parameter.
..

Now executing "/system/bin/diff" for 1 file(s) ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp_RF.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_libnfc-nxp_RF.conf.patch" ...

1|ASUS_I006D:/ $


1|ASUS_I006D:/ $ cat /data/local/tmp/patches/_vendor_etc_libnfc-nxp_RF.conf.patch
--- /dev/ov/rootfs//vendor/etc/libnfc-nxp_RF.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libnfc-nxp_RF.conf    2026-11-01 16:05:03.000000000 +0100
@@ -1,4 +1,7 @@
 ###############################################################################
+#
+# Test Comment
+#
 # NXP RF configuration ALM/PLM settings
 # This section needs to be updated with the correct values based on the platform
 NXP_RF_CONF_BLK_1={
ASUS_I006D:/ $


The directory for the patch files is defined in the environment variable PATCH_DIR; the default value for this variable is /data/local/tmp/patches. Existing patch files will be renamed and not overwritten.

The name of the patch files is

<original_filename><patch_file_extension>

The variable EXTENSION_FOR_PATCH_FILES defines the extension for the patch files; the default value for that variable is ".patch".



The action diff_file can also be used to execute diff for all files in a directory.


Example:

/data/local/tmp/create_overlay_mount.sh diff_file /vendor/etc
ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff_file /vendor/etc
Searching modified files ...
Found 10 modified file(s) matching the script parameter.
....................

Now executing "/system/bin/diff" for 10 file(s) ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libese-nxp.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/libese-nxp.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libese-nxp.conf    2026-11-01 16:04:44.000000000 +0100
@@ -1,4 +1,7 @@
 ##This file needs to be pushed into /vendor/etc/libese-nxp.conf
+#
+# Test Commment
+#
 
 ###############################################################################
 # Application options

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp_RF.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/libnfc-nxp_RF.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libnfc-nxp_RF.conf    2026-11-01 16:05:03.000000000 +0100
@@ -1,4 +1,7 @@
 ###############################################################################
+#
+# Test Comment
+#
 # NXP RF configuration ALM/PLM settings
 # This section needs to be updated with the correct values based on the platform
 NXP_RF_CONF_BLK_1={

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/izat.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/izat.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/izat.conf    2026-11-01 16:04:38.000000000 +0100
@@ -1,4 +1,7 @@
 #########################################
+#
+# Test Comment
+#
 # Log verbosity control for izat modules
 #########################################
 # OFF = 0, ERROR = 1, WARNING = 2, INFO = 3, DEBUG = 4, VERBOSE = 5

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/libnfc-nxp.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libnfc-nxp.conf    2026-11-01 16:04:58.000000000 +0100
@@ -1,4 +1,7 @@
 ## This file is used by NFC NXP NCI HAL(external/libnfc-nci/halimpl/pn547)
+#
+# Test Commment
+#
 ## and NFC Service Java Native Interface Extensions (packages/apps/Nfc/nci/jni/extns/pn547)
 ###############################################################################
 ## Project: SAKE AR - NQ410

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/gnss_antenna_info.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/gnss_antenna_info.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/gnss_antenna_info.conf    2026-11-01 16:04:25.000000000 +0100
@@ -1,4 +1,8 @@
 ###################################
+#
+# Test Comment
+#
+#
 #####   ANTENNA INFORMATION   #####
 ###################################
 

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/apdr.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/apdr.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/apdr.conf    2026-11-01 16:04:12.000000000 +0100
@@ -1,5 +1,7 @@
 # AP DR SENSOR Configuration file
 #
+#  Test Comment
+#
 # SENSOR_SERVICE options are one of below
 #   accel,gyro,vehicle_accel,vehicle_gyro,pedometer,vehicle_odometry,accel_temp,
 #   gyro_temp,baro,mag_calib,mag_uncalib,amd,rmd.

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/lowi.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/lowi.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/lowi.conf    2026-11-01 16:05:10.000000000 +0100
@@ -1,5 +1,7 @@
 #*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*
 #
+#  Test TEst
+#
 # LOWI Config file - lahaina
 #
 # GENERAL DESCRIPTION

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/flp.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/flp.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/flp.conf    2026-11-01 16:04:18.000000000 +0100
@@ -1,4 +1,8 @@
 ###################################
+#
+# TEst Comment
+#
+#
 #####       FLP settings      #####
 ###################################
 

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/gps.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/gps.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/gps.conf    2026-11-01 16:04:31.000000000 +0100
@@ -1,4 +1,6 @@
 # Error Estimate
+# Test Comment
+#
 # _SET = 1
 # _CLEAR = 0
 ERR_ESTIMATE=0

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nci.conf" ... RC=1
--- /dev/ov/rootfs//vendor/etc/libnfc-nci.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/libnfc-nci.conf    2026-11-01 16:04:51.000000000 +0100
@@ -1,4 +1,7 @@
 ###################### Start of libnfc-brcm.conf #######################
+#
+# Test Comment
+#
 ## Project: SAKE AR
 ###############################################################################
 # Application options

 ----------------------------------------------------------------------
*** Summary:

10 file(s) checked

10 modified file(s) found:

/vendor/etc/libese-nxp.conf
/vendor/etc/libnfc-nxp_RF.conf
/vendor/etc/izat.conf
/vendor/etc/libnfc-nxp.conf
/vendor/etc/gnss_antenna_info.conf
/vendor/etc/apdr.conf
/vendor/etc/lowi.conf
/vendor/etc/flp.conf
/vendor/etc/gps.conf
/vendor/etc/libnfc-nci.conf


1|ASUS_I006D:/ $

----

The parameter --patch can also be used to create patch files for all modified files in a directory. In this case, the script creates separate patch files for each file.

/data/local/tmp/create_overlay_mount.sh diff_file  /vendor/etc --patch
ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff_file  /vendor/etc --patch
Searching modified files ...
Found 10 modified file(s) matching the script parameter.
....................

Now executing "/system/bin/diff" for 9 file(s) ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libese-nxp.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_libese-nxp.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp_RF.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_libnfc-nxp_RF.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/izat.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_izat.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nxp.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_libnfc-nxp.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/gnss_antenna_info.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_gnss_antenna_info.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/apdr.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_apdr.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/lowi.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_lowi.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/flp.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_flp.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/gps.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_gps.conf.patch" ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/libnfc-nci.conf" ... RC=1
Creating the patch file "/data/local/tmp/patches/_vendor_etc_libnfc-nci.conf.patch" ...

 ----------------------------------------------------------------------
*** Summary:

10 file(s) checked

10 modified file(s) found:

/vendor/etc/libese-nxp.conf
/vendor/etc/libnfc-nxp_RF.conf
/vendor/etc/izat.conf
/vendor/etc/libnfc-nxp.conf
/vendor/etc/gnss_antenna_info.conf
/vendor/etc/apdr.conf
/vendor/etc/lowi.conf
/vendor/etc/flp.conf
/vendor/etc/gps.conf
/vendor/etc/libnfc-nci.conf


1|ASUS_I006D:/ $


----


To execute diff for all modified files in a directory and in all sub directories of that directory, add two trailing slashes "//" to the directory name, e.g.:

/data/local/tmp/create_overlay_mount.sh diff_file  /vendor// --patch

Example:

ASUS_I006D:/data/local/tmp # ./create_overlay_mount.sh  diff_file /vendor//  BASEDIR=/data/local/tmp/virtualfs001
Searching modified files ...
Found 5 file(s) matching the script parameter.
.
"/vendor/bin/xx" is a new file or the original filesystem for that file is not mounted -- can not diff that file
....
The file "/vendor/etc/NOTICE.xml.gz" has been deleted


Now executing "/system/bin/diff" for 3 file(s) ...

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/izat.conf" ... RC=0


*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/lowi.conf" ... RC=1
--- /data/local/tmp/virtualfs001/rootfs//vendor/etc/lowi.conf    2009-01-01 01:00:00.000000000 +0100
+++ ./vendor/etc/lowi.conf    2026-11-04 07:03:00.000000000 +0100
@@ -1,5 +1,7 @@
 #*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*
 #
+# Test Comment
+#
 # LOWI Config file - lahaina
 #
 # GENERAL DESCRIPTION

*** Executing "/system/bin/diff" " -u " for the file "/vendor/etc/wifi/vendor_cmd.xml" ... RC=0


 ----------------------------------------------------------------------
*** Summary:

5 file(s) checked

1 new file(s) found:

/vendor/bin/xx

2 file(s) with modified meta information (such as date, permissions, etc) found:

/vendor/etc/izat.conf
/vendor/etc/wifi/vendor_cmd.xml

1 deleted file(s) found:

/vendor/etc/NOTICE.xml.gz

1 modified file(s) found:

/vendor/etc/lowi.conf


ASUS_I006D:/data/local/tmp #



Files without modifications are ignored by the script when the action parameter diff_file is used.

Example:

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh diff_file /vendor/etc/powerhint.json
Searching modified files ...
Found 1 modified file(s) matching the script parameter.
..
The file "/vendor/etc/powerhint.json" has not been modified


ASUS_I006D:/ $


The action diff_files can also be used to execute other actions for the modified files. The script uses the executable defined in the environment variable DIFF and the options defined in the environment variable DIFF_OPTIONS when the action parameter diff_files is used. Therefore, simply change the value of these variables to execute other actions for the list of modified files.

The command executed by the script is

${DIFF} ${DIFF_OPTIONS} [original_file] [modified_file]


Example:

27|ASUS_I006D:/data/local/tmp # DIFF="ls -ld"  ./create_overlay_mount.sh  diff_file /vendor//  BASEDIR=/data/local/tmp/virtualfs001
Searching modified files ...
Found 5 file(s) matching the script parameter.
.
"/vendor/bin/xx" is a new file or the original filesystem for that file is not mounted -- can not diff that file
....
The file "/vendor/etc/NOTICE.xml.gz" has been deleted


Now executing "ls -ld" for 3 file(s) ...

*** Executing "ls -ld" " -u " for the file "/vendor/etc/izat.conf" ... RC=0
-rw-r--r-- 1 root root 7938 2026-11-04 07:06 ./vendor/etc/izat.conf
-rw-r--r-- 1 root root 7938 2009-01-01 01:00 /data/local/tmp/virtualfs001/rootfs//vendor/etc/izat.conf

*** Executing "ls -ld" " -u " for the file "/vendor/etc/lowi.conf" ... RC=0
-rw-r--r-- 1 root root 977 2026-11-04 07:04 ./vendor/etc/lowi.conf
-rw-r--r-- 1 root root 960 2009-01-01 01:00 /data/local/tmp/virtualfs001/rootfs//vendor/etc/lowi.conf

*** Executing "ls -ld" " -u " for the file "/vendor/etc/wifi/vendor_cmd.xml" ... RC=0
-rw-rw-rw- 1 root root 53085 2026-11-04 07:19 ./vendor/etc/wifi/vendor_cmd.xml
-rw-r--r-- 1 root root 53085 2009-01-01 01:00 /data/local/tmp/virtualfs001/rootfs//vendor/etc/wifi/vendor_cmd.xml

 ----------------------------------------------------------------------
*** Summary:

5 file(s) checked

1 new file(s) found:

/vendor/bin/xx

The command "ls -ld" ended with RC=0 for 3 file(s)

/vendor/etc/izat.conf
/vendor/etc/lowi.conf
/vendor/etc/wifi/vendor_cmd.xml

1 deleted file(s) found:

/vendor/etc/NOTICE.xml.gz


ASUS_I006D:/data/local/tmp #


To get an overview of the number of modified files in the various overlay filesystems, the action list_disk with the option parameter --details can be used.

 

The action undo


To undo all changes in a directory with an overlay mount use the action undo, e.g. to undo all modifications in the directory /system execute:

/data/local/tmp/create_overlay_mount.sh undo /system
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  undo /system
Undoing the change in the directories ...
Undoing the changes for the directory "/system" ...

ASUS_I006D:/data/local/tmp #

----


To undo the modifications for all files in the directories listed in in the variable DIRS_TO_OVERLAY run::

/data/local/tmp/create_overlay_mount.sh undo
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  undo
Undoing the modifications in the directories

/system_ext
/product
/odm
/system

Please confirm that all modifications in the overlay filesystems for the directories listed above should be deleted (use the parameter "--yes" to suppress this question) (y/N)?  y

Undoing the change in the directories ...

Undoing the changes for the directory "/system_ext" ...
Undoing the changes for the directory "/product" ...
Undoing the changes for the directory "/odm" ...
Undoing the changes for the directory "/system" ...

ASUS_I006D:/data/local/tmp #

----

To undo the modifications for all files in the currently mounted overlay directories add the option --active:


/data/local/tmp/create_overlay_mount.sh undo --active


If the action undo is used without a directory parameter, the script asks the user for confirmation. Use the parameter --yes or --no to suppress this question.


Please be aware that there is no redo action.



The action restore


To undo the modifications only for specific files use the parameter restore:

/data/local/tmp/create_overlay_mount.sh restore /system/etc/hosts
ASUS_I006D:/data/local/tmp # cat /system/etc/hosts
127.0.0.1       localhost
::1             ip6-localhost
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # echo "1.1.1.1 dnsserver" >>/system/etc/hosts
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # cat /system/etc/hosts                                                                                                                                                 
127.0.0.1       localhost
::1             ip6-localhost
1.1.1.1 dnsserver
ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh restore /system/etc/hosts
Deleting the files "/data/local/tmp/ov/upper/system/etc/hosts" and "/data/local/tmp/ov/merged/system/etc/hosts" ...
Restoring the file "/system/etc/hosts" ...

ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # cat /system/etc/hosts
127.0.0.1       localhost
::1             ip6-localhost
ASUS_I006D:/data/local/tmp #



----


To restore a deleted file on a directory mounted on an overlay filesystem use the parameter restore :

/data/local/tmp/create_overlay_mount.sh restore /odm/etc/build.prop
ASUS_I006D:/data/local/tmp # ls -l /odm/etc/build.prop
-rw------- 1 root root 999 2009-01-01 01:00 /odm/etc/build.prop
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # rm /odm/etc/build.prop
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -l /odm/etc/build.prop
ls: /odm/etc/build.prop: No such file or directory
1|ASUS_I006D:/data/local/tmp #

1|ASUS_I006D:/data/local/tmp # /data/local/tmp//create_overlay_mount.sh restore /odm/etc/build.prop
Restoring the file "/odm/etc/build.prop" ...

ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -l /odm/etc/build.prop
-rw------- 1 root root 999 2009-01-01 01:00 /odm/etc/build.prop
ASUS_I006D:/data/local/tmp #



----

Note:

The action restore for a new file (= a file that does not exist in the original directory) deletes that file.


Other examples for the action restore
commands to create the test environment
/data/local/tmp/create_overlay_mount.sh mount /system/app/EasterEgg

----


ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh diff /system/app/EasterEgg
List the changes in the directories ...

 ----------------------------------------------------------------------
List the changes in the directory "/system/app/EasterEgg" ...
There is currently an overlay mounted for the directory "/system/app/EasterEgg"
File changes in the directory "/system/app/EasterEgg" :


Files or directories deleted in the directory "/system/app/EasterEgg" :



ASUS_I006D:/ #


ASUS_I006D:/ # ls -ld $( find /system/app/EasterEgg )
drwxr-xr-x 1 root root    1024 2025-06-22 13:35 /system/app/EasterEgg
-rw-r--r-- 1 root root 2139850 2009-01-01 01:00 /system/app/EasterEgg/EasterEgg.apk
drwxr-xr-x 3 root root    4096 2009-01-01 01:00 /system/app/EasterEgg/oat
drwxr-xr-x 2 root root    4096 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64
-rw-r--r-- 1 root root   41904 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64/EasterEgg.odex
-rw-r--r-- 1 root root   56904 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64/EasterEgg.vdex
ASUS_I006D:/ #


# delete some files


ASUS_I006D:/ # rm /system/app/EasterEgg/EasterEgg.apk
ASUS_I006D:/ # rm /system/app/EasterEgg/oat/arm64/EasterEgg.odex
ASUS_I006D:/ # rm /system/app/EasterEgg/oat/arm64/EasterEgg.vdex                                                                                                   
ASUS_I006D:/ #

ASUS_I006D:/ # ls -ld $( find /system/app/EasterEgg )                                                                                                                
drwxr-xr-x 1 root root 1024 2025-06-22 13:41 /system/app/EasterEgg
drwxr-xr-x 1 root root 1024 2009-01-01 01:00 /system/app/EasterEgg/oat
drwxr-xr-x 1 root root 1024 2025-06-22 13:41 /system/app/EasterEgg/oat/arm64
ASUS_I006D:/ #


# restore a file

ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh restore /system/app/EasterEgg/EasterEgg.apk
Restoring the file "/system/app/EasterEgg/EasterEgg.apk" ...

ASUS_I006D:/ #

ASUS_I006D:/ # ls -ld $( find /system/app/EasterEgg )                                                                                                                
drwxr-xr-x 1 root root    1024 2025-06-22 13:42 /system/app/EasterEgg
-rw-r--r-- 1 root root 2139850 2009-01-01 01:00 /system/app/EasterEgg/EasterEgg.apk
drwxr-xr-x 1 root root    1024 2009-01-01 01:00 /system/app/EasterEgg/oat
drwxr-xr-x 1 root root    1024 2025-06-22 13:41 /system/app/EasterEgg/oat/arm64
ASUS_I006D:/ #


# restore all  files in a directory

ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh restore /system/app/EasterEgg/oat
Restoring the directory "/system/app/EasterEgg/oat" ...

ASUS_I006D:/ #

ASUS_I006D:/ # ls -ld $( find /system/app/EasterEgg )                                                                                                                
drwxr-xr-x 1 root root    1024 2025-06-22 13:43 /system/app/EasterEgg
-rw-r--r-- 1 root root 2139850 2009-01-01 01:00 /system/app/EasterEgg/EasterEgg.apk
drwxr-xr-x 3 root root    4096 2009-01-01 01:00 /system/app/EasterEgg/oat
drwxr-xr-x 2 root root    4096 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64
-rw-r--r-- 1 root root   41904 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64/EasterEgg.odex
-rw-r--r-- 1 root root   56904 2009-01-01 01:00 /system/app/EasterEgg/oat/arm64/EasterEgg.vdex
ASUS_I006D:/ #


ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh diff /system/app/EasterEgg
List the changes in the directories ...

 ----------------------------------------------------------------------
List the changes in the directory "/system/app/EasterEgg" ...
There is currently an overlay mounted for the directory "/system/app/EasterEgg"
File changes in the directory "/system/app/EasterEgg" :


Files or directories deleted in the directory "/system/app/EasterEgg" :



ASUS_I006D:/ #

# change a file

ASUS_I006D:/ # echo >/system/app/EasterEgg/EasterEgg.apk
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l /system/app/EasterEgg/EasterEgg.apk
-rw-r--r-- 1 root root 1 2025-06-22 13:49 /system/app/EasterEgg/EasterEgg.apk
ASUS_I006D:/ #


ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh restore /system/app/EasterEgg/
"/system/app/EasterEgg" is a directory with an overlay mount -- use the parameter "undo /system/app/EasterEgg" to undo all changes for this directory

ASUS_I006D:/ #

ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh restore /system/app/EasterEgg/EasterEgg.apk
Restoring the file "/system/app/EasterEgg/EasterEgg.apk" ...

ASUS_I006D:/ # ls -l /system/app/EasterEgg/EasterEgg.apk
-rw-r--r-- 1 root root 2139850 2009-01-01 01:00 /system/app/EasterEgg/EasterEgg.apk
ASUS_I006D:/ #

----


The action remount


In case of an error in a directory with an overlay you may remount the directory using the action remount:

 /data/local/tmp/create_overlay_mount.sh remount /system_ext

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh remount /system_ext
Remounting the overlay mounts ...
Remounting "/system_ext" ...
 ... done

ASUS_I006D:/data/local/tmp #


----



The action clean


The action clean umounts all overlay mounts, all mounts for virtual disks used for overlay mounts, and all temporary mounts for the devices with the original filesystems.



Environment variables used by the script



The script uses these environment variables:


Variable
Usage
Default value
Comment
IMAGE_FILE file used for the virtual disk
/data/local/tmp/image001
The value of this variable is ignored if the ${BASEDIR} is already mounted to a virtual disk
BASEDIR the mount point for the virtual disk /dev/ov
the parent directory for this directory (/dev in the default config) must be readable and executable by any user
DIRS_TO_OVERLAY the directories for which the script creates an overlay mount /system_ext
/product
/odm
/system

FILESYSTEM_TO_USE the filesystem used on the virtual disk
ext4
This must be a filesystem known by the running Android that supports overlay mounts (e.g. ext4 or ext3)

The parameter is only used when creating a new filesystem on the virtual disk.
 
FILESYSTEM_SIZE the size of the virtual disk 100m
the value can be any value that is known by the binary dd for the parameter bs (see the output of "dd --help")

The variable is only used when the virtual disk is created.
MKFS_OPTIONS additional options for the mkfs* command to create the filesystem on the loop device
The variable is only used when the virtual disk is created.

set this variable to "none" to execute mkfs without options
MOUNT_OPTIONS additional options for the mount command to mount the filesystem on the loop device
set this variable to "none" to execute mount without options
SELINUX_CONTEXT the SELinux context used for new directories if the script can not read the SELinux context of an existing directory u:object_r:system_file:s0





MOUNT
mount executable to use
$( which mount )

UMOUNT
umount executable to use $( which umount )
LOSETUP
losetup executable to use $( which losetup )
MKFS
mkfs executable to use $( which mkfs.${FILESYSTEM_TO_USE} )
DD
dd executable to use $( which dd )




UMOUNT_WAIT_TIME
time in seconds to wait between umounting the bind mounts and umounting the overlay mounts
0
in some Android versions it's necessary to wait some time between umounting the bind mount andumounting the overlay mount. Set this variable to the number of seconds the script should wait between these umounts.
BIND_MOUNT_TARGET_DIR
target directory for bind mounts for the files listed in the variable FILES_TO_KEEP
/data/local/tmp
see using Magisk and overlay mounts in parallel
FILES_TO_KEEP
list of files for which a bind mount shoud be created

see using Magisk and overlay mounts in parallel
DIFF
diff executable to use
$( which diff )

DIFF_OPTIONS
options for the diff command -o
set this variable to "none" to execute diff without options
TMPMOUNT_OPTIONS
mount options for the temporary mounts for the devices with the original directories
"-o ro" for read-only mounted filesystems and
"-o rw" for read-write mounted filesystesms
In Android the mount options for rw or ro for a second mount to a device must match the mount options for the first mount
USER_RESPONSE
this is the default value for the questions for confirmation

the known values for this variable are "yes" or "no"
The parameter --yes and --no overwrite the value of this variable


To change one or more of these variables use either a command like this

IMAGE_FILE="/data/local/tmp/image002" BASEDIR="/data/local/tmp/ov2" create_overlay_mount.sh

or this

export IMAGE_FILE="/data/local/tmp/image002"
export BASEDIR="/data/local/tmp/ov2"

create_overlay_mount.sh

or this

create_overlay_mount.sh IMAGE_FILE="/data/local/tmp/image002" BASEDIR="/data/local/tmp/ov2"


Note:

Use

create_overlay_mount.sh vars

to only print the current list of supported environment variables with the default values and the current values (see here).




Description of the backend directories used for the overlay mounts


The new files created in the directories with overlay mounts can be found in the directory

${BASEDIR}/upper/${DIR_NAME}

e.g. using the default BASEDIR:

ASUS_I006D:/data/local/tmp # df -h /odm
Filesystem      Size Used Avail Use% Mounted on
overlay          88M  55K   88M   1% /odm
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # touch /odm/testfile.$$
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -ldZ /odm/testfile.$$
-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2025-06-24 21:59 /odm/testfile.4944
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -ldZ /dev/ov/upper/odm/testfile.4944
-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2025-06-24 21:59 /dev/ov/upper/odm/testfile.4944
ASUS_I006D:/data/local/tmp #




For sub directories with overlay mounts the directory name in the directory ${BASEDIR}/upper is in the format subir1#subdir2#....#subdirN,

For an overlay mount for /vendor/vendor_dlkm/etc the directory name is vendor#vendor_dlkm#etc :

ASUS_I006D:/data/local/tmp # df -h /vendor/vendor_dlkm/
Filesystem      Size Used Avail Use% Mounted on
/dev/block/dm-4 1.1G 1.1G  3.5M 100% /vendor
ASUS_I006D:/data/local/tmp #   
                                                                                                                                              
ASUS_I006D:/data/local/tmp # df -h /vendor/vendor_dlkm/etc
Filesystem      Size Used Avail Use% Mounted on
overlay          88M  59K   88M   1% /vendor/vendor_dlkm/etc
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # touch /vendor/vendor_dlkm/etc/test.$$
ASUS_I006D:/data/local/tmp #
ASUS_I006D:/data/local/tmp # ls -ldZ /vendor/vendor_dlkm/etc/test.$$
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  0 2025-06-24 22:02 /vendor/vendor_dlkm/etc/test.4944
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -ldZ /dev/ov/upper/vendor\#vendor_dlkm\#etc/test.$$
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  0 2025-06-24 22:02 /dev/ov/upper/vendor#vendor_dlkm#etc/test.4944
ASUS_I006D:/data/local/tmp #


For deleted files or directories a character device with major 0 and minor 0 is created in the directory ./upper, e.g:

ASUS_I006D:/data/local/tmp # rm /vendor/etc/ueventd.rc
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # ls -l /vendor/etc/ueventd.rc
ls: /vendor/etc/ueventd.rc: No such file or directory

1|ASUS_I006D:/data/local/tmp #

1|ASUS_I006D:/data/local/tmp # ls -l /data/local/tmp/ov/upper/vendor\#etc/ueventd.rc
c--------- 1 root root 0,   0 2025-06-14 14:17 /data/local/tmp/ov/upper/vendor#etc/ueventd.rc
ASUS_I006D:/data/local/tmp #


Notes

Use the action get to print the backend for a file in a directory with an overlay mount:


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /odm/testfile.4944
/dev/ov/upper/odm/testfile.4944 # /odm/testfile.4944 # the file was changed

ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /odm/testfile.4944 --details
-rw-r--r-- 1 root root u:object_r:vendor_file:s0  0 2025-06-24 21:59 /dev/ov/upper/odm/testfile.4944 # /odm/testfile.4944 # the file was changed

ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp #
/data/local/tmp/create_overlay_mount.sh get /vendor/vendor_dlkm/etc/test.4944
/dev/ov/upper/vendor#vendor_dlkm#etc/test.4944 # /vendor/vendor_dlkm/etc/test.4944 # the file was changed

ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh get /vendor/vendor_dlkm/etc/test.4944  --details
-rw-r--r-- 1 root root u:object_r:vendor_configs_file:s0  0 2025-06-24 22:02 /dev/ov/upper/vendor#vendor_dlkm#etc/test.4944 # /vendor/vendor_dlkm/etc/test.4944 # the file was changed

ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor/etc/ueventd.rc
/dev/ov/upper/vendor#etc/ueventd.rc # /vendor/etc/ueventd.rc # the file/directory was deleted

ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  get /vendor/etc/ueventd.rc  --details
c--------- 1 root root u:object_r:vendor_configs_file:s0  0,   0 2025-06-24 22:08 /dev/ov/upper/vendor#etc/ueventd.rc # /vendor/etc/ueventd.rc # the file/directory was deleted

ASUS_I006D:/data/local/tmp #




Using Magisk and overlay mounts in parallel


The Magisk executables, such as magisk, su, etc, are no longer visible after configuring an overlay mount for the directory with these files.

To work around this issue, create_overlay_mount.sh creates bind mounts for the Magisk executables magisk, su, magiskpolicy, and resetprop before mounting an overlay filesystem for the directory containing the Magisk executables.

These bind mounts can then be used instead of the original executables.

For example if the Magisk executables are installed in /system/bin:


ASUS_I006D:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012(readtracefs) context=u:r:shell:s0
ASUS_I006D:/ $

ASUS_I006D:/ $ which su
/system/bin/su
ASUS_I006D:/ $

ASUS_I006D:/ $ su - -c /data/local/tmp/create_overlay_mount.sh /system

The image file "/data/local/tmp/image001" already exists - there should already be a filesystem
Creating the directory "/dev/ov" ...
Mounting the imagefile "/data/local/tmp/image001" to "/dev/ov" ...

Creating and mounting the directories for the overlay mount for "/system" ...

Magisk is installed - creating temporary copies of the Magisk executables ...
Creating the temporary file "/data/local/tmp/system/bin/magisk" ...
Creating the temporary file "/data/local/tmp/system/bin/su" ...
Creating the temporary file "/data/local/tmp/system/bin/resetprop" ...
Creating the temporary file "/data/local/tmp/system/bin/magiskpolicy" ...

Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Summary:
--------

1 overlay mount(s) created:

  /system

ASUS_I006D:/ $

ASUS_I006D:/ $ which su

1|ASUS_I006D:/ $

1|ASUS_I006D:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012(readtracefs) context=u:r:shell:s0
ASUS_I006D:/ $

# use the bind mount instead of the now hidden original files
#
ASUS_I006D:/ $ /data/local/tmp/system/bin/su -

ASUS_I006D:/ #

ASUS_I006D:/ # id

uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #


This also works if the Magisk binaries are installed in any other directory, e.g. if the Magisk executables are in /product/bin:

ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh /product
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/product" ...

Magisk is installed in /product/bin - creating temporary copies of the Magisk executables ...
Creating the temporary file "/data/local/tmp/product/bin/magisk" ...
Creating the temporary file "/data/local/tmp/product/bin/su" ...
Creating the temporary file "/data/local/tmp/product/bin/resetprop" ...
Creating the temporary file "/data/local/tmp/product/bin/magiskpolicy" ...

Creating the overlay mount for "/product" ...
Creating the bind mount "/product"...
Checking the overlay mount for "/product" ...

Summary:
--------

1 overlay mount(s) created:

  /product

ASUS_I006D:/ $


Note

Use the parameter --nomagisk to disable creating bind mounts for the Magisk executables



How to keep files installed via Magisk module



Files created with Magisk modules, e.g. in /system/bin, are no longer visible after configuring an overlay mount for /system.

To create bind mounts for these files, add the filenames to the environment variable FILES_TO_KEEP before calling the script create_overlay_mounts.sh.

The number of filenames in the variable FILES_TO_KEEP is not limited by the script; the filenames must be separated by white spaces or commas. The files must exist.  bind mounts for directories are not supported.

The filenames in the variable FILES_TO_KEEP are interpreted by the script using these rules:

Rule
Example
filenames without a slash are searched in the directory "/system/bin" bash -> /system/bin/bash
filenames starting with "bin/" are searched in the directory "/system" bin/sh -> /system/bin/sh
filenames starting with "./" are searched in the directory "/system" /etc/ssh/sshd_config  -> /system/etc/ssh/sshd_config
fully qualified names are searched in "/" /system_ext/bin/rsync -> /system_ext/bin/rsync



All files in other directories than /system must be specified with fully qualified directory name.

The script create_overlay_mount.sh only creates bind mounts for files in a directory for which an overlay mount should be created. Other entries in the variable FILES_TO_KEEP are silently ignored


Example:


ASUS_I006D:/ $ FILES_TO_KEEP="dmesg bin/sh /system_ext/bin/rsync ./etc/ssh/sshd_config ./usr/bin/fuser ./bin/7zz"  su - -c /data/local/tmp/create_overlay_mount.sh /system /system_ext
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk
Creating the directory "/dev/ov" ...
Mounting the image file "/data/local/tmp/image001" to "/dev/ov" ...

Creating and mounting the directories for the overlay mount for "/system" ...
Creating the temporary file "/data/local/tmp/system/bin/dmesg" ...
Creating the temporary file "/data/local/tmp/system/bin/sh" ...
Creating the temporary file "/data/local/tmp/system/etc/ssh/sshd_config" ...
Creating the temporary file "/data/local/tmp/system/usr/bin/fuser" ...
Creating the temporary file "/data/local/tmp/system/bin/7zz" ...

Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Creating and mounting the directories for the overlay mount for "/system_ext" ...
Creating the temporary file "/data/local/tmp/system_ext/bin/rsync" ...

Creating the overlay mount for "/system_ext" ...
Creating the bind mount "/system_ext"...
Checking the overlay mount for "/system_ext" ...

Summary:
--------

2 overlay mount(s) created:

  /system
  /system_ext

ASUS_I006D:/ $



The default target directory for the bind mounts is /data/local/tmp. To change the directory for the bind mounts, set the variable BIND_MOUNT_TARGET_DIR, e.g.:

ASUS_I006D:/ $ mkdir -p /data/local/tmp/bind_mounts
ASUS_I006D:/ $

ASUS_I006D:/ $ FILES_TO_KEEP="bvi ./bin/DebugTools/7zz"  su - -c /data/local/tmp/create_overlay_mount.sh /system BIND_MOUNT_TARGET_DIR=/data/local/tmp/bind_mounts
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem
Creating the directory "/dev/ov" ...
Mounting the imagefile "/data/local/tmp/image001" to "/dev/ov" ...

Creating and mounting the directories for the overlay mount for "/system" ...

Magisk is installed - creating temporary copies of the Magisk executables ...
Creating the temporary file "/data/local/tmp/bind_mounts/system/bin/bvi" ...
Creating the temporary file "/data/local/tmp/bind_mounts/system/bin/DebugTools/7zz" ...
Creating the temporary file "/data/local/tmp/bind_mounts/system/bin/magisk" ...
Creating the temporary file "/data/local/tmp/bind_mounts/system/bin/su" ...
Creating the temporary file "/data/local/tmp/bind_mounts/system/bin/resetprop" ...

Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Summary:
--------

1 overlay mount(s) created:

  /system

ASUS_I006D:/ $


If there are many files implemented via Magisk Modules, I recommend to copy these files to /system after creating the overlay mount:

# Copy the files from the Magisk module myscripts to /system:
 
cp -r /data/adb/modules/myscripts/system/* /system 



Creating the overlay mounts early in the boot process


The script create_overlay_mount.sh can also run early in the boot process if Magisk (or a similar tool) is installed. E.g. with installed Magisk do:

Copy the script to /data/adb/create_overlay_mount.sh into the directory /data/adb and create a start script in the directory /data/adb/post-fs-data.d:

cat <<EOT >/data/adb/post-fs-data.d/configure_overlay_mounts.sh
exec 2>/cache/confiure_overlay.log 1>&2
set -x
/data/adb/create_overlay_mount.sh mount
EOT
chmod 755 /data/adb/post-fs-data.d/configure_overlay_mounts.sh


In this case, the restrictions described above regarding the command "su" and the installed Magisk modules do not apply.

But not all sub directories in /system are writable using this approach. Furthermore, other problems may arise when using the script this way.

Therefore, this approach is not recommended—it is better to copy the necessary files from the Magisk modules from /data/adb/modules/<module name>/system to /system while the overlay file system is mounted.

Warning

You should have a working recovery such as TWRP that can access the files in the directory /data for your phone before adding files to /data/adb/post-fs-data.d.

Starting the phone in Safe mode does NOT help to fix a buggy script in /data/adb/post-fs-data.d!

When booted into the recovery of most Android distributions the access to /data is not possible!



See here for instructions to manually create an overlay mount in Android.



Filesystem structure on a virtual disk


The general filesystem structure on a virtual disk with an overlay filesystem is:

ASUS_I006D:/dev/ov # ls -ld $( find . -maxdepth 2 )
drwxr-xr-x  8 root  root   1024 2026-10-31 10:01 .
drwx------  2 root  root  12288 2026-10-28 13:05 ./lost+found
drwxrwxrwx 17 root  root   1024 2026-11-02 20:33 ./merged
lrwxrwxrwx  1 root  root      4 2026-10-28 13:05 ./merged/dev -> /dev
lrwxrwxrwx  1 root  root      5 2026-10-28 13:05 ./merged/proc -> /proc
lrwxrwxrwx  1 root  root      4 2026-10-28 13:05 ./merged/sys -> /sys
drwxr-xr-x  2 root  root   1024 2026-10-28 13:05 ./merged/system
drwxr-xr-x  7 root  root   1024 2026-10-31 16:05 ./rootfs
drwxr-xr-x  3 root  root   1024 2026-10-31 16:05 ./rootfs/system
drwxrwxrwx 17 root  root   1024 2026-11-02 20:33 ./upper
drwxr-xr-x  2 root  root   1024 2026-11-02 15:23 ./upper/system
drwxrwxrwx 17 root  root   1024 2026-10-31 16:05 ./work
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/system
ASUS_I006D:/dev/ov #


 
In this example, there is only an overlay filesystem for /system on the virtual disk. For virtual disks with overlay directories for various directories, the directory tree on the virtual disk looks like this

ls -ld $( find . -maxdepth 2 )
ASUS_I006D:/dev/ov #  ls -ld $(sudo  find . -maxdepth 2 )   
drwxr-xr-x  8 root  root   1024 2026-10-31 10:01 .
drwx------  2 root  root  12288 2026-10-28 13:05 ./lost+found
drwxrwxrwx 17 root  root   1024 2026-11-02 20:33 ./merged
drwxr-xr-x  2 root  root   1024 2026-10-31 16:05 ./merged/data#local#tmp#sysroot
lrwxrwxrwx  1 root  root      4 2026-10-28 13:05 ./merged/dev -> /dev
drwxr-xr-x  2 root  root   1024 2026-10-28 13:05 ./merged/odm
drwxr-xr-x  2 root  root   1024 2026-10-31 10:28 ./merged/odm#etc
drwxr-xr-x  1 root  root   1024 2026-11-02 20:33 ./merged/odm_dlkm
lrwxrwxrwx  1 root  root      5 2026-10-28 13:05 ./merged/proc -> /proc
drwxr-xr-x  2 root  root   1024 2026-10-28 13:05 ./merged/product
drwxr-xr-x  2 root  root   1024 2026-10-28 20:05 ./merged/product#etc
drwxr-xr-x  2 root  root   1024 2026-10-31 12:24 ./merged/product#usr
lrwxrwxrwx  1 root  root      4 2026-10-28 13:05 ./merged/sys -> /sys
drwxr-xr-x  2 root  root   1024 2026-10-28 13:05 ./merged/system
drwxr-xr-x  2 root  root   1024 2026-10-28 20:05 ./merged/system#etc
drwxr-xr-x  2 root  root   1024 2026-10-28 13:05 ./merged/system_ext
drwxr-xr-x  2 root  root   1024 2026-10-29 14:51 ./merged/system_ext#etc
drwxr-xr-x  2 root  root   1024 2026-10-29 14:51 ./merged/system_ext#framework
drwxr-xr-x  1 root  shell  1024 2026-10-28 19:53 ./merged/vendor
drwxr-xr-x  2 root  root   1024 2026-10-31 12:24 ./merged/vendor#bin
drwxr-xr-x  2 root  root   1024 2026-10-29 14:38 ./merged/vendor#etc
drwxr-xr-x  7 root  root   1024 2026-10-31 16:05 ./rootfs
drwxr-xr-x  3 root  root   1024 2026-10-31 16:05 ./rootfs/data
drwxr-xr-x  3 root  root   1024 2026-10-31 10:28 ./rootfs/odm
drwxr-xr-x  2 root  root   1024 2026-10-31 12:24 ./rootfs/product
drwxr-xr-x  2 root  root   1024 2026-10-31 12:23 ./rootfs/system_ext
drwxr-xr-x 16 root  shell  4096 2009-01-01 01:00 ./rootfs/vendor
drwxr-xr-x  4 root  root   1024 2026-10-31 07:58 ./tmp
drwxr-xr-x  2 root  root   1024 2026-10-31 07:55 ./tmp/rootfs
drwxr-xr-x  2 root  root   1024 2026-10-31 07:58 ./tmp/vendor
drwxrwxrwx 17 root  root   1024 2026-11-02 20:33 ./upper
drwxrwxr-x  5 shell shell  1024 2026-11-02 15:23 ./upper/data#local#tmp#sysroot
drwxr-xr-x  2 root  root   1024 2026-11-02 15:23 ./upper/odm
drwxr-xr-x  2 root  root   1024 2026-10-31 10:28 ./upper/odm#etc
drwxr-xr-x  2 root  root   1024 2026-11-02 20:33 ./upper/odm_dlkm
drwxr-xr-x  2 root  root   1024 2026-11-02 15:23 ./upper/product
drwxr-xr-x  2 root  root   1024 2026-10-28 20:05 ./upper/product#etc
drwxr-xr-x  2 root  root   1024 2026-10-31 12:24 ./upper/product#usr
drwxr-xr-x  2 root  root   1024 2026-11-02 15:23 ./upper/system
drwxr-xr-x  2 root  root   1024 2026-10-28 20:05 ./upper/system#etc
drwxr-xr-x  3 root  root   1024 2026-11-02 15:23 ./upper/system_ext
drwxr-xr-x  2 root  root   1024 2026-10-29 14:51 ./upper/system_ext#etc
drwxr-xr-x  2 root  root   1024 2026-10-29 14:51 ./upper/system_ext#framework
drwxr-xr-x  3 root  shell  1024 2026-10-28 19:53 ./upper/vendor
drwxr-x--x  2 root  shell  1024 2026-11-02 15:23 ./upper/vendor#bin
drwxr-xr-x  4 root  shell  1024 2026-11-02 15:23 ./upper/vendor#etc
drwxrwxrwx 17 root  root   1024 2026-10-31 16:05 ./work
drwxr-xr-x  3 root  root   1024 2026-11-01 19:18 ./work/data#local#tmp#sysroot
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/odm
drwxr-xr-x  3 root  root   1024 2026-10-31 12:23 ./work/odm#etc
drwxr-xr-x  3 root  root   1024 2026-11-02 20:33 ./work/odm_dlkm
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/product
drwxr-xr-x  3 root  root   1024 2026-10-29 14:51 ./work/product#etc
drwxr-xr-x  3 root  root   1024 2026-10-31 12:24 ./work/product#usr
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/system
drwxr-xr-x  3 root  root   1024 2026-10-29 14:51 ./work/system#etc
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/system_ext
drwxr-xr-x  3 root  root   1024 2026-10-29 14:51 ./work/system_ext#etc
drwxr-xr-x  3 root  root   1024 2026-10-29 14:51 ./work/system_ext#framework
drwxr-xr-x  3 root  root   1024 2026-11-02 20:45 ./work/vendor
drwxr-xr-x  3 root  root   1024 2026-11-02 14:18 ./work/vendor#bin
drwxr-xr-x  3 root  root   1024 2026-11-02 07:31 ./work/vendor#etc
ASUS_I006D:/dev/ov #


All files for the overlay filesystems for directory <dirname>, are in the directory ./upper/<dirname>, e.g. the overlay filesystem for /system is ./upper/system.

The directory ./rootfs/system is mounted on the device with the original /system directory. The files in this directory are only used for the action diff_file -- they are not used for the overlay filesystem.


The other directories on the virtual disk must not contain any files or directories.

This directory structure is automatically created by the script create_overlay_mount.sh on new virtual disks.

See the script create_virtual_disk.sh in the repository https://github.com/bnsmb/Virtual-Disks-with-a-clang-toolchain for the commands to create the directories on a virtual disk manually .



Using multiple virtual disks in parallel


The script also supports mounting overlay file systems on different virtual disks at the same time. To distinguish between the different virtual disks the variable BASEDIR is used.

Therefore, to use different virtual disks in parallel the variable BASEDIR must also be different:

Example for using multiple virtual disks
ASUS_I006D:/data/local/tmp $ IMAGE_FILE=/data/local/tmp/virtualdisk002 BASEDIR=/data/local/tmp/virtualfs002 ./create_overlay_mount.sh /odm /odm_dlkm 
The image file "/data/local/tmp/virtualdisk002" already exists - there should already be a filesystem on the disk
Mounting the image file "/data/local/tmp/virtualdisk002" to "/data/local/tmp/virtualfs002" ...

Creating and mounting the directories for the overlay mount for "/odm" ...

Creating the overlay mount for "/odm" ...
Mounting "/data/local/tmp/virtualfs002/rootfs" on "/dev/block/dm-2" ...
Mounting "/data/local/tmp/virtualfs002/rootfs/odm" on "/dev/block/dm-0" ...
Creating the bind mount "/odm"...
Checking the overlay mount for "/odm" ...

Creating and mounting the directories for the overlay mount for "/odm_dlkm" ...

Creating the overlay mount for "/odm_dlkm" ...
 "/odm_dlkm" is not on a separate device -- no tempporary mount is necessary or this directory
Creating the bind mount "/odm_dlkm"...
Checking the overlay mount for "/odm_dlkm" ...

Summary:
--------

2 overlay mount(s) created:

  /odm
  /odm_dlkm

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ IMAGE_FILE=/data/local/tmp/virtualdisk001 BASEDIR=/data/local/tmp/virtualfs001 ./create_overlay_mount.sh /vendor /vendor_dlkm
The image file "/data/local/tmp/virtualdisk001" already exists - there should already be a filesystem on the disk
Mounting the image file "/data/local/tmp/virtualdisk001" to "/data/local/tmp/virtualfs001" ...

Creating and mounting the directories for the overlay mount for "/vendor" ...

Creating the overlay mount for "/vendor" ...
Mounting "/data/local/tmp/virtualfs001/rootfs" on "/dev/block/dm-2" ...
Mounting "/data/local/tmp/virtualfs001/rootfs/vendor" on "/dev/block/dm-4" ...
Creating the bind mount "/vendor"...
Remounting the mount point "/vendor/bt_firmware" ...
Remounting the mount point "/vendor/dsp" ...
Remounting the mount point "/vendor/firmware_mnt" ...
Checking the overlay mount for "/vendor" ...

Creating and mounting the directories for the overlay mount for "/vendor_dlkm" ...

Creating the overlay mount for "/vendor_dlkm" ...
Mounting "/data/local/tmp/virtualfs001/rootfs/vendor_dlkm" on "/dev/block/dm-5" ...
Creating the bind mount "/vendor_dlkm"...
Checking the overlay mount for "/vendor_dlkm" ...

Summary:
--------

2 overlay mount(s) created:

  /vendor
  /vendor_dlkm

ASUS_I006D:/data/local/tmp $
ASUS_I006D:/data/local/tmp $
ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list --details
Directories mounted on an overlay filesystem

Directory         Backend Directory
---------         -----------------
/odm              /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/odm_dlkm         /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/vendor           /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/vendor_dlkm      /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)

ASUS_I006D:/data/local/tmp $


----

Note that in this case you must always use BASEDIR=<base_directory> to process the overlay mounts (e.g. for the actions mount, undo, umount, diff, etc).


Overlay mounts without specifiying the BASEDIR are still created on the default virtual disk.

Example:

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh  /system_ext
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/system_ext" ...

Creating the overlay mount for "/system_ext" ...
Mounting "/dev/ov/rootfs/system_ext" on "/dev/block/dm-3" ...
Creating the bind mount "/system_ext"...
Checking the overlay mount for "/system_ext" ...

Summary:
--------

1 overlay mount(s) created:

  /system_ext

ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list --details
Directories mounted on an overlay filesystem

Directory         Backend Directory
---------         -----------------
/odm              /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/odm_dlkm         /data/local/tmp/virtualfs002 (Virtual disk: /data/local/tmp/virtualdisk002)
/vendor           /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/vendor_dlkm      /data/local/tmp/virtualfs001 (Virtual disk: /data/local/tmp/virtualdisk001)
/system_ext       /dev/ov (Virtual disk: /data/local/tmp/image001)

ASUS_I006D:/data/local/tmp $



Therefore, it's recommended to create different wrapper scripts for using multiple virtual disks.


This feature can be used, for example, to create different test environments.



Calculating the size for the file used as virtual disk



The default size for virtual disks created by create_overlay_mount.sh is 100 MB. This not that much. On the other hand, it's quite simple to increase the size of a virtual disk -- see here for instructions to do that.


To create a virtual disk with another size, set the environment variable FILESYSTEM_SIZE to the size for the virtual disk -- e.g. to create a virtual disk with 1 GB use

./create_overlay_mount.sh FILESYSTEM_SIZE=1g ...

Note: The environment variable FILESYSTEM_SIZE is only used when the file for the virtual disk is crreated, the value for this variable must be a valid parameter for the parameter bs from the dd command.


Or create the file for the virtual disk as sparse file using the script parameter --sparse : sparse files for virtual disks only use the space of the files in the filesystems on the virtual disk. For example a sparse file with 1 GB used as virtual disk with empty filesystem looks like this:

ASUS_I006D:/data/local/tmp # ls -lh /data/local/tmp/sparse.img
-rw-rw-rw- 1 shell shell 1.0G 2026-11-04 09:54 /data/local/tmp/sparse.img
ASUS_I006D:/data/local/tmp #       

# the disk space used for that file is:

ASUS_I006D:/data/local/tmp # du -hs /data/local/tmp/sparse.img
32M    /data/local/tmp/sparse.img

ASUS_I006D:/data/local/tmp #


But be aware, that most commands in Android do not support sparse files -- they just convert them to "normal" files.

Example:

ASUS_I006D:/data/local/tmp # cp  /data/local/tmp/sparse.img /data/local/tmp/sparse.img.copy
ASUS_I006D:/data/local/tmp #

ASUS_I006D:/data/local/tmp # du -hs  /data/local/tmp/sparse.img /data/local/tmp/sparse.img.copy                                                                                                                                                    
32M    /data/local/tmp/sparse.img
1.0G    /data/local/tmp/sparse.img.copy
ASUS_I006D:/data/local/tmp #


You can use the tar executable in Android to copy sparse file -- the tar executable (at least in /e/) supports sparse files if the parameter --sparse is used.

 


Creating an empty virtual disk


To create a new virtual disk /data/local/tmp/image001_ext3 with 50 MB and ext3 filesystem without creating any overlay filesystem use this command:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/data/local/tmp/image001_ext3 FILESYSTEM_TO_USE=ext3 FILESYSTEM_SIZE=50m BASEDIR=/data/local/tmp/ovtest mount_only

ASUS_I006D:/ #  /data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/data/local/tmp/image001_ext3 FILESYSTEM_TO_USE=ext3 FILESYSTEM_SIZE=50m BASEDIR=/data/local/tmp/ovtest mount_only
Creating the image file "/data/local/tmp/image001_ext3" with the size 50m ...
1+0 records in
1+0 records out
52428800 bytes (50 M) copied, 0.056713 s, 882 M/s
Creating a "ext3" filesystem on the image file "/data/local/tmp/image001_ext3" now ...
mke2fs 1.46.2 (28-Feb-2021)
Discarding device blocks: done                           
Creating filesystem with 51200 1k blocks and 12824 inodes
Filesystem UUID: e5433d8e-da14-4ca5-bae1-1c7a7b13382c
Superblock backups stored on blocks:
    8193, 24577, 40961

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Creating the directory "/data/local/tmp/ovtest" ...
Mounting the imagefile "/data/local/tmp/image001_ext3" to "/data/local/tmp/ovtest" ...

The virtual disk is mounted to "/data/local/tmp/ovtest"

ASUS_I006D:/ #


----


To use the file /data/local/tmp/image001_ext3 for overlay mounts later use:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/data/local/tmp/image001_ext3  BASEDIR=/data/local/tmp/ovtest  /odm /odm_dlkm
ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/data/local/tmp/image001_ext3  BASEDIR=/data/local/tmp/ovtest  /odm /odm_dlkm
The image file "/data/local/tmp/image001_ext3" already exists - there should already be a filesystem
Creating the directory "/data/local/tmp/ovtest/upper" ...
Creating the directory "/data/local/tmp/ovtest/merged" ...
Creating the directory "/data/local/tmp/ovtest/work" ...

Creating and mounting the directories for the overlay mount for "/odm" ...
Creating the directory "/data/local/tmp/ovtest/upper/odm" ...
Creating the directory "/data/local/tmp/ovtest/merged/odm" ...
Creating the directory "/data/local/tmp/ovtest/work/odm" ...
Creating the overlay mount for "/odm" ...
Creating the bind mount "/odm"...
Checking the overlay mount for "/odm" ...

Creating and mounting the directories for the overlay mount for "/odm_dlkm" ...
Creating the directory "/data/local/tmp/ovtest/upper/odm_dlkm" ...
Creating the directory "/data/local/tmp/ovtest/merged/odm_dlkm" ...
Creating the directory "/data/local/tmp/ovtest/work/odm_dlkm" ...
Creating the overlay mount for "/odm_dlkm" ...
Creating the bind mount "/odm_dlkm"...
Checking the overlay mount for "/odm_dlkm" ...

Summary:
--------

2 overlay mount(s) created:

  /odm
  /odm_dlkm

ASUS_I006D:/data/local/tmp #


----



Increasing the size of a virtual disk


ext3 and ext4 filesystems can be increased while mounted:

Instructions to increase the virtual disk used as backend
# Note: only the commands in bold are necessary to increase the virtual disk

ASUS_I006D:/ # ls -lh /data/local/tmp/image001
-rw-r--r-- 1 root root 10M 2025-03-15 20:36 /data/local/tmp/image001
ASUS_I006D:/ #

# -> the size of the file used as virtual disk is 10 MB

ASUS_I006D:/ # df -h /data/local/tmp/ov
Filesystem        Size Used Avail Use% Mounted on
/dev/block/loop31 8.6M  39K  8.6M   1% /data/local/tmp/ov
ASUS_I006D:/ #

# increase the size of the file /data/local/tmp/image001 by 50M

ASUS_I006D:/ # dd if=/dev/zero count=1 bs=50m >>/data/local/tmp/image001
1+0 records in
1+0 records out
52428800 bytes (50 M) copied, 0.058147 s, 860 M/s
ASUS_I006D:/ #

ASUS_I006D:/ # ls -lh /data/local/tmp/image001
-rw-r--r-- 1 root root 60M 2025-03-15 20:38 /data/local/tmp/image001
ASUS_I006D:/ #


# -> the size of the file used as virtual disk is now 60 MB

# update the loop device
#
ASUS_I006D:/ # losetup -j /data/local/tmp/image001 -c
ASUS_I006D:/ #

# resize the filesystem on the virtual disk
#
ASUS_I006D:/ # resize2fs /dev/block/loop31
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/block/loop31 is mounted on /data/local/tmp/ov; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/block/loop31 is now 61440 (1k) blocks long.

ASUS_I006D:/ #

ASUS_I006D:/ # df -h /data/local/tmp/ov
Filesystem        Size Used Avail Use% Mounted on
/dev/block/loop31  58M  39K   58M   1% /data/local/tmp/ov
ASUS_I006D:/ #



Note:

ext4 filesystem can also be decreased when the filesystem is not mounted but it is not that easy to shrink the file used for the virtual disk.

 

Using virtual disks created on a non-Android OS


For virtual disks created on operating systems other than Android, the SELinux context for most files and directories on the virtual disk is “system_u:object_r:unlabeled_t:s0” or “unconfined_u:object_r:default_t:s0” or something similar. Because of this SELinux context, these files cannot be accessed by users without root privileges. Therefore, it is essential to correct the SELinux context for these files before they can be used.

The “--relabel” parameter of the script create_overlay_mount.sh can be used for this purpose:

If the “--relabel” parameter is specified, the script corrects the SELinux context for all files in the overlay directories for all directories specified in the parameters for the script. The SELinux context used for this modification is the SELinux context of the target directory for the overlay mount. The script modifies only the files with an SELinux context that matches the expression "*:unlabeled*" or "*:default:*"-.

If the SELinux context of the files is to be corrected only for certain overlay file systems, the file “relabel” can be created in those directories. In this case, the “--relabel” parameter must not be specified.
For the overlay filesystem for /system, this is, for example, the file ./upper/system/relabel.

To relabel the files in the overlay filesystem with other SELinux contexts, create a script to change the SELinux context and run it as post install script using the parameter "--run=script". The script can also be located on the overlay filesystem. Do not use the parameter "--relabel" in this case.

If the parameter --norelabel” is specified, the “relabel” files are ignored.

To correct the SELinux contexts in all overlay filesystems on the virtual disk, the following script command can also be used:

create_overlay_mount.sh --relabel mount_only

Using these parameter, the script mounts the virtual disk and corrects the SELinux context for all overlay filesystems on the virtual disk without mounting the overlay file systems.

The code for correcting the SELinux context is currently implemented only for overlay filesystems for directories in the root directory (such as /system, /product, /vendor, etc.)

Please note that these correction must only done once for each overlay filesystem on the virtual disk but it does not harm, if the code to change the SELInux context for the files is executed each time the virtual disk is mounted.

For virtual disks created under Android, no correction for the SELinux context is necessary.



Miscellaneous




Instructions to create an overlay mount manually



This section contains detailed instructions to create overlay mounts manually.

Manually create an overlay mount for /system_ext

The standard filesystems on Android for data partitions do not support overlay filesystems; therefor a virtual disk is necessary to use overlay mounts.

The virtual disk with a filesystem that supports overlay mounts like ext4 or ext3 can be created and mounted using these commands:

# define variables
#
ASUS_I006D:/ # TARGET_DIR="/system_ext"
ASUS_I006D:/ # SELINUX_CONTEXT=$( stat -c %C ${TARGET_DIR} )

ASUS_I006D:/ # MOUNT_POINT="/dev/virtualfs"
ASUS_I006D:/ # VIRTUAL_DISK="/data/local/tmp/virtualdisk"

# create and format the file used as virtual disk

ASUS_I006D:/ #  dd if=/dev/zero of=${VIRTUAL_DISK} bs=10m count=1
1+0 records in
1+0 records out
10485760 bytes (10 M) copied, 0.028 s, 357 M/s
ASUS_I006D:/ #

ASUS_I006D:/ # ls -lh ${VIRTUAL_DISK}
-rw-r--r-- 1 root root 10M 2025-06-24 08:17 /data/local/tmp/virtualdisk
ASUS_I006D:/ #

ASUS_I006D:/ # mkfs.ext4 ${VIRTUAL_DISK}
mke2fs 1.46.6 (1-Feb-2023)
128-byte inodes cannot handle dates beyond 2038 and are deprecated
Discarding device blocks: done                      
Creating filesystem with 10240 1k blocks and 2560 inodes
Filesystem UUID: fe5d0925-5e0e-43bf-b701-3744fb315128
Superblock backups stored on blocks:
    8193

Allocating group tables: done                      
Writing inode tables: done                      
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

ASUS_I006D:/ #

# create and mount the virtual disk

ASUS_I006D:/ #  mkdir ${MOUNT_POINT}
ASUS_I006D:/ #

ASUS_I006D:/ # chcon u:object_r:system_file:s0 ${MOUNT_POINT}
ASUS_I006D:/ #

ASUS_I006D:/ # mount ${VIRTUAL_DISK} ${MOUNT_POINT}

ASUS_I006D:/ #


# correct the SElinux context once again after the mount

ASUS_I006D:/ # chcon u:object_r:system_file:s0 ${MOUNT_POINT}
ASUS_I006D:/ #


ASUS_I006D:/ # df -h ${MOUNT_POINT}
Filesystem        Size Used Avail Use% Mounted on
/dev/block/loop36 8.6M  13K  8.6M   1% /dev/virtualfs
ASUS_I006D:/ #


1|ASUS_I006D:/ # mount | grep ${MOUNT_POINT}
/dev/block/loop35 on /dev/virtualfs type ext4 (rw,seclabel,relatime)
ASUS_I006D:/ #


Next create the necessary directory structure for overlay mounts:

ASUS_I006D:/ # mkdir ${MOUNT_POINT}/{upper,work,merged}
ASUS_I006D:/ #

ASUS_I006D:/ # chcon u:object_r:system_file:s0   ${MOUNT_POINT}/{upper,work,merged}
ASUS_I006D:/ #
ASUS_I006D:/ # chcon u:object_r:rootfs:s0 ${MOUNT_POINT}/lost+found
ASUS_I006D:/ #

ASUS_I006D:/ # ls -ldZ $( find ${MOUNT_POINT} )
drwxr-xr-x 6 root root u:object_r:system_file:s0   1024 2025-06-24 08:37 /dev/virtualfs
drwx------ 2 root root u:object_r:rootfs:s0       12288 2025-06-24 08:35 /dev/virtualfs/lost+found
drwxr-xr-x 2 root root u:object_r:system_file:s0   1024 2025-06-24 08:37 /dev/virtualfs/merged
drwxr-xr-x 2 root root u:object_r:system_file:s0   1024 2025-06-24 08:37 /dev/virtualfs/upper
drwxr-xr-x 2 root root u:object_r:system_file:s0   1024 2025-06-24 08:37 /dev/virtualfs/work
ASUS_I006D:/ #


Then create the directories for an overlay mount for the directory /system_ext:

ASUS_I006D:/ # mkdir ${MOUNT_POINT}/{upper,work,merged}${TARGET_DIR}
ASUS_I006D:/ #


# correct the SELinux context for the new directories

ASUS_I006D:/ # chcon ${SELINUX_CONTEXT}  ${MOUNT_POINT}/{upper,work,merged}${TARGET_DIR}
ASUS_I006D:/ #


ASUS_I006D:/ # ls -ldZ $( find ${MOUNT_POINT} )
drwxr-xr-x 6 root root u:object_r:unlabeled:s0     1024 2025-06-24 08:18 /dev/virtualfs
drwx------ 2 root root u:object_r:rootfs:s0       12288 2025-06-24 08:18 /dev/virtualfs/lost+found
drwxr-xr-x 3 root root u:object_r:system_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/merged
drwxr-xr-x 2 root root u:object_r:vendor_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/merged/system_ext
drwxr-xr-x 3 root root u:object_r:system_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/upper
drwxr-xr-x 2 root root u:object_r:vendor_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/upper/system_ext
drwxr-xr-x 3 root root u:object_r:system_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/work
drwxr-xr-x 2 root root u:object_r:vendor_file:s0   1024 2025-06-24 08:19 /dev/virtualfs/work/system_ext
ASUS_I006D:/ #


Now we can create the overlay mount for /system_ext:

ASUS_I006D:/ #  mount -t overlay overlay -o lowerdir=${TARGET_DIR},upperdir=${MOUNT_POINT}/upper${TARGET_DIR},workdir=${MOUNT_POINT}/work${TARGET_DIR} ${MOUNT_POINT}/merged${TARGET_DIR}
ASUS_I006D:/ #

ASUS_I006D:/ # df -h ${MOUNT_POINT}/merged${TARGET_DIR}
Filesystem      Size Used Avail Use% Mounted on
overlay         8.6M  22K  8.6M   1% /dev/virtualfs/merged/system_ext
ASUS_I006D:/ #


And last we use a bind mount to make the directory /system_ext writable:

ASUS_I006D:/ # mount -o bind ${MOUNT_POINT}/merged${TARGET_DIR} ${TARGET_DIR}
ASUS_I006D:/ #

ASUS_I006D:/ # df -h ${TARGET_DIR}
Filesystem      Size Used Avail Use% Mounted on
overlay         8.6M  22K  8.6M   1% /system_ext
ASUS_I006D:/ #

To test the writable access, create a dummy file in /system_ext:

ASUS_I006D:/ # touch ${TARGET_DIR}/test.$$
ASUS_I006D:/ #
ASUS_I006D:/ # ls -l ${TARGET_DIR}/test.$$
-rw-r--r-- 1 root root 0 2025-06-24 08:50 /system_ext/test.8065
ASUS_I006D:/ #


That's it .


The modifciations done for files and directories in /system_ext are now in the directory/dev/virtualfs/upper/system_ext:

ASUS_I006D:/ # ls -ldZ ${MOUNT_POINT}/upper${TARGET_DIR}
drwxr-xr-x 2 root root u:object_r:system_file:s0  1024 2025-06-24 09:14 /dev/virtualfs/upper/system_ext
ASUS_I006D:/ #

ASUS_I006D:/ # ls -lZ ${MOUNT_POINT}/upper${TARGET_DIR}
total 1
-rw-r--r-- 1 root root u:object_r:system_file:s0  0 2025-06-24 09:14 test.7285
ASUS_I006D:/ #


The modifications for the files and directdories in/system_ext are saved in the virtual disk and will therefore survive a reboot. But to re-use them, the overlay mount must be recreated after a reboot.

Example:

ASUS_I006D:/ # TARGET_DIR="/system_ext"
ASUS_I006D:/ # MOUNT_POINT="/dev/virtualfs"                                                                                                               
ASUS_I006D:/ # VIRTUAL_DISK="/data/local/tmp/virtualdisk"

ASUS_I006D:/ # id
uid=0(root) gid=0(root) groups=0(root) context=u:r:magisk:s0
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l ${TARGET_DIR}/test.*
ls: /vendor/test.*: No such file or directory
1|ASUS_I006D:/ #
 
1|ASUS_I006D:/ # mkdir -p ${MOUNT_POINT}
ASUS_I006D:/ #

ASUS_I006D:/ # mount ${VIRTUAL_DISK} ${MOUNT_POINT}
ASUS_I006D:/ #

ASUS_I006D:/ #  mount -t overlay overlay -o lowerdir=${TARGET_DIR},upperdir=${MOUNT_POINT}/upper${TARGET_DIR},workdir=${MOUNT_POINT}/work${TARGET_DIR} ${MOUNT_POINT}/merged${TARGET_DIR}
ASUS_I006D:/ #

ASUS_I006D:/ # mount -o bind ${MOUNT_POINT}/merged${TARGET_DIR} ${TARGET_DIR}
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l ${TARGET_DIR}/test.*
-rw-r--r-- 1 root root 0 2025-06-24 08:50 /system_ext/test.8065
ASUS_I006D:/ #


----



Commands to create an overlay mount for cut & paste


Below is the list of commands necessary to create an overlay mount that can be used with cut & paste.

Commands to create an overlay mount for cut & paste
   TARGET_DIR="/system_ext"
   SELINUX_CONTEXT=$( stat -c %C ${TARGET_DIR}   )
   MOUNT_POINT="/dev/virtualfs"
   VIRTUAL_DISK="/data/local/tmp/virtualdisk"


   dd if=/dev/zero of=${VIRTUAL_DISK} bs=10m count=1
   mkfs.ext4 ${VIRTUAL_DISK}

   mkdir -p ${MOUNT_POINT}
   mount ${VIRTUAL_DISK} ${MOUNT_POINT}

   mkdir ${MOUNT_POINT}/{upper,work,merged}
   chcon u:object_r:system_file:s0   ${MOUNT_POINT}/{upper,work,merged}
   chcon u:object_r:rootfs:s0 ${MOUNT_POINT}/lost+found
 
   mkdir ${MOUNT_POINT}/{upper,work,merged}${TARGET_DIR}

   chcon ${SELINUX_CONTEXT} ${MOUNT_POINT}/{upper,work,merged}${TARGET_DIR}

   mount -t overlay overlay -o lowerdir=${TARGET_DIR},upperdir=${MOUNT_POINT}/upper${TARGET_DIR},workdir=${MOUNT_POINT}/work${TARGET_DIR} ${MOUNT_POINT}/merged${TARGET_DIR}
   mount -o bind ${MOUNT_POINT}/merged${TARGET_DIR} ${TARGET_DIR}

   echo "Test:"

   touch ${TARGET_DIR}/test.$$

   ls -l ${TARGET_DIR}/test.$$


----



Example disk images




Virtual disk with a clang21 toolchain


URL : https://xdaforums.com/t/using-a-virtual-disk-with-a-clang21-toolchain-and-android-ndk-r29-for-an-overlay-mount.4764760/


I created a virtual disk image with a clang21 toolchain, the necessary files from the Android NDK r29 for compiling C/C++ programs on the phone, and some other useful tools for compiling source code:

http://bnsmb.de/files/public/Android/clang21_virtual_image.gz

This virtual disk image can be used on any phone with an arm64 CPU and a recent Android version .

The clang21 toolchain contains these executables:

clang 21.0
make 4.4.1
cmake 4.0.1
ninja 1.13.0
gnupatch 2.8
pkg-config 0.29
pkgconf 2.30
autoconf 2.72
automake 1.17
m4 1.4.20
libtool 2.5.3
bison 3.8
flex 2.6.4
git 2.50.1
gdb 16.3
sqlite3 3.50.4
bash 5.2.37
perl 5.42.0
python 3.14.0
rsync 3.4.1
curl 8.11.0
wget2 2.1.0
binutils 2.42
nano 8.6
openssh 10.0p2
openssl 3.5.4
openvpn 2.7
unfsd 0.11
man 2.13.0

plus some other tools

Root access is required for overlay mounting the file system on the virtual disk image; root access is not required to use the compiler and tools from the virtual disk.

Note that the compressed file containing the disk image is approximately 500 MB in size; the uncompressed file containing the virtual disk occupies 2.0 GB of storage space. Approximately 300 MB of storage space is available on the virtual disk


To use the virtual disk use these commands:

Copy the file clang21_virtual_image.gz to the phone and uncompress it:

adb push clang21_virtual_image.gz /sdcard/Download

adb shell gzip -d /sdcard/Download/clang21_virtual_image.gz



Then open an adb shell on the phone, become root user, and configure the virtual disk as overlay file system for the directory /system:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang21_virtual_image /system

(This command must be done once after each reboot of the phone to use the overlay file system)

Example:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang21_virtual_image /system
ASUS_I006D:/ #  /data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang21_virtual_image /system
The image file "/sdcard/Download/clang21_virtual_image" already exists - there should already be a filesystem
Creating the directory "/dev/ov" ...
Mounting the imagefile "/sdcard/Download/clang21_virtual_image" to "/dev/ov" ...

Creating and mounting the directories for the overlay mount for "/system" ...
Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Summary:
--------

1 overlay mount(s) created:

  /system

ASUS_I006D:/ #



Now all files from the virtual disk are available in /system , e.g:

ASUS_I006D:/ $ id
uid=2000(shell) gid=2000(shell) groups=2000(shell),1004(input),1007(log),1011(adb),1015(sdcard_rw),1028(sdcard_r),1078(ext_data_rw),1079(ext_obb_rw),3001(net_bt_admin),3002(net_bt),3003(inet),3006(net_bw_stats),3009(readproc),3011(uhid),3012(readtracefs) context=u:r:shell:s0
ASUS_I006D:/ $

126|ASUS_I006D:/ $ /system/usr/bin/git --version
git version 2.50.1
ASUS_I006D:/ $

ASUS_I006D:/ $ /system/usr/clang21/utils/bin/make --version
GNU Make 4.4.1
Built for aarch64-unknown-linux-android
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
ASUS_I006D:/ $


And the directory /system is writable for the user root:


ASUS_I006D:/ # touch /system/xxx.$$$
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l /system/xxx.$$$
-rw-r--r-- 1 root root 0 2025-10-19 13:49 /system/xxx.3264$
ASUS_I006D:/ #

Note: Some executables on the virtual disk require libraries in /system/usr/lib -- these executables are only usable after initializing the environment (or setting the variable LD_LIBRARY_PATH manually)


Before using the binaries from the clang21 toolchain on the virtual disk in an adb session to compile programs, init the toolchain environment with the command:

source /system/bin/init_clang21_env

(this command must be done once in each adb session using the clang21 toolchain)

Example:


source /system/bin/init_clang21_env
ASUS_I006D:/ $ source /system/bin/init_clang21_env
The clang21 tool chain environment is already prepared for the user "shell" (remove the file "/data/local/tmp/toolchain_prepare_shell_done" to prepare the environment again)
Initializing the clang21 tool chain environment ...

Preparing the clang environment for creating binaries for the CPU type aarch64
Using the home directory "/data/local/tmp/home/shell"
INFO: The target root directory "/data/local/tmp/develop/sysroot" does not exist

Using clang 21                                                                            
Using the NDK /system/usr/ndk/r29                                                          (environment variable NDK_DIR)
Using the sysroot directory /system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot   (environment variable SYSROOT)
Using the target root directory /data/local/tmp/develop/sysroot                            (environment variable TARGET_ROOT)

Environment variables used:

PATH is now:         /system/usr/clang21/bin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin:/system/usr/clang21/utils/bin:/system/usr/bin

LD_LIBRARY_PATH:     :/system/usr/lib:/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/lib/aarch64-linux-android:/system/usr/clang21/lib

API is now:          31
NDK_DIR is now:      /system/usr/ndk/r29

SYSROOT is now:      /system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot

CFLAGS are now:       -I/system/usr/include -I/system/usr/clang21/include -I/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/include--sysroot=/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot

CPPFLAGS are now:     -I/system/usr/include -I/system/usr/clang21/include -I/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/include

CXXFLAGS are now:     -I/system/usr/include -I/system/usr/clang21/include -I/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/include --target=aarch64-linux-android31

LDFLAGS are now:      -L/system/usr/lib -L/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/lib/clang/21/lib/linux/aarch64 -L/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/lib/aarch64-linux-android/31 -L/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/lib/aarch64-linux-android -B/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot/usr/lib/aarch64-linux-android/31 --sysroot=/system/usr/ndk/r29/toolchains/llvm/prebuilt/aarch64/sysroot -lc 

CLANG is now:        /system/usr/clang21/bin/clang
CC is now:           /system/usr/clang21/bin/clang
CXX is now:          /system/usr/clang21/bin/clang++
CPP is now:          /system/usr/clang21/bin/clang-cpp
CXXCPP is now:       /system/usr/clang21/bin/clang-cpp
AR is now:           /system/usr/clang21/bin/llvm-ar
AS is now:           /system/usr/clang21/bin/llvm-as
LD is now:           /system/usr/clang21/bin/lld
LLD is now:          /system/usr/clang21/bin/lld
RANLIB is now:       /system/usr/clang21/bin/llvm-ranlib
STRIP is now:        /system/usr/clang21/bin/llvm-strip
PKG_CONFIG is now:   /system/usr/clang21/utils/bin/pkg-config

Checking the clang binary ...

clang version 21.0.0git (https://android.googlesource.com/toolchain/llvm-project 37f38d1f3276b62fba09462ab4807dce846c732d)
Target: aarch64-unknown-linux-android
Thread model: posix
InstalledDir: /system/usr/clang21/bin

Defining some aliases ...
vi=/system/usr/bin/vi
find=/system/usr/bin/find
tar=/system/usr/bin/tar
bash=/system/usr/bin/bash
sed=/system/usr/bin/sed
awk=/system/usr/bin/awk
dd=/system/usr/bin/dd
nano=/system/usr/bin/nano
[clang21 toolchain] ASUS_I006D:/ $
                                                                                                                                                                



This command must be done once in each adb or ssh session.


The script /system/bin/init_clang21_env executes the script /system/bin/prepare_clang21_environment to prepare the clang21 toolchain environment (this script is only executed once for each user).

The script /system/bin/prepare_clang21_environment creates the necessary directories and files in /data/local/tmp/home if they do not yet exist.
 

The script init_clang21_env sets some environment variables, if they are not already defined:

Environment variable
Default Value
Comment
HOME
/data/local/tmp/home/$( id -un )
the variable is also set to the default value if the value is "/"

The home directory is created by the script prepare_clang21_environment if it does not yet exist
TMPDIR
/data/local/tmp

TERMINFO
/system/etc/terminfo
the terminfo database is part of the virtual disk
TERM
vt100

SSL_CERT_DIR
/system/etc/security/cacerts

SSL_CERT_FILE
/data/local/tmp/home/ca-certificates.crt
This file is created by the script prepare_clang21_environment

If the file does not exist the script uses the file

/system/etc/security/ca-certificates.crt

(That file is part of the virtual disk)
CLANG_VERSION
21

CLANG_DIR
/system/usr/clang${CLANG_VERSION}

NDK_VERSION
r29

NDK_DIR
/system/usr/ndk/${NDK_VERSION]

SYSROOT
/system/usr/ndk/${NDK_VERSION]/toolchains/llvm/prebuilt/aarch64/sysroot

API
31

CPU_TYPE
uname -m

TARGET_ROOT
/data/local/tmp/develop/sysroot
this variable can be used for the parameter "--prefix" for the configure scripts.

The environment variable is only defined if the directory exists (the directory is not created by the script)
CFLAGS, CPPFLAGS, CXXFLAGS, LDFLAGS
mandatory values for using the clang compiler





The script also sets the environment variables

CC, CXX, CPP, CXXPP, AR, AS, LD, RANLIB, STRIP, PKG_CONFIG

with the fully qualified names of the clang binaries.

Note that it's important to use the environment variables CFLAGS or CXXFLAGS and LDFLAGS to compile a binary or library using the clang21 toolchain.
Most configure scripts for Unix programs use the values of these variables when they are set. To invoke clang manually, always use this syntax

# to compile a C program
#
clang $CFLAGS $LDFLAGS <your parameter>

or

# to compile a C++ program
#
clang $CXXFLAGS $LDFLAGS <your parameter>


The necessary files to compile binaries for arm64 CPUs from the Android NDK are in the directory /system/usr/ndk/r29.


The virtual disk also contains some libraries in the directory /system/usr/lib (including the necessary header files in the directory /system/usr/include)


If a file is missing, just copy it to /system/bin or another sub directory in /system. All new files copied to one of these directories are saved in the virtual disk and will therefor survive a reboot (dito for file changes in /system)

To test the compiler use these commands:

[clang21 toolchain] ASUS_I006D:/data/local/tmp/home/shell $ cd /system/usr/share/examples/
[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $

[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $ b
total 16
-rw-r--r-- 1 system root 586 2025-10-19 12:05 helloworld_in_assembler.s
-rw-r--r-- 1 system root 608 2025-10-19 12:05 helloworld_in_assembler_for_as.s
-rw-r--r-- 1 system root 774 2025-10-19 12:05 helloworld_in_c++.cpp
-rw-r--r-- 1 system root 398 2025-10-19 12:05 helloworld_in_c.c
[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $

[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $ clang ${CFLAGS} ${LDFLAGS} -o /data/local/tmp/helloworld_in_c helloworld_in_c.c  && /data/local/tmp/helloworld_in_c
Hello, World from a C program!
Compiled with Clang 21.0.0
[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $

[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $ clang++ ${CXXFLAGS} ${LDFLAGS}  -o /data/local/tmp/helloworld_in_c++ ./helloworld_in_c++.cpp && /data/local/tmp//helloworld_in_c++
Hello, World from a C++ program!
Compiled with Clang 21.0.0
Compiler version: Clang 21.0.0git (https://android.googlesource.com/toolchain/llvm-project 37f38d1f3276b62fba09462ab4807dce846c732d)
[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $

[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $ clang -nostdlib -static -Wl,--entry=_start -o /data/local/tmp/helloworld_in_assembler helloworld_in_assembler.s && /data/local/tmp//helloworld_in_assembler                                                  
Hello, World from an assembler program compiled with clang!
[clang21 toolchain] ASUS_I006D:/system/usr/share/examples $


Another test : Download and compile the editor nano:

# init the clang21 toolchain environment if not done yet
#
source /system/bin/init_clang21_env


cd /data/local/tmp


wget https://www.nano-editor.org/dist/v8/nano-8.6.tar.gz
tar -xf nano-8.6.tar.gz    
cd nano-8.6

CFLAGS="$CFLAGS -Wno-implicit-function-declaration -Wno-int-conversion -DGNULIB_LIBPOSIX"

LDFLAGS="$LDFLAGS -static"

./configure --prefix=/system --disable-nls

make -j$( nproc )


The compiled nano binary is then in the directory ./src, e.g:

ASUS_I006D:/data/local/tmp/nano-8.6 # ls -ltr src/nano
-rwxr-xr-x 1 root root 3329704 2025-10-19 13:35 src/nano
ASUS_I006D:/data/local/tmp/nano-8.6 #

ASUS_I006D:/data/local/tmp/nano-8.6 # file src/nano
src/nano: ELF executable, 64-bit LSB arm64, static, for Android 31, built by NDK r29 (14206865), not stripped
ASUS_I006D:/data/local/tmp/nano-8.6 #

ASUS_I006D:/data/local/tmp/nano-8.6 # src/nano --version
 GNU nano, version 8.6
 (C) 2025 the Free Software Foundation and various contributors
 Compiled options: --disable-libmagic --disable-nls --enable-utf8
ASUS_I006D:/data/local/tmp/nano-8.6 #


To replace the nano binary in the virtual disk become root user and copy the new nano binary to /system/bin:

cp src/nano /system/bin/nano

or execute as user root:

make install

to install nano.


Configuration Details

The home directory for the user using the clang21 toolchain is

/data/local/tmp/home/$( id -un )

This directory is created by the script /system/bin/prepare_clang21_environment if it does not yet exist.

The SSL certificate bundle file used by wget, curl, and git is /data/local/tmp/home/ca-certificates.crt; this file is generated using the certificates in /system/etc/security/cacerts by the script /system/bin/prepare_clang21_environment if it does not yet exist.

The host key files for OpenSSH are in the directory /data/local/tmp/.ssh. The script /system/bin/prepare_clang21_environment creates this directory and the host key files if they do not yet exist
The authorized_keys file for OpenSSH is /data/local/tmp/.ssh/authorized_keys; this file must be created by the user with the used public ssh keys (ssh connections with password authentication are not supported)

See here for the documenation for the NFS Server unfsd.

See here for the documentation for OpenSSH.

See here for the documentation for OpenVPN.

see here for the documentation for a Magisk Module with clang21 and the Android NDK r29





Virtual disk with a clang19 toolchain


(see also https://xdaforums.com/t/using-a-virtual-disk-with-a-clang19-toolchain-for-an-overlay-mount.4749365/)

I have created a virtual disk image with a clang19 toolchain that can be used for testing.


Notes

This virtual disk is only a prove of concept. I did not do indepth tests and I do not plan to update the image on a a regular base.

Be aware that compressed file with the disk image is about 520 MB; the uncompressed file with the virtual disk occupies 2,1 GB diskspace. There is about 500 MB free space in the virtual disk.


To use the virtual disk use these commands:


Download the file with the virtual disk image to the PC

wget http://bnsmb.de/files/public/Android/clang19_virtual_image.gz


Copy the file clang19_virtual_image.gz to the phone

adb push clang19_virtual_image.gz /sdcard/Download


and uncompress it:

adb shell gzip -d /sdcard/Download/clang19_virtual_image.gz



Then open an adb shell on the phone, become root user, and configure the virtual disk as overlay filesystem for the directory /system:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang19_virtual_image /system

(This command must be done once after each reboot of the phone to use the overlay filesystem)


Example:

/data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang19_virtual_image  /system
ASUS_I006D:/ # /data/local/tmp/create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/clang19_virtual_image  /system
The image file "/sdcard/Download/clang19_virtual_image" already exists - there should already be a filesystem
Creating the directory "/dev/ov" ...
Mounting the imagefile "/sdcard/Download/clang19_virtual_image" to "/dev/ov" ...

Creating and mounting the directories for the overlay mount for "/system" ...
Creating the overlay mount for "/system" ...
Creating the bind mount "/system"...
Checking the overlay mount for "/system" ...

Summary:
--------

1 overlay mount(s) created:

  /system

ASUS_I006D:/ #



Now the directory /system is writable:

ASUS_I006D:/ # touch /system/xxx.$$$
ASUS_I006D:/ #

ASUS_I006D:/ # ls -l /system/xxx.$$$
-rw-r--r-- 1 root root 0 2025-07-09 20:00 /system/xxx.4975$
ASUS_I006D:/ #


To use the clang19 toolchain from the virtual disk, init the toolchain with the command:

source /system/bin/init_clang19_env

(this command must be done once in each adb session using the clang toolchain)


Example:

source /system/bin/init_clang19_env
ASUS_I006D:/ # source /system/bin/init_clang19_env

Preparing the clang environment for creating binaries for the CPU type aarch64
The target root directory /data/local/tmp/develop/sysroot does not exist

Using clang 19                                                                            
Using the NDK /system/usr/ndk/r27b                                                         (environment variable NDK_DIR)
Using the sysroot directory /system/usr/ndk/r27b/sysroot                                   (environment variable SYSROOT)
Using the target root directory /data/local/tmp/develop/sysroot                            (environment variable TARGET_ROOT)


Environment variables used:


PATH is now:         /system/usr/clang19/bin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin

LD_LIBRARY_PATH:     :/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/:/system/usr/clang19/lib:/system/usr/lib

API is now:          31
NDK_DIR is now:      /system/usr/ndk/r27b

SYSROOT is now:      /system/usr/ndk/r27b/sysroot

CFLAGS are now:       -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include --sysroot=/system/usr/ndk/r27b/sysroot

CPPFLAGS are now:     -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include

CXXFLAGS are now:     -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include --sysroot=/system/usr/ndk/r27b/sysroot

LDFLAGS are now:      -L/system/usr/lib -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/31 -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android -B/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/31/ --sysroot=/system/usr/ndk/r27b/sysroot -lc
CC is now:           /system/usr/clang19/bin/clang
CXX is now:          /system/usr/clang19/bin/clang++
CPP is now:          /system/usr/clang19/bin/clang-cpp
CXXCPP is now:       /system/usr/clang19/bin/clang-cpp
AR is now:           /system/usr/clang19/bin/llvm-ar
AS is now:           /system/usr/clang19/bin/llvm-as
LD is now:           /system/usr/clang19/bin/lld
RANLIB is now:       /system/usr/clang19/bin/llvm-ranlib
STRIP is now:        /system/usr/clang19/bin/llvm-strip
PKG_CONFIG is now:   /system/usr/clang19/bin/pkg-config

Checking the clang binary ...

clang version 19.0.0git (https://android.googlesource.com/toolchain/llvm-project b3a530ec6537146650e42be89f1089e9a3588460)
Target: aarch64-unknown-linux-android
Thread model: posix
InstalledDir: /system/usr/clang19/bin

Define some aliase ...
[1752086863.227690] alias 'setlibpath=export LD_LIBRARY_PATH=:/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/:/system/usr/clang19/lib:/system/usr/lib'
[1752086863.227904] alias 'cp_crt_libs=cp ${NDK_DIR}/sysroot/usr/lib/${CPU_TYPE}-linux-android/${API}/crt*.o .'
[1752086863.228071] alias 'make_fast=make -j$( nproc )'
[1752086863.228231] alias 'cc=/system/usr/clang19/bin/clang'
[1752086863.228371] set +x
ASUS_I006D:/ #



 
(This command must be done once in each adb or ssh session)


Now you can use the tools from the clang19 toolchain to compile C, C++, and assembler source files on the phone.

Installed in the overlay filesystem on the virtual disk are most of the tools from the clang19 toolchain for installation in /data/local/tmp/sysroot -- see the GitHub repository with the clang19 toolchain :

https://github.com/bnsmb/clang19_toolchain_for_android 

The virtual disk also contains a lot of pre-compiled libraries in the directory /system/usr/lib (including the necessary header files in the directory /system/usr/include) and the necessary files to compile binaries for arm64 CPUs from the Android NDK in the directory. /system/usr/ndk/r27b.


If a file is missing, just copy it to /system/bin or another sub directory in /system. All new files copied to one of these directories are saved in the virtual disk and will therefor survive a reboot (dito for files changes in /system)

To test the compiler use these commands:


ASUS_I006D:/ # cd /system/usr/share/examples
ASUS_I006D:/system/usr/share/examples #

ASUS_I006D:/system/usr/share/examples # clang ${CFLAGS} ${LDFLAGS} -o helloworld_in_c helloworld_in_c.c  && ./helloworld_in_c
Hello, World from a C program!
Compiled with Clang 19.0.0
ASUS_I006D:/system/usr/share/examples #

ASUS_I006D:/system/usr/share/examples # clang++ ${CXXFLAGS} ${LDFLAGS}  -o helloworld_in_c++ ./helloworld_in_c++.cpp && ./helloworld_in_c++

Hello, World from a C++ program!
Compiled with Clang 19.0.0
Compiler version: Clang 19.0.0git (https://android.googlesource.com/toolchain/llvm-project b3a530ec6537146650e42be89f1089e9a3588460)
ASUS_I006D:/system/usr/share/examples #

ASUS_I006D:/system/usr/share/examples # clang -nostdlib -static -Wl,--entry=_start -o helloworld_in_assembler helloworld_in_assembler.s && ./helloworld_in_assembler
Hello, World from an assembler program compiled with clang!
ASUS_I006D:/system/usr/share/examples #
ASUS_I006D:/system/usr/share/examples #


Another test : Download and compile the editor nano:

source /system/bin/init_clang19_env

cd /data/local/tmp


wget https://www.nano-editor.org/dist/v8/nano-8.5.tar.gz
tar -xf nano-8.5.tar.gz    
cd nano-8.5

CFLAGS="$CFLAGS -Wno-implicit-function-declaration -Wno-int-conversion -DGNULIB_LIBPOSIX"

LDFLAGS="$LDFLAGS -static"

./configure --prefix=/system --disable-nls --enable-utf8

make -j$( nproc )


The compiled nano binary is then in the directory src, e.g:


ASUS_I006D:/data/local/tmp/develop/nano-8.5 $ ls -ltr src/nano
-rwxrwxrwx 1 shell shell 3394288 2025-07-11 13:51 src/nano
ASUS_I006D:/data/local/tmp/develop/nano-8.5 $

ASUS_I006D:/data/local/tmp/develop/nano-8.5 $ file  src/nano
src/nano: ELF executable, 64-bit LSB arm64, static, for Android 31, built by NDK r27b (12297006), not stripped
ASUS_I006D:/data/local/tmp/develop/nano-8.5 $

ASUS_I006D:/data/local/tmp/develop/nano-8.5 $   src/nano --version 
 GNU nano, version 8.5
 (C) 2025 the Free Software Foundation and various contributors
 Compiled options: --disable-libmagic --disable-nls --enable-utf8
ASUS_I006D:/data/local/tmp/develop/nano-8.5 $


To replace the nano binary in the virtual disk just copy the new nano binary to /system/bin:

cp src/nano /system/bin/nano




Virtual disk with Perl 5.42 and a minimal clang19 toolchain


(see also https://xdaforums.com/t/using-a-virtual-disk-with-perl-5-42-and-a-minimal-clang19-toolchain-for-an-overlay-mount.4749262/)

I have created a virtual disk with Perl 5.42, a minimal clang19 toolchain, vim, nano and wget2 for arm64 CPUs that can be used to compile new Perl modules on the phone:

http://bnsmb.de/files/public/Android/perl542_and_clang_virtual_image.gz


Notes

This virtual disk is only a prove of concept. I did not do indepth tests and I do not plan to update the image on a a regular base.

The size of the compressed image is about 270 MB; the uncompressed virtual disk occupies 1 GB space and there are about 115 MB free space in the virtual disk.


To use the virtual disk, download the file with the virtual disk to the PC

wget http://bnsmb.de/files/public/Android/perl542_and_clang_virtual_image.gz


Copy the file to the phone

adb push perl542_and_clang_virtual_image.gz /sdcard/Download/perl542_and_clang_virtual_image.gz


uncompress it on the phone

adb shell gzip -d /sdcard/Download/perl542_and_clang_virtual_image.gz



and execute as user root in an adb shell

create_overlay_mount.sh IMAGE_FILE=/sdcard/Download/perl542_and_clang_virtual_image  /system

This command must be executed once after each reboot because overlay mounts are not persistent (-> if somethings goes wrong after creating the overlay mount just reboot the phone and you're back in buisness)


To use the clang19 from the virtual disk in an adb shell, execute this command

source /system/bin/init_clang19_env ex


Notes:


This command must be executed once in each adb session using the clang toolchain.

The parameter "ex" for init_clang19_env is optional -- the only purpose of this parameter is to print the commands to test the compiler.


Before using cpan to install perl modules, create the home directory if it does not yet exist (see also the notes below)

mkdir -p /data/local/tmp/perl_home


To test the image, install a simple Perl module like for example Scalar::Util using cpan:

cpan install Scalar::Util

cpan install
 

ASUS_I006D:/ $

# init the clang19 environment
#
ASUS_I006D:/ $ source /system/bin/init_clang19_env

Preparing the clang environment for creating binaries for the CPU type aarch64
The target root directory /data/local/tmp/develop/sysroot does not exist

Using clang 19                                                                            
Using the NDK /system/usr/ndk/r27b                                                         (environment variable NDK_DIR)
Using the sysroot directory /system/usr/ndk/r27b/sysroot                                   (environment variable SYSROOT)
Using the target root directory /data/local/tmp/develop/sysroot                            (environment variable TARGET_ROOT)


Environment variables used:


PATH is now:         /system/usr/bin:/system/usr/clang19/bin:/product/bin:/apex/com.android.runtime/bin:/apex/com.android.art/bin:/system_ext/bin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin

LD_LIBRARY_PATH:     :/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/:/system/usr/clang19/lib:/system/usr/lib

API is now:          31
NDK_DIR is now:      /system/usr/ndk/r27b

SYSROOT is now:      /system/usr/ndk/r27b/sysroot

CFLAGS are now:       -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include --sysroot=/system/usr/ndk/r27b/sysroot

CPPFLAGS are now:     -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include

CXXFLAGS are now:     -I/system/usr/clang19/include -I/system/usr/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include --sysroot=/system/usr/ndk/r27b/sysroot

LDFLAGS are now:      -L/system/usr/lib -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/31 -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android -B/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/31/ --sysroot=/system/usr/ndk/r27b/sysroot -lc
CC is now:           /system/usr/clang19/bin/clang
CXX is now:          /system/usr/clang19/bin/clang++
CPP is now:          /system/usr/clang19/bin/clang-cpp
CXXCPP is now:       /system/usr/clang19/bin/clang-cpp
AR is now:           /system/usr/clang19/bin/llvm-ar
AS is now:           /system/usr/clang19/bin/llvm-as
LD is now:           /system/usr/clang19/bin/lld
RANLIB is now:       /system/usr/clang19/bin/llvm-ranlib
STRIP is now:        /system/usr/clang19/bin/llvm-strip
PKG_CONFIG is now:   /system/usr/clang19/bin/pkg-config

Checking the clang binary ...

clang version 19.0.0git (https://android.googlesource.com/toolchain/llvm-project b3a530ec6537146650e42be89f1089e9a3588460)
Target: aarch64-unknown-linux-android
Thread model: posix
InstalledDir: /system/usr/clang19/bin

Define some aliase ...
[1752212875.848172] alias 'setlibpath=export LD_LIBRARY_PATH=:/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/:/system/usr/clang19/lib:/system/usr/lib'
[1752212875.848379] alias 'cp_crt_libs=cp ${NDK_DIR}/sysroot/usr/lib/${CPU_TYPE}-linux-android/${API}/crt*.o .'
[1752212875.848569] alias 'make_fast=make -j$( nproc )'
[1752212875.848735] alias 'cc=/system/usr/clang19/bin/clang'
[1752212875.848905] set +x
ASUS_I006D:/ $
ASUS_I006D:/ $

ASUS_I006D:/ $ cpan install Scalar::Util
Loading internal logger. Log::Log4perl recommended for better logging

CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.

Would you like to configure as much as possible automatically? [yes]

Trying with
    /system/bin/wget -O "/data/local/tmp/perl_home/.cpan/sources/authors/01mailrc.txt.gz.tmp5308"
to get
    https://cpan.org/authors/01mailrc.txt.gz
HTTP response 301  [https://cpan.org/authors/01mailrc.txt.gz]
Adding URL: https://www.cpan.org/authors/01mailrc.txt.gz
Saving '/data/local/tmp/perl_home/.cpan/sources/authors/01mailrc.txt.gz.tmp5308'
HTTP response 200  [https://www.cpan.org/authors/01mailrc.txt.gz]
/data/local/tmp/perl 100% [============================================================================================================>]  243.98K  149.99KB/s
                          [Files: 1  Bytes: 243.98K [96.70KB/s] Redirects: 1  Todo: 0  Errors: 0                                        ]
Reading '/data/local/tmp/perl_home/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE

Trying with
    /system/bin/wget -O "/data/local/tmp/perl_home/.cpan/sources/modules/02packages.details.txt.gz.tmp5308"
to get
    https://cpan.org/modules/02packages.details.txt.gz
HTTP response 301  [https://cpan.org/modules/02packages.details.txt.gz]
Adding URL: https://www.cpan.org/modules/02packages.details.txt.gz
Saving '/data/local/tmp/perl_home/.cpan/sources/modules/02packages.details.txt.gz.tmp5308'
HTTP response 200  [https://www.cpan.org/modules/02packages.details.txt.gz]
/data/local/tmp/perl 100% [============================================================================================================>]    2.45M  155.90KB/s
                          [Files: 1  Bytes: 2.45M [155.11KB/s] Redirects: 1  Todo: 0  Errors: 0                                         ]
Reading '/data/local/tmp/perl_home/.cpan/sources/modules/02packages.details.txt.gz'
  Database was generated on Thu, 10 Jul 2025 23:29:02 GMT
  HTTP::Date not available
............................................................................DONE

Trying with
    /system/bin/wget -O "/data/local/tmp/perl_home/.cpan/sources/modules/03modlist.data.gz.tmp5308"
to get
    https://cpan.org/modules/03modlist.data.gz
HTTP response 301  [https://cpan.org/modules/03modlist.data.gz]
Adding URL: https://www.cpan.org/modules/03modlist.data.gz
Saving '/data/local/tmp/perl_home/.cpan/sources/modules/03modlist.data.gz.tmp5308'
HTTP response 200  [https://www.cpan.org/modules/03modlist.data.gz]
/data/local/tmp/perl 100% [============================================================================================================>]     248     --.-KB/s
                          [Files: 1  Bytes: 248  [928 B/s] Redirects: 1  Todo: 0  Errors: 0                                             ]
Reading '/data/local/tmp/perl_home/.cpan/sources/modules/03modlist.data.gz'
DONE
Writing /data/local/tmp/perl_home/.cpan/Metadata
Running install for module 'Scalar::Util'

Trying with
    /system/bin/wget -O "/data/local/tmp/perl_home/.cpan/sources/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz.tmp5308"
to get
    https://cpan.org/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz
HTTP response 301  [https://cpan.org/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz]
Adding URL: https://www.cpan.org/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz
Saving '/data/local/tmp/perl_home/.cpan/sources/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz.tmp5308'
HTTP response 200  [https://www.cpan.org/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz]
/data/local/tmp/perl 100% [============================================================================================================>]  177.18K  192.67KB/s
                          [Files: 1  Bytes: 177.18K [123.47KB/s] Redirects: 1  Todo: 0  Errors: 0                                       ]

Trying with
    /system/bin/wget -O "/data/local/tmp/perl_home/.cpan/sources/authors/id/P/PE/PEVANS/CHECKSUMS.tmp5308"
to get
    https://cpan.org/authors/id/P/PE/PEVANS/CHECKSUMS
HTTP response 301  [https://cpan.org/authors/id/P/PE/PEVANS/CHECKSUMS]
Adding URL: https://www.cpan.org/authors/id/P/PE/PEVANS/CHECKSUMS
Saving '/data/local/tmp/perl_home/.cpan/sources/authors/id/P/PE/PEVANS/CHECKSUMS.tmp5308'
HTTP response 200  [https://www.cpan.org/authors/id/P/PE/PEVANS/CHECKSUMS]
/data/local/tmp/perl 100% [============================================================================================================>]  452.19K  155.75KB/s
                          [Files: 1  Bytes: 452.19K [137.40KB/s] Redirects: 1  Todo: 0  Errors: 0                                       ]
Checksum for /data/local/tmp/perl_home/.cpan/sources/authors/id/P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz with Makefile.PL
Checking if your kit is complete...
Looks good
Unrecognized argument in LIBS ignored: '/data/local/tmp/develop/sysroot/usr/lib/libcrypt.a'
Generating a Unix-style Makefile
Writing Makefile for List::Util
Writing MYMETA.yml and MYMETA.json
  PEVANS/Scalar-List-Utils-1.69.tar.gz
  /system/usr/bin/perl Makefile.PL -- OK
Running make for P/PE/PEVANS/Scalar-List-Utils-1.69.tar.gz
cp lib/List/Util.pm blib/lib/List/Util.pm
cp lib/Scalar/List/Utils.pm blib/lib/Scalar/List/Utils.pm
cp lib/Sub/Util.pm blib/lib/Sub/Util.pm
cp lib/Scalar/Util.pm blib/lib/Scalar/Util.pm
cp lib/List/Util/XS.pm blib/lib/List/Util/XS.pm
Running Mkbootstrap for Util ()
chmod 644 "Util.bs"
"/system/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
"/system/usr/bin/perl" "/system/usr/lib/perl5/5.42.0/ExtUtils/xsubpp"  -typemap '/system/usr/lib/perl5/5.42.0/ExtUtils/typemap'  ListUtil.xs > ListUtil.xsc
mv ListUtil.xsc ListUtil.c
cc -c   -fPIE -fPIC -pie --std=gnu99 --sysroot=/system/usr/ndk/r27b/sysroot -I/system/usr/clang19/include -I/system/usr/ndk/r27b/include -I/system/usr/ndk/r27b/sysroot/usr/include -I/data/local/tmp/develop/sysroot/usr/include --sysroot=/system/usr/ndk/r27b/sysroot -Wno-implicit-function-declaration -Wno-int-conversion -DHAS_SHMAT_PROTOTYPE -DNO_LOCALE -DNO_LOCALE_CTYPE -DNO_LOCALE_NUMERIC -DNO_LOCALE_COLLATE -DNO_LOCALE_TIME -DNO_LOCALE_MESSAGES -DNO_LOCALE_MONETARY -DNO_LOCALE_ADDRESS -DNO_LOCALE_IDENTIFICATION -DNO_LOCALE_MEASUREMENT -DNO_LOCALE_PAPER -DNO_LOCALE_TELEPHONE -DNO_LOCALE_NAME -DNO_LOCALE_SYNTAX -DNO_LOCALE_TOD -fPIC -O2   -DVERSION=\"1.69\" -DXS_VERSION=\"1.69\" -fPIC --sysroot=/system/usr/ndk/r27b/sysroot -B/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android//31 "-I/system/usr/lib/perl5/5.42.0/aarch64-linux-android/CORE"  -DPERL_EXT -DUSE_PPPORT_H ListUtil.c
cc: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
In file included from ListUtil.xs:8:
In file included from /system/usr/lib/perl5/5.42.0/aarch64-linux-android/CORE/perl.h:46:
/system/usr/lib/perl5/5.42.0/aarch64-linux-android/CORE/config.h:1906:9: warning: 'HAS_SHMAT_PROTOTYPE' macro redefined [-Wmacro-redefined]
 1906 | #define HAS_SHMAT_PROTOTYPE     /**/
      |         ^
<command line>:1:9: note: previous definition is here
    1 | #define HAS_SHMAT_PROTOTYPE 1
      |         ^
1 warning generated.
rm -f blib/arch/auto/List/Util/PL_List__Util.so
cc  -shared -O2 --sysroot=/system/usr/ndk/r27b/sysroot -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/31 -L/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android -L/data/local/tmp/develop/sysroot/usr/lib -fPIC --sysroot=/system/usr/ndk/r27b/sysroot -B/system/usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android//31 --sysroot=/system/usr/ndk/r27b/sysroot  ListUtil.o  -o blib/arch/auto/List/Util/PL_List__Util.so  \
   -ldl -lm -lc   \
 
chmod 755 blib/arch/auto/List/Util/PL_List__Util.so
  PEVANS/Scalar-List-Utils-1.69.tar.gz
  /system/usr/clang19/bin/make -- OK
The current configuration of allow_installing_outdated_dists is 'ask/no', but for this option we would need 'CPAN::DistnameInfo' installed. Please install 'CPAN::DistnameInfo' as soon as possible. As long as we are not equipped with 'CPAN::DistnameInfo' this option does not take effect
Running make test for PEVANS/Scalar-List-Utils-1.69.tar.gz
"/system/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
PERL_DL_NONLAZY=1 "/system/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/00version.t ......... ok  
t/any-all.t ........... ok    
t/blessed.t ........... ok    
t/dualvar.t ........... ok    
t/exotic_names.t ...... ok        
t/first.t ............. ok    
t/getmagic-once.t ..... ok  
t/head-tail.t ......... ok    
t/isvstring.t ......... ok  
t/lln.t ............... ok    
t/max.t ............... ok    
t/maxstr.t ............ ok  
t/mesh.t .............. ok  
t/min.t ............... ok    
t/minstr.t ............ ok  
t/openhan.t ........... ok    
t/pair.t .............. ok    
t/product.t ........... ok    
t/prototype.t ......... ok    
t/readonly.t .......... ok    
t/reduce.t ............ ok    
t/reductions.t ........ ok  
t/refaddr.t ........... ok    
t/reftype.t ........... ok    
t/rt-96343.t .......... ok  
t/sample.t ............ ok  
t/scalarutil-proto.t .. ok    
t/shuffle.t ........... ok  
t/stack-corruption.t .. ok  
t/subname.t ........... ok    
t/sum.t ............... ok    
t/sum0.t .............. ok  
t/tainted.t ........... ok  
t/undefined-block.t ... ok    
t/uniq.t .............. ok    
t/uniqnum.t ........... ok    
t/weak.t .............. ok    
t/zip.t ............... ok  
All tests successful.
Files=38, Tests=2160,  4 wallclock secs ( 0.46 usr  0.14 sys +  2.69 cusr  0.89 csys =  4.18 CPU)
Result: PASS
  PEVANS/Scalar-List-Utils-1.69.tar.gz
  /system/usr/clang19/bin/make test -- OK
Running make install for PEVANS/Scalar-List-Utils-1.69.tar.gz
"/system/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Util.bs blib/arch/auto/List/Util/Util.bs 644
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/auto/List/Util/PL_List__Util.so
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/List/Util.pm
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/List/Util/XS.pm
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/Scalar/Util.pm
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/Scalar/List/Utils.pm
Installing /data/local/tmp/perl_home/lib/perl5/aarch64-android/Sub/Util.pm
Appending installation info to /data/local/tmp/perl_home/lib/perl5/aarch64-android/perllocal.pod
  PEVANS/Scalar-List-Utils-1.69.tar.gz
  /system/usr/clang19/bin/make install  -- OK
ASUS_I006D:/ $

ASUS_I006D:/ $ ls -l /data/local/tmp/perl_home/lib/perl5/aarch64-android/
total 16
drwxr-xr-x 3 shell shell 3452 2025-07-11 07:48 List
drwxr-xr-x 3 shell shell 3452 2025-07-11 07:48 Scalar
drwxr-xr-x 2 shell shell 3452 2025-07-11 07:48 Sub
drwxr-xr-x 3 shell shell 3452 2025-07-11 07:48 auto
-rw-rw-rw- 1 shell shell  233 2025-07-11 07:48 perllocal.pod
ASUS_I006D:/ $


----


All perl executables in the virtual disk use a wrapper script:

ASUS_I006D:/ # cat /system/bin/perl_env ^C                                                                                                                                                                          
130|ASUS_I006D:/ # ls -l /system/bin  | grep perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 cpan -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 instmodsh -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perl -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perl5.42.0 -> ./perl_wrapper
-rwxr-xr-x 1 root root       241 2025-07-10 07:13 perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perlbug -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perldoc -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perlivp -> ./perl_wrapper
lrwxrwxrwx 1 root root        14 2025-07-10 07:13 perlthanks -> ./perl_wrapper
ASUS_I006D:/ #


The wrapper script perl_wrapper reads and executes the file /system/bin/perl_env to init the perl environment before executing the "real" perl executable.

The script /system/bin/perl_env uses the home directory /data/local/tmp/perl_home. To change this, edit the file /system/bin/perl_env or set the environment variable HOME to another existing directory before executing cpan or any other perl executable.

Perl modules installed via cpan will be installed in the directory ${HOME}/perl5/lib. To change this behaviour, edit the environment variables in the file /system/bin/perl_env.

Note also that the script /system/bin/perl_env reads and executes the file ${HOME}/perl_env if it exists

cat /system/bin/perl_env
ASUS_I006D:/system/usr/share/examples # cat /system/bin/perl_env

# LD_LIBRARY_PATH is not required for this Perl binary or the compiled perl modules
# export LD_LIBRARY_PATH=/system/usr/lib:${LD_LIBRARY_PATH}

PERL_HOME_DIR="/data/local/tmp/perl_home"

if [ "${HOME}"x = ""x -o "${HOME}"x = "/"x ] ; then
  export HOME="${PERL_HOME_DIR}"
else
  PERL_HOME_DIR="${HOME}"
fi

export PERL5LIB="${PERL_HOME_DIR}/lib/perl5:/system/usr/lib/perl5/5.42.0"

export PERL_LOCAL_LIB_ROOT="${PERL_HOME_DIR}"

export PERL_MB_OPT="--install_base ${PERL_HOME_DIR}"
export PERL_MM_OPT="INSTALL_BASE=${PERL_HOME_DIR}"

USER_DEFINED_PERL_INIT_FILE="${PERL_HOME_DIR}/perl_env"

if [ -r "${USER_DEFINED_PERL_INIT_FILE}" ] ; then
  echo "${USER_DEFINED_PERL_INIT_FILE} found - now executing it ..."
  echo
  source "${USER_DEFINED_PERL_INIT_FILE}"
fi

ASUS_I006D:/system/usr/share/examples #

----

No root access is required to run cpan to install new Perl modules as long as the user running cpan has write access to the home directory.

 


Test Environment



ASUS Zenfone 8 with

ASUS Android 13 Beta for ASUS Zenfone 8
ASUS Android 13 for ASUS Zenfone 8
/e/ 3.5
(= Android 15)
/e/ 4.x (= Android 16)
LineageOS 20 (= Android 13)
LineageOS 21 (= Android 14)
LineageOS 22 (= Android 15)
StatixOS v7.10
(= Android 14)
OmniROM 14 (= Android 14)
OmniROM 15 (= Android 15)
OmniROM 16 (= Android 16)

Note:

According to ChatGPT the overlay mount functionality does not work on all Android versions (but ChatGTP is sometimes also a great liar ...)



Limitations





Mounts to subdirectories on separate partitions (/dev/block/s*) such as /vendor/dsp in /vendor are remounted after the overlay mount has been created. Please note that there are NO overlay mounts for these mounts!

Example
ASUS_I006D:/data/local/tmp # df -h | grep " /vendor"
/dev/block/dm-4   1.1G 1.1G  3.5M 100% /vendor
/dev/block/sde4   220M 173M   47M  79% /vendor/firmware_mnt
/dev/block/sde9    59M  41M   18M  70% /vendor/dsp
/dev/block/sde5    64M 1.0M   63M   2% /vendor/bt_firmware
/dev/block/sda17  496M 404K  496M   1% /vendor/xrom
ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp #
/data/local/tmp/create_overlay_mount.sh  /vendor mount
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem

Creating and mounting the directories for the overlay mount for "/vendor" ...
Creating the overlay mount for "/vendor" ...
Creating the bind mount "/vendor"...
Remounting the mount point "/vendor/bt_firmware" ...
Remounting the mount point "/vendor/dsp" ...
Remounting the mount point "/vendor/firmware_mnt" ...
Remounting the mount point "/vendor/xrom" ...
Checking the overlay mount for "/vendor" ...

Summary:
--------

1 overlay mount(s) created:

  /vendor

ASUS_I006D:/data/local/tmp #


ASUS_I006D:/data/local/tmp # /data/local/tmp/create_overlay_mount.sh  /vendor umount
Umounting the bind mounts ...
Umounting the mounted sub directories ...
Umounting "/vendor/bt_firmware" ...
Umounting "/vendor/dsp" ...
Umounting "/vendor/firmware_mnt" ...
Umounting "/vendor/xrom" ...
Umounting the bind mount  "/vendor" ...
 ... done
Umounting the overlay mounts ...
Umounting "/dev/ov/merged/vendor" ...
 ... done

ASUS_I006D:/data/local/tmp #






The filesystems vfat does not support overlay mounts. The filesystem f2fs supports overlay mounts but only if the feature is implemented and configured in the kernel.
There maybe other filesystems also not supporting overlay mounts.

See How to use overlay mounts for directories in /data for an example for using create_overlay_mount.sh for a directory on a filesystem that does not support overlay mounts.



Trouble Shooting




create_overlay_mount.sh does not support directory names with a hash "#" in the name.




To check, if overlay filesystems are supported in the Android OS use the command:

grep overlay /proc/filesystems

The output should look like this:

ASUS_I006D:/data/local/tmp #  grep overlay /proc/filesystems
nodev    overlay
ASUS_I006D:/data/local/tmp #




create_overlay_mount.sh may fail with this error message:


ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh /product umount                                                                                                                                                                             

Executing a command as user "root" via "su -c " failed:
./create_overlay_mount.sh[297]: su: inaccessible or not found

ERROR: The script "./create_overlay_mount.sh" must be executed by the root user (the current user is "shell") (RC=250)
250|ASUS_I006D:/data/local/tmp $


In this case either there is no "su" command in the Android OS or, if Magisk is installed, a bind mount was created for the directory with the Magisk binaries. Therefor, the Magisk binaries, such as su, are not available via PATH anymore.

To workaround that error, start the script as user root or use the bind mounts for the Magisk binaries (only if Magisk is installed, of course):

# replace "/data/local/tmp/product/bin" with "/data/local/tmp/system/bin" if Magisk was installed in /system
#
ASUS_I006D:/data/local/tmp $ PATH=/data/local/tmp/product/bin:$PATH ./create_overlay_mount.sh /product umount /product                                                                                                                         
Umounting the bind mounts ...
Umounting the bind mount  "/product" ...
 ... done
Umounting the overlay mounts ...
Umounting "/dev/ov/merged/product" ...
 ... done

ASUS_I006D:/data/local/tmp $




An overlay mount for sub directories like /system_ext/bin or /system/etc may or may not work.

If it does not work, the files in the sub directory with overlay mount do not have any permission, example:

ASUS_I006D:/data/local/tmp # ls -ldZ /system_ext/bin/*
---------- 1 root root  u:object_r:unlabeled:s0   0 1970-01-04 04:35 /system_ext/bin/adb_root
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0  16 1970-01-04 04:35 /system_ext/bin/bash -> /system/bin/bash
---------- 1 root root  u:object_r:unlabeled:s0   0 1970-01-04 04:35 /system_ext/bin/dpmd
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/eview -> vim
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/evim -> vim
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/ex -> vim
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/gview -> vim
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/gvim -> vim
lrwxrwxrwx 1 root root  u:object_r:unlabeled:s0   3 1970-01-04 04:35 /system_ext/bin/gvimdiff -> vim
---------- 1 root root  u:object_r:unlabeled:s0   0 1970-01-04 04:35 /system_ext/bin/htop
---------- 1 root root  u:object_r:unlabeled:s0   0 1970-01-04 04:35 /system_ext/bin/nano
...

create_overlay_mount.sh prints a warning in this case, example:

WARNING: Seems like the overlay mount for "/system_ext/bin" works only partial -- please check the directory contents


To work around this problem, create an overlay mount for the upper directory (e.g. /system or /system_ext) -- at least in my tests, overlay mounts for these directories have always worked.






Umounting /system will fail in most cases due to open files, as the umount command uses libraries from /system/lib64. To "fix" this error, use a statically linked umount binary.

A statically linked umount binary for arm64 CPUs is available here: umount

Either add the statically linked umount binary to a directory in the PATH before /system/bin or set the environment variable UMOUNT before starting the script, e.g:

copy the statically linked umount to /data/local/tmp and execute:


UMOUNT=/data/local/tmp/umount  /data/local/tmp/create_overlay_mount.sh umount /system

or

/data/local/tmp/create_overlay_mount.sh umount /system UMOUNT=/data/local/tmp/umount


If the umount of /system still fails, use a statically linked shell instead of sh.
A statically linked bash binary for arm64 CPUs is available here: bash-static-stripped

Copy the statically linked bash binary to /data/local/tmp and use this command to umount /system:

UMOUNT=/data/local/tmp/umount /data/local/tmp/bash-static-stripped /data/local/tmp/create_overlay_mount.s umount /system


Example

ASUS_I006D:/ # UMOUNT=/data/local/tmp/umount  /data/local/tmp/bash-static-stripped   /data/local/tmp/create_overlay_mount.sh umount /system
Umounting the bind mounts ...
Umounting "/system" ...
 ... done

ASUS_I006D:/ #


It's recommended to change the shebang in the first line in the script create_overlay_mount.sh to use the statically linked bash binary, e.g

ASUS_I006D:/data/local/tmp # diff ./create_overlay_mount.sh.or  ./create_overlay_mount.sh.original
create_overlay_mount.sh.org          create_overlay_mount.sh.original
ASUS_I006D:/data/local/tmp # diff ./create_overlay_mount.sh.original   ./create_overlay_mount.sh                                                                                                                               
--- ./create_overlay_mount.sh.original    2025-06-23 14:38:23.000000000 +0200
+++ ./create_overlay_mount.sh    2025-06-23 14:59:15.979999758 +0200
@@ -1,4 +1,4 @@
-#!/system/bin/sh
+#!/data/local/tmp/bin/bash-static-stripped
 #
 #h#
 #h# create_overlay_mount.sh <VERSION> - create one or more overlay mounts on a device running a rooted Android OS
1|ASUS_I006D:/data/local/tmp #





If creating a overlay mount for /system be careful not to replace one of the symbolic links for toybox.

ls -l /system/bin | grep toybox
ASUS_I006D:/ $ ls -l /system/bin | grep toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 [ -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 acpi -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 base64 -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 basename -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 blkdiscard -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 blockdev -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 brctl -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cal -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cat -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chattr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chcon -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chgrp -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chmod -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chown -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chroot -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 chrt -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cksum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 clear -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cmp -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 comm -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cp -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cpio -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 cut -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 date -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 dd -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 devmem -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 df -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 diff -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 dirname -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 dmesg -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 dos2unix -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 du -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 echo -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 egrep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 env -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 expand -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 expr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 fallocate -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 false -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 fgrep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 file -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 find -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 flock -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 fmt -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 free -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 fsync -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 getconf -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 getenforce -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 getfattr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 getopt -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gpiodetect -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gpiofind -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gpioget -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gpioinfo -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gpioset -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 grep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 groups -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gunzip -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 gzip -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 head -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 hostname -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 hwclock -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 i2cdetect -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 i2cdump -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 i2cget -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 i2cset -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 i2ctransfer -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 iconv -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 id -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ifconfig -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 inotifyd -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 insmod -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 install -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ionice -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 iorenice -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 kill -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 killall -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ln -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 load_policy -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 log -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 logger -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 logname -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 losetup -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ls -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 lsattr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 lsmod -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 lsof -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 lspci -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 lsusb -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 md5sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 memeater -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 microcom -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mkdir -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mkfifo -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mknod -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mkswap -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mktemp -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 modinfo -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 more -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mount -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mountpoint -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 mv -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nc -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 netcat -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 netstat -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nice -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nl -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nohup -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nproc -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 nsenter -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 od -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 paste -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 patch -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 pgrep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 pidof -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 pkill -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 pmap -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 printenv -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 printf -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ps -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 pwd -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 readelf -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 readlink -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 realpath -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 renice -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 restorecon -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 rm -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 rmdir -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 rmmod -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 rtcwake -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 runcon -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sed -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sendevent -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 seq -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 setenforce -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 setfattr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 setsid -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sha1sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sha224sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sha256sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sha384sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sha512sum -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sleep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sort -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 split -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 stat -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 strings -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 stty -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 swapoff -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 swapon -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sync -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 sysctl -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tac -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tail -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tar -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 taskset -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tee -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 test -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 time -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 timeout -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 top -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 touch -> toybox
-rwxr-xr-x 1 root shell   566056 2009-01-01 01:00 toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tr -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 true -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 truncate -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 tty -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uclampset -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 ulimit -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 umount -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uname -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uniq -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 unix2dos -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 unlink -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 unshare -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uptime -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 usleep -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uudecode -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uuencode -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 uuidgen -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 vi -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 vmstat -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 watch -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 wc -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 which -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 whoami -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 xargs -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 xxd -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 yes -> toybox
lrwxrwxrwx 1 root shell        6 1970-02-13 10:11 zcat -> toybox
ASUS_I006D:/ $







Use the script parameter -v or --verbose to print more messages


Set the variable TRACE to any string before executing the script to run it with "set -x"



Most problems with overlay mounts are caused by missing or invalid SELinux contexts for the files and directories for which an overlay mount is configured. It is therefore recommended to
temporarily disable SELinux either by using the command

setenforce 0

or use the script parameter "--noselinux"

Start a parallel adb session with the command

logcat | grep denied

or, on the PC, :

adb logcat | grep denied

while testing the overlay mounts.




The original files in the directories with overlay mounts are available in the directory

${BASEDIR}/rootfs/<directory_with_overlay_mounts>


Examples
ASUS_I006D:/data/local/tmp $ ./create_overlay_mount.sh list    
Directories mounted on an overlay filesystem

/system_ext/etc/nano
/system_ext/bin
/system_ext/usr/share
/data/local/tmp/sysroot/etc
/data/local/tmp/sysroot/usr/bin


ASUS_I006D:/data/local/tmp $ ls -l /dev/ov/rootfs/system_ext/etc/nano/ | head -5
total 196
-rw-r--r-- 1 root root  873 2009-01-01 01:00 Makefile.am
-rw-r--r-- 1 root root 1263 2009-01-01 01:00 ada.nanorc
-rw-r--r-- 1 root root  801 2009-01-01 01:00 asm.nanorc
-rw-r--r-- 1 root root  649 2009-01-01 01:00 autoconf.nanorc
ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ su - -c ls -l /dev/ov/rootfs/system_ext/bin | head -5
total 6496
-rwxr-xr-x 1 root shell   32152 2009-01-01 01:00 adb_root
-rwxr-xr-x 1 root shell 1037456 2009-01-01 01:00 bash
-rwxr-xr-x 1 root shell   53720 2009-01-01 01:00 dpmd
-rwxr-xr-x 1 root shell  302608 2009-01-01 01:00 htop
ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ls -l /dev/ov/rootfs/system_ext/usr/share | head -5
total 4
drwxr-xr-x 7 root root 4096 2009-01-01 01:00 vim
ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ls -l /dev/ov/rootfs/data/local/tmp/sysroot/etc | head -5
total 944
drwxrwxr-x  3 shell shell   4096 2026-03-25 16:58 bash-completion
-rw-rw-r--  1 shell shell   3316 2026-03-25 16:58 bash.bashrc
drwxrwxr-x  2 shell shell   4096 2026-03-25 16:58 bash_completion.d
-rw-r--r--  1 shell shell    685 2026-05-19 21:44 e2scrub.conf
ASUS_I006D:/data/local/tmp $

ASUS_I006D:/data/local/tmp $ ls -l /dev/ov/rootfs/data/local/tmp/sysroot/usr/bin | head -5
total 734208
lrwxrwxrwx 1 shell shell       11 2026-10-10 14:40 7zz -> ./7zz-26.04
-rwxr-xr-x 1 shell shell  2856696 2026-09-08 14:31 7zz-26.03
-rwxr-xr-x 1 shell shell  2853576 2026-10-10 11:07 7zz-26.04
-rwxr-xr-x 1 shell shell  3090736 2026-09-08 14:31 7zz_static_26.03
ASUS_I006D:/data/local/tmp $



----

To access the original file you can also create a temporary bind mount for the file when creating the overlay mount.


Example
ASUS_I006D:/ $ /data/local/tmp/create_overlay_mount.sh /vendor mount FILES_TO_KEEP="/vendor/etc/mkshrc /vendor/etc/vmmgr.conf" 
The image file "/data/local/tmp/image001" already exists - there should already be a filesystem on the disk

Creating and mounting the directories for the overlay mount for "/vendor" ...
Creating the temporary file "/data/local/tmp/vendor/etc/mkshrc" ...
Creating the temporary file "/data/local/tmp/vendor/etc/vmmgr.conf" ...

Creating the directory "/dev/ov/upper/vendor" ...
Creating the directory "/dev/ov/merged/vendor" ...
Creating the directory "/dev/ov/work/vendor" ...
Creating the overlay mount for "/vendor" ...
Creating the bind mount "/vendor"...
Remounting the mount point "/vendor/bt_firmware" ...
Remounting the mount point "/vendor/dsp" ...
Remounting the mount point "/vendor/firmware_mnt" ...
Checking the overlay mount for "/vendor" ...

Summary:
--------

1 overlay mount(s) created:

  /vendor

ASUS_I006D:/ $

# change the file /vendor/etc/mkshrc
#
|ASUS_I006D:/ $ echo | su - -c tee  /vendor/etc/mkshrc

ASUS_I006D:/ $ cat /vendor/etc/mkshrc

ASUS_I006D:/ $

# the bind mount still points to the original file
#
ASUS_I006D:/ $ cat /data/local/tmp/vendor/etc/mkshrc
# Copyright (c) 2010, 2012, 2013, 2014
#    Thorsten Glaser <tg@mirbsd.org>
# This file is provided under the same terms as mksh.
#-
# Minimal /system/etc/mkshrc for Android
#
# Support: https://launchpad.net/mksh

set +o nohup

if (( USER_ID )); then PS1='$'; else PS1='#'; fi
PS4='[$EPOCHREALTIME] '; PS1='${|
    local e=$?

    (( e )) && REPLY+="$e|"

    return $e
}$HOSTNAME:${PWD:-?} '"$PS1 "
ASUS_I006D:/ $ 


----



If the contents of a directory with overlay mount look weird, remount the overlay directory using the script with the parameter "remount" and check the directory contents again.

Example

[ 03:38 PM root@localhost /data/local/tmp ]# ./create_overlay_mount.sh remount /odm
Remounting the overlay mounts ...
Remounting "/odm" ...
 ... done

[ 03:38 PM root@localhost /data/local/tmp ]#

and check again.




To manually list all overlay mounts this command can be used:
 
mount | grep ^overlay





Overlay mounts created with create_overlay_mount.sh are not persistent — restarting the phone will always "delete" them.

Before restarting the phone if you encounter a problem with the overlay mounts, you can try the following:

./create_overlay_mount.sh clean

to unmount all overlay mounts




Additional infos



The Magisk Module magisk_overlayfs


If Magisk is installed, the Magisk module for implementing overlay mounts can be used to create overlay mounts.

This Magisk Module creates the overlay mounts very early in the boot process . Therefore, the overlay mounts created by this Magisk module do not overwrite bind mounts created by other Magisk modules and "su" via Magisk is still possible in adb sessions when using this Magisk module.

This Magisk module also works in the Android 16.

See How to create Magisk Modules that install new files in system for Details using this Magisk Module

Note that the original Magisk Module for overlay mounts does not work anymore with Magisk v30.7.

A version of the Magisk Module that works in Magisk v30.7 is available here:

https://github.com/bnsmb/magisk_overlayfs/



Notes


The virtual disk used by the Magisk Module for implementing overlay mounts, /data/adb/overlay, can also be used with the script create_overlay_mount.sh:

IMAGE_FILE=/data/adb/overlay  ./create_overlay_mount.sh  default /vendor_dlkm /odm_dlkm


Do not use the Magisk module for implementing overlay mounts and the script create_overlay_mount.sh in parallel!



Other Magisk Modules using overlay mounts



Other Magisk Modules using overlay mounts are:

https://github.com/backslashxx/mountify

https://github.com/dyokism/NanoMount




Downloads



create_overlay_mount.sh


Statically linked binaries for arm64 CPUs:

umount
bash-static-stripped

mount
losetup


The binaries are also available in a GitHub repository: 

https://github.com/bnsmb/binaries-for-Android


A virtual disk with a clang21 toolchain for arm64 CPUs is available here

http://bnsmb.de/files/public/Android/clang21_virtual_image.gz


A virtual disk with a clang19 toolchain for arm64 CPUs is available here

http://bnsmb.de/files/public/Android/clang19_virtual_image.gz


A virtual disk with only Perl 5.42 and clang19 for arm64 CPUs is available here:

http://bnsmb.de/files/public/Android/perl542_and_clang_virtual_image.gz



Links

 

The Linux Kernel - overlay filesystems

How to use Overlay FS?

My HowTos for Android

 

Back to top