Fix: updater-script how to mount /system and delete apk in /system


katerpanne

Members
Apr 19, 2014
3,541
332
Hello together,

perhaps somebody can help me. I have written a script for twrp.

The script should remove "/system/priv-apps/MiuiCamera/MiuiCamera.apk" and put some new files into the folder.

If I execute the script, it will not delete "/system/priv-apps/MiuiCamera/MiuiCamera.apk" but if I execute it again without reboot, the file is deleted.

I have tried everything ... I think it has to to with the "mount". My TWRP ist mounting "system_root" instead of "system" ...

Perhaps anybody has an idea ....

The updater-script with a lot of tries ...

###########################################################
ui_print(" Set busybox up and running ");
package_extract_file("META-INF/com/miui/busybox", "/tmp/busybox");
run_program("/sbin/chmod", "777", "/tmp/busybox");
###########################################################
# ui_print(" UnMounting filesystem");
# run_program("/tmp/busybox", "umount", "/system");
# unmount("/system");
# run_program("/tmp/busybox", "umount", "/vendor");
# sleep(1);
# ui_print(" Mounting filesystem");
#
# mount("ext4", "EMMC", "system_root", "/system_root");
# mount("ext4", "EMMC", "/dev/block/sde54", "/system");
# mount("yaffs2", "MTD", "system", "/system");
# run_program("/tmp/busybox", "mount", "/system_root");
# run_program("/tmp/busybox", "mount", "/vendor");
sleep(3);
###########################################################
delete_recursive("/system_root/system/priv-app/MiuiCamera");
###########################################################
ui_print(" Delete old files");
package_extract_file("delete.sh", "/tmp/delete.sh");
set_perm(0, 0, 0777, "/tmp/delete.sh");
run_program("/tmp/delete.sh", "");
delete("/tmp/delete.sh");
###########################################################
run_program("/tmp/busybox", "rm", "-f", "/system_root/system/priv-app/MiuiCamera/*");
delete("/system_root/system/priv-app/MiuiCamera/MiuiCamera*");
delete("/system_root/system/priv-app/MiuiCamera/MiuiCamera.apk");
sleep(1);
###########################################################
ui_print(" Extracting system filesystem");
package_extract_dir("system", "/system");
ui_print(" Extracting vendor filesystem");
package_extract_dir("vendor", "/vendor");
sleep(1);
###########################################################
# ui_print(" Set permission on vendor");
# set_perm_recursive(0,2000,0755, 0755, "/vendor/camera");
ui_print(" UnMounting filesystem");
# run_program("/tmp/busybox", "umount", "/system");
# unmount("/system");
# run_program("/tmp/busybox", "umount", "/vendor");
ui_print(" Done.... Ready to reboot");
ui_print("-------------------------------------");
ui_print(" ");

The delete-script:
#!/sbin/sh
rm -f /system_root/system/priv-app/MiuiCamera/MiuiCamera.apk
# cat /proc/mounts > /tmp/test.txt

Kind regards Kater

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Solution:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
But I want to keep the script as simple as possible, so I have decided do go back to the roots -> shell scripting :)
And now it is working no matter if "/system" or "/system_root" is listed in the fstab

With this scripts I don't want to win a programming contest, it is simple, works and good :)
TWRP_Flashable_Zip_Example.zip

drive.google.com
drive.google.com

This is the magic (mount.sh) and double delete:
mount -o rw,remount /system
mount -o rw,remount /system /system
mount -o rw,remount /system_root
mount -o rw,remount /system_root /system_root
rm -f /system_root/system/priv-app/MiuiCamera/MiuiCamera.apk
rm -f /system/priv-app/MiuiCamera/MiuiCamera.apk

Now MimojiCamera is working with one install-step in twrp, for those guys who want to have it.
https://xiaomi.eu/community/threads/how-to-install-mimoji-camera-into-xiaomi-eu-rom.54976/
 
Last edited:
Hello together,

perhaps somebody can help me. I have written a script for twrp.

The script should remove "/system/priv-apps/MiuiCamera/MiuiCamera.apk" and put some new files into the folder.

If I execute the script, it will not delete "/system/priv-apps/MiuiCamera/MiuiCamera.apk" but if I execute it again without reboot, the file is deleted.

I have tried everything ... I think it has to to with the "mount". My TWRP ist mounting "system_root" instead of "system" ...

Perhaps anybody has an idea ....

The updater-script with a lot of tries ...

###########################################################
ui_print(" Set busybox up and running ");
package_extract_file("META-INF/com/miui/busybox", "/tmp/busybox");
run_program("/sbin/chmod", "777", "/tmp/busybox");
###########################################################
# ui_print(" UnMounting filesystem");
# run_program("/tmp/busybox", "umount", "/system");
# unmount("/system");
# run_program("/tmp/busybox", "umount", "/vendor");
# sleep(1);
# ui_print(" Mounting filesystem");
#
# mount("ext4", "EMMC", "system_root", "/system_root");
# mount("ext4", "EMMC", "/dev/block/sde54", "/system");
# mount("yaffs2", "MTD", "system", "/system");
# run_program("/tmp/busybox", "mount", "/system_root");
# run_program("/tmp/busybox", "mount", "/vendor");
sleep(3);
###########################################################
delete_recursive("/system_root/system/priv-app/MiuiCamera");
###########################################################
ui_print(" Delete old files");
package_extract_file("delete.sh", "/tmp/delete.sh");
set_perm(0, 0, 0777, "/tmp/delete.sh");
run_program("/tmp/delete.sh", "");
delete("/tmp/delete.sh");
###########################################################
run_program("/tmp/busybox", "rm", "-f", "/system_root/system/priv-app/MiuiCamera/*");
delete("/system_root/system/priv-app/MiuiCamera/MiuiCamera*");
delete("/system_root/system/priv-app/MiuiCamera/MiuiCamera.apk");
sleep(1);
###########################################################
ui_print(" Extracting system filesystem");
package_extract_dir("system", "/system");
ui_print(" Extracting vendor filesystem");
package_extract_dir("vendor", "/vendor");
sleep(1);
###########################################################
# ui_print(" Set permission on vendor");
# set_perm_recursive(0,2000,0755, 0755, "/vendor/camera");
ui_print(" UnMounting filesystem");
# run_program("/tmp/busybox", "umount", "/system");
# unmount("/system");
# run_program("/tmp/busybox", "umount", "/vendor");
ui_print(" Done.... Ready to reboot");
ui_print("-------------------------------------");
ui_print(" ");

The delete-script:
#!/sbin/sh
rm -f /system_root/system/priv-app/MiuiCamera/MiuiCamera.apk
# cat /proc/mounts > /tmp/test.txt

Kind regards Kater
Hello
I just noticed that System path is different with rom /phone version.
As example for Hosts file path.
MI9T weekly rom:
- system-root/system/etc/hosts
Redmi 8 Stable EU rom:
- system/system/etc/hosts
MI8SE eu weekly:
- System/etc/hosts
I have no explanation for these difference.
This can be a way to investigate for your script.
 
  • Like
Reactions: katerpanne
Hello
I just noticed that System path is different with rom /phone version.
As example for Hosts file path.
MI9T weekly rom:
- system-root/system/etc/hosts
Redmi 8 Stable EU rom:
- system/system/etc/hosts
MI8SE eu weekly:
- System/etc/hosts
I have no explanation for these difference.
This can be a way to investigate for your script.

Hi Lolo,

thank you for the hint. I have tried both on MI9 (system_root and system).

the result is the same for both options. The deletion of the apk only takes place the second time. Maybe I'll change the order.

I have looked how xiaomi.eu is doing that, but it is a different way ...

Thanks and a nice greeting
 
Last edited:
Hi Lolo,

thank you for the hint. I have tried both on MI9 (system_root and system).

the result is the same for both options. The deletion of the apk only takes place the second time. Maybe I'll change the order.

I have looked how xiaomi.eu is doing that, but it is a different way ...

Thanks and a nice greeting
I am using this script:
Sure you know it.
It is well working on the MI9T and other phone having system_root path.
Keep me in the loop of your findings I am interested to know.
Greetings
 
  • Love
Reactions: katerpanne
Hi Lolo,

I have read the fstab ... on MI9 it looks like this:
  • Processing '/recovery'
  • Processing '/system_root'
As you mentioned it depends on the phone / TWRP - I dont know.
Using Edify Script Language in "updater-script" for mounting, I haven't been able to get it to fly in one pass.

And there is another thing... it might be a difference in:
  • package_extract_file
  • package_extract_dir
It seems, that "package_extract_file" will copy the file if it already exists or not
while "package_extract_dir" says ... I will do nothing, because the file already exist - that was my problem

But I want to keep the script as simple as possible, so I have decided do go back to the roots -> shell scripting :)
And now it is working no matter if "/system" or "/system_root" is listed in the fstab

With this scripts I don't want to win a programming contest, it is simple, works and good :)

This is the magic (mount.sh) and double delete:
mount -o rw,remount /system
mount -o rw,remount /system /system
mount -o rw,remount /system_root
mount -o rw,remount /system_root /system_root
rm -f /system_root/system/priv-app/MiuiCamera/MiuiCamera.apk
rm -f /system/priv-app/MiuiCamera/MiuiCamera.apk

Now MimojiCamera is working with one install-step in twrp, for those guys who want to have it.

@LOLO9393 : Dankeschön!

Happy day

PS: I know, I can read the fstab, put the partition into a variable and use it in the script - but I can look out of the window as well :cool:
 
Last edited:
i love you :) soooo much ...... i spend the hole night on this script... and I am so happy that you read it and show me my issue :)
 
  • Like
Reactions: trahzebuck
i love you :) soooo much ...... i spend the hole night on this script... and I am so happy that you read it and show me my issue :)

I was reading it. One i made such scripts and I was really a pro.
But at this point...
What is confusing me since I have a Xiaomi device are the mount points.
For example Orange Fox gives the advice to backup system and vendor *IMAGE*
I don't understand completely how this partitions are used.
Perhaps you problem is related to this.
Just a idea....
 
  • Love
Reactions: katerpanne
yes there are the /system and /vendor partitions...
but if you start twrp or orangefox /system is mounted sometimes as /system and sometimes as /system_root ...

and if you try to delete something on the /system or /system_root ...
it will end in an issue in the first try, it will pass in the second try .... why ever if I use the edify script :)
when I mount it with the shell-script it will pass in the first try

and in /vendor there is a lot of user stuff...
I have search the internet and found no rules when they save it in /vendor or in other folders like /sdcard/miui ...

as example... in some roms you find the "camera" files in /sdcard/miui and in other roms you find it as well in /vendor

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
lolo and trahzebuck ... it is my pleasure to have an inner japanese cherry blossom festival for you here in the forum
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Nice Greetings from Home Office :) yeepyeep ....
 
Last edited: