Hi<br><br>I was looking around on the initramfs to try to understand how you will load the policy at that point in the boot process, using the selinux_init_load_policy() from libselinux would be ideal since it does everything for you, but you would have to boot without the &#39;ro&#39; flag otherwise it wont be able to write to syslog, or rewrite code that already exists in libselinux? or load the libraries and shared objects onto initramfs for the executable? Could you please clarify to me how this would be done from initramfs?
<br><br>Also when running this pre-init executable, after a successful policy load and a relabel, init which replaces the pre-init will have the context system_u:system_r:init_t , so it get&#39;s into the right context, though it will show as &#39;/sbin/pre-init&#39; in &#39;ps Zaux&#39;.
<br><br><br>Updated this pre-init for those who want to try it :<br><br>#include &lt;unistd.h&gt;<br>#include &lt;selinux/selinux.h&gt;<br>#include &lt;stdio.h&gt;<br><br>int main(int argc, char *argv[]) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int enforce = 0;
<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if ( ! getenv(&quot;SELINUX_INIT&quot;) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; putenv( &quot;SELINUX_INIT=YES&quot; );<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( selinux_init_load_policy(&amp;enforce) == 0 ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;SELinux: Policy loaded successfully.&quot;);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execv(&quot;/sbin/init&quot;, argv);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else if( enforce &gt; 0 ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(&quot;SELinux: Enforcing mode enabled but load_policy failed.&quot;);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; execv(&quot;/sbin/init&quot;, argv);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>}<br><br>-----------<br><br>Thanks<br><br>