mount ext4 drives into the google pixel's internal storage
WARNING: this code is experimental and there is no guarantee that it works. rooting your phone or running any commands as root can be very dangerous. you have been warned.
anyway here is a demo image of an SSD mounted into the internal storage on my Pixel XL. the data is readable & writable in the Google Photos app.
the main goal is to allow for easy backup of external media via Google Photos on original Google Pixel phones, which which have an unlimited storage benefit. the "usual" method is to copy every file to the device's internal storage, which can incur terabytes of unnecessary writes to the limited lifetime of the internal flash memory.
i first tried using FUSE (filesystem in user space) based solutions like bindfs (via termux root-packages) and fuse-nfs (complicated to compile for android so i built my own minimal version in Rust). this works and is especially good at sidestepping android's selinux policies. however the performance was not acceptable. (note: i have not tried fbind but i don't think that works out of the box here without using FUSE)
this method is basically a hack around the selinux policies + app permissions using the plain old mount
command.
(if you don't care about using these scripts and just want to see how it's done, take a look at mount_ext4.sh)
installation is essentially just copying the scripts to the device & making them executable. you can do this manually, or use one of the automated steps below. you also probably want to disable Google Play Protect scanning in the Play Store menu.
sh -c "$(curl -fSs https://raw.githubusercontent.com/master-hax/pixel-backup-gang/master/install.sh)"
make mobile-install
. this installs the scripts to /data/local/tmp
by default.
make mobile-install DEVICE_INSTALL_DIRECTORY=/data/data/com.termux/files/home
make mobile-install HOST_ADB_COMMAND=/mnt/c/Users/someone/AppData/Local/Android/Sdk/platform-tools/adb.exe
./start_global_shell.sh
to enter the global mount namespace
/dev/block/sdg1
but changes when devices are connected and disconnected.
./show_devices.sh
./find_device.sh
./mount_ext4.sh <BLOCK_DEVICE>
e.g. ./mount_ext4.sh /dev/block/sdg1
everything located under /the_binding
on the external drive should now be visible by apps at /the_binding
in the internal storage
./unmount.sh
everything located under /the_binding
in the internal storage should now be gone. you can disconnect the drive if you're sure all pending writes have been flushed.
setenforce 1
to re-enable it earlier. don't forget that the software on the pixel is severely out of date and there are a lot of serious known vulnerabilities. try to keep device radios off (especially bluetooth and NFC) to reduce the attack surface../show_devices.sh
and store it. you can then use this UUID in a script to always re-mount that same drive without having to figure out what the block device path is at e.g. something like ./mount_ext4.sh $(./find_device.sh ./my_drive_id.txt)