Module in post-fs mode?

Search This thread

LinoX

Senior Member
May 10, 2005
383
123
41
Roma
Hi there.
I'm trying to write a "cache module" (which runs in post-fs stage, after the system has been mounted but before data).
Why do I need it?
Because I want to execute an "iptables -P OUTPUT DROP" to block every outgoing connection until afwall+ kicks in (in post-fs-data) and establishes the proper rules for the apps.
I can't find a proper "module template" on github.
moreover...Is there a way to "print to magisk_debug.log" from the script?
I would like to "iptables -L" pre-script execution and post-script execution so I can check that everything has gone ok.
Is there a function to do that or should I "iptables -L > /tmp/iptables.log"
Any hint?
Thank you.
 

LinoX

Senior Member
May 10, 2005
383
123
41
Roma
In post-fs, Magisk only does a simple mount of any files found in /cache/magisk_mount/system. No scripts are run... That's not until post-fs-data.

See here for more details (if you haven't already):
https://github.com/topjohnwu/Magisk/blob/master/docs/details.md
Thanks Didgeridoohan, I already read that but if you read carefully
4UgbRUI.png


He says he can run script in different stages. That "simple mount thing" sounds to me like "hey, look...don't ask me to do mounts different than simple mounts."
Moreover I found this on another script...
t6d9t1C.png

so it must be possible...(or it was possible with previous versions of magisk)
 
Last edited:

Didgeridoohan

Senior Moderator / Dev Committee / Dev Relations
Staff member
May 31, 2012
11,643
12,412
Gothenburg
Google Nexus 4
Nexus 6
Thanks Didgeridoohan, I already read that but if you read carefully
https%3A%2F%2Fi.imgur.com%2F4UgbRUI.png


He says he can run script in different stages. That "simple mount thing" sounds to me like "hey, look...don't ask me to do mounts different than simple mounts."
Moreover I found this on another script...
https%3A%2F%2Fi.imgur.com%2Ft6d9t1C.png

so it must be possible...(or it was possible with previous versions of magisk)

"Simple mounts" means that it doesn't add anything new, only replaces already existing files/folders. But you've read the docs, you know that...

Here's some reading on cache modules:
https://forum.xda-developers.com/showpost.php?p=69621730&postcount=7

It might be possible to run scripts in post-fs in the future (that's up to @topjohnwu). Right now it isn't...
 

LinoX

Senior Member
May 10, 2005
383
123
41
Roma
Thank you very much for that.:)
Yeah I didn't read that specific post (even if I searched for it a lot) and it replies my question: Cache modules aren't supported anymore.
I guess I'll have to deal with post-fs-data mode then...
Even if I don't need the data partition and even if, once data is mounted, it could be too late to block the network (some services might have already accessed it..yet not the apps themselves)
Thank you again, man.
 

Didgeridoohan

Senior Moderator / Dev Committee / Dev Relations
Staff member
May 31, 2012
11,643
12,412
Gothenburg
Google Nexus 4
Nexus 6
Thank you very much for that.:)
Yeah I didn't read that specific post (even if I searched for it a lot) and it replies my question: Cache modules aren't supported anymore.
I guess I'll have to deal with post-fs-data mode then...
Even if I don't need the data partition and even if, once data is mounted, it could be too late to block the network (some services might have already accessed it..yet not the apps themselves)
Thank you again, man.

No worries...

Just in case you haven't thought about it: if you want to run the script as early as possible, place it in /magisk/.core/post-fs-data.d rather than in the post-fs-data.sh file of a module.
 
  • Like
Reactions: LinoX

m45k

Senior Member
Nov 19, 2008
76
5
I am using Magisk 16.7 on Android 8.1
On my phone there is no /magisk folder
For using a boot script should i just create the folder structure or where do i have to place my files?
 

DanGLES3

Senior Member
Nov 11, 2017
738
722
I am using Magisk 16.7 on Android 8.1
On my phone there is no /magisk folder
For using a boot script should i just create the folder structure or where do i have to place my files?
Boot scripts should be placed on /sbin/.core/img/.core/post-fs-data.d

Sent from my LGE w5 using XDA Labs
 

Top Liked Posts

  • There are no posts matching your filters.
  • 2
    Thanks Didgeridoohan, I already read that but if you read carefully
    https%3A%2F%2Fi.imgur.com%2F4UgbRUI.png


    He says he can run script in different stages. That "simple mount thing" sounds to me like "hey, look...don't ask me to do mounts different than simple mounts."
    Moreover I found this on another script...
    https%3A%2F%2Fi.imgur.com%2Ft6d9t1C.png

    so it must be possible...(or it was possible with previous versions of magisk)

    "Simple mounts" means that it doesn't add anything new, only replaces already existing files/folders. But you've read the docs, you know that...

    Here's some reading on cache modules:
    https://forum.xda-developers.com/showpost.php?p=69621730&postcount=7

    It might be possible to run scripts in post-fs in the future (that's up to @topjohnwu). Right now it isn't...
    1
    In post-fs, Magisk only does a simple mount of any files found in /cache/magisk_mount/system. No scripts are run... That's not until post-fs-data.

    See here for more details (if you haven't already):
    https://github.com/topjohnwu/Magisk/blob/master/docs/details.md
    1
    Thank you very much for that.:)
    Yeah I didn't read that specific post (even if I searched for it a lot) and it replies my question: Cache modules aren't supported anymore.
    I guess I'll have to deal with post-fs-data mode then...
    Even if I don't need the data partition and even if, once data is mounted, it could be too late to block the network (some services might have already accessed it..yet not the apps themselves)
    Thank you again, man.

    No worries...

    Just in case you haven't thought about it: if you want to run the script as early as possible, place it in /magisk/.core/post-fs-data.d rather than in the post-fs-data.sh file of a module.