These are the steps I followed to root my old Samsung Galaxy J6 device. The procedure might vary slightly for other devices
Requirements
- Stock ROM of the current device OS
- Android Development Bridge (ADB) installed in computer
- Heimdall in computer
- Magisk app installed in device
Process
- Extract
boot.imgfrom the current ROM- Download the ROM online from SamFW or GalaxyFirmware. It’ll be a .tar.md5 file
- extract the
APthe file usingtar -xvf. - From the extracted
APget theboot.img.lz4by the same method lz4 -d boot.img.lz4to getboot.imgInstead of getting the whole ROM, one can just download theAPfile to start with.
- Connect the android device to the computer via ADB
- Send the
boot.imgto the Android device. Can useadb push boot.img /sdcard - Select Install in the Magisk app and select
boot.imgand get a patched boot image - get the patched boot image back to the computer
adb pull /sdcard/Download/Magisk-...img - Install heimdall/Odin in computer
- Put the device to download mode by
adb reboot bootloader - When the device boots into bootloader mode, verify heimdall detects it by
heimdall detect - When the device boots into bootloader, flash the boot image using heimdall
heimdall flash --BOOT Magisk-...img - The android device will auto reboot. If Samsung Knox triggers and ask to factory reset, proceed with it and reinstall Magisk app.
- Follow the instructions in the Magisk app.
Later I also managed to install Magisk in a 2017 J5 Pro following the Magisk wiki