[Sony Xperia M4 Aqua] HRSE:
I only trim the odex.system.sqsh file.

The sequence is as described in post#15 but most of it has been simplified by using the scripts in post#1.

For some reason, OP didn't include any how-to, so I shared my understanding here for anyone who wanted to try this. All credits go to OP [MENTION=7806698]klarseher[/MENTION]

Just a quick recap, after debloating the phone, many system APK files are deleted but the associated ODEX files still remain. In fact, these stock ODEX files are compressed into the file /system/odex.system.sqsh, and they are extracted to /system/odex.system folder on boot. The goal is to delete those unused ODEX files (no associated APKs) from /system/odex.system.sqsh.

Create the list of .APK and .ODEX files to remove (CRITICAL)

OP included a default list of files to remove in system_cleanup.sh (between #BEGIN and #END).

You have to create your own list according to your need.

Besides the apps, other T&C files and ringtones/notification sound files are removed (optional: comment out the lines not stated with /system/app/ or /system/priv-app/ - we can easily delete those files later using any root file manager)

The script system_cleanup.sh will delete the APKs listed, and

at the same time it automatically creates another list of ODEX files to be removed

in later steps (odex_sqsh_cleanup.lst). This is truly brilliant!

However, if you have already debloated your phone then the script won't work as intended! Specifically, the script will not be able to auto create the odex_sqsh_cleanup.lst.

Proceed with either option below:

For not debloated phone (but rooted):

Extract the ZIP file in post#1 to some folder on your phone.

Modify file system_cleanup.sh, add/remove the path to the apps that you want to delete from phone.

Delete file odex_sqsh_cleanup.lst (the new file will be created automatically)

Run as root:

sh system_cleanup.sh -d

This command list all system app directories -> maybe useful:

find /system/app /system/priv-app -type d -maxdepth 1 > /sdcard/app_list.txt

For debloated phone: need extra effort to come up with the list of ODEX files to remove.

What I did

:

Create a list of all ODEX files:

find /system/ -type f -name "*.odex" > /sdcard/odex_list.txt

Create a list of all DEX files:

find /data/ -type f -name "*.dex" > /sdcard/dex_list.txt

Manually compare 2 lists: ODEX file which does not have associate DEX file can be safely removed.

Other method (not tested)

:

Create a list of all ODEX files in /system/odex.system:

find /system/odex.system -type f -name "*.odex" > /sdcard/odex_list.txt

Create a list of all linked ODEX files:

find /system/ -type l -name "*.odex" > /sdcard/linked_odex_list.txt

Manually compare 2 lists: ODEX file which is not linked can be safely removed.

After having the list of ODEX files to be removed (odex_sqsh_cleanup.lst), proceed to step 2 below.

Install CentOS in VirtualBox

I used CentOS-7-x86_64-Minimal-1611.iso

VirtualBox VM needs special settings to install CentOS and enable network adapter, please referer to attached screenshots.

I can't figure out how to set up Shared Folder in VirtualBox, so I use other methods for transfering files to CentOS VM (via internet & USB)

After installing CentOS:

Open Terminal

Install squashfs-tools (this will fail if CentOS VM has no internet access)

sudo yum install squashfs-tools

[MENTION=7837559]ivy.lally[/MENTION] reported that it was ok to use Funtoo OS

with XFS filesystem

. With other filesystems, there will be a lot of warnings when running unsquashfs in step 3 below, and after replacing odex.system.sqsh the phone is unresponsive & apps crash.

Clean up odex.system.sqsh

In CentOS VM:

Extract ZIP file in post#1 to a folder in CentOS VM

Put the file odex_sqsh_cleanup.lst (prepared in step 1) into the same folder (overwrite if prompted)

Copy odex.system.sqsh from phone to CentOS VM, put it into the same folder as in step 2 (I copied directly to CentOS VM via MTP in recovery mode, need to mount /system)

Run in terminal:

./odex_sqsh_cleanup[B].sh[/B]

It will extract the file odex.system.sqsh to folder /squashfs-root, then delete the files listed in odex_sqsh_cleanup.lst and finally compress into odex.system_new.sqsh

Move the cleaned up odex.system.sqsh file back to phone

While phone is in TWRP:

Mount /system as rw (via adb command or TWRP menu)

Transfer file odex.system-new.sqsh to phone, put into /system folder (I copied directly from CentOS VM via MTP in recovery mode)

Run the following commands: (via adb shell or directly in TWRP terminal)

cd /system
touch dummy
chcon --reference=odex.system.sqsh dummy
rm system.odex.sqsh
mv odex.system[B]-new[/B].sqsh odex.system.sqsh
chcon --reference=dummy odex.system.sqsh

Wipe Cache & ART/DalvikCache

Reboot

Resize Partition: OP included the (incompleted?) script for it, but I didn't try.

Note: actually you can also remove some other apps like Chrome, YouTube, Hangouts, etc. which are available on Google Play Store, then reinstall later. Doing this will help to save some space when those apps are updated.