[Sony Xperia M2] m.tarhsaz:
#include <std_disclaimer.h>
/*
* Your warranty is now void.
*
* I am not responsible for bricked devices, dead SD cards,
* thermonuclear war, or you getting fired because the alarm app failed. Please
* do some research if you have any concerns about features included in this ROM
* before flashing it! YOU are choosing to make these modifications, and if
* you point the finger at me for messing up your device, I will laugh at you.
*/

Finally I managed to build mount namespace enabled(required by MagiskHide) kernel for Sony Xperia M2.

I applied patch to the original kernel source code(available on Sony website), version 3.40(18.6.A.0.182)

So you don't need kernel 3.8+ for using MagiskHide

This kernel tested on D2302 device.

Kernel:

3.40 - 18.6.A.0.182

Features:

mount namespace(required by MagiskHide)

kernel configuration is available in /proc/config.gz

boot image format is AOSP, so there is no need to use Boot Bridge for flashing Magisk

Tools:

Ubuntu 14.04

gcc 4.7

mkqcdtbootimg (for building flashable boot image)

Flashtool 0.9.11.0 (for extracting kernel.elf from original .FTF)

Android Image Kitchen 3.6 (for extracting ramdisk and cmdline from original kernel image)

TWRP 3.1.0-0

Magisk 20.3 (20300)

Magisk Manager 7.5.1 (267)

Download:

DM2-V0100-D2302-boot.img

Installation:

Ensure device ROM version is 18.6.A.0.182 or based on that or has same working kernel

Download .img file

Power off device

Press Vol+

Hold Vol+ and connect device to your computer using USB cable

Device will boot in fastboot mode(verify that notification light color is blue)

run "fastboot devices" to ensure device is connected (fastboot print device serial number)

run "fastboot flash boot DM2-V0100-D2302-boot.img"

Ensure no error is occured during flash

run "fastboot reboot" to restarting device

After boot up check kernel version in Setting->About

Magisk can be flashed using TWRP

If MagsikHide not worked :

turn off and then on again MagiskHide in MagiskManager->Seetings

Hide Magisk Manager using "Magisk Manager->Settings->Hide Magisk Manager"

If you encounter bootloop or other kernel related problem:

Don't worry

Download original ROM 18.6.A.0.182 using XperiFirm or newer version of Flashtool bundled with XperiFirm

Install and Run Flashtool 0.9.11.0+(I used 0.9.11.0 version)

Click on "Flash Device" button in toolbar

Select "Flashmode" in "Bootmode chooser" window

Select downloaded ROM in left panel

Exclude eveything in right panel

except

KERNEL

Uncheck

all WIPE options

Don't change other settings

Click "Flash" button and follow flash process

Thanks:

Norbert Harrer

didgeridoohan and Magisk Documentation,

here

,

here

and

here

Eric W. Biederman

(patching kernel source code)

xavileon

(patching kernel source code)

ugurkrl

(kernel compiling and image building guideline)

XDA:DevDB Information

DM2 - MagiskHide working kernel 3.40, Kernel for the Sony Xperia M2

Contributors

m.tarhsaz

Kernel Special Features: MagiskHide working patched kernel 18.6.A.0.182

Version Information

Status: Stable

Current Stable Version: 1.0

Stable Release Date: 2020-03-11

Created 2020-03-10

Last Updated 2020-03-12