Skip to content

Instantly share code, notes, and snippets.

@tothi
Last active May 10, 2024 22:57
Show Gist options
  • Save tothi/972b4316d2da7083292b7e628487e738 to your computer and use it in GitHub Desktop.
Save tothi/972b4316d2da7083292b7e628487e738 to your computer and use it in GitHub Desktop.
Upgrading LineageOS and reinstalling Magisk

Upgrade LineageOS with Magisk

WARNING: tested only on my setup (LineageOS 18.1 on instantnoodle), other setups may break and brick the device!

Step-by-step instructions (for reinstalling patched boot.img for Magisk):

  1. upgrade LineageOS to the latest by the standard way in Android GUI (download + install + reboot)
  2. if using not the latest Magisk: wipe old (possibly hidden) Magisk app then install the up-to-date one from the official Magisk github repo
  3. install (git clone) payload_dumper from GitHub (in Termux or in an SSH session on the Android device) for the 1st time, or update (git pull) later
  4. the Android terminal session: wget the same LineageOS nightly image installed in step 1 from https://download.lineageos.org/
  5. unzip downloaded zip image in the payload_dumper folder (we need payload.bin)
  6. run python payload_dumper.py payload.bin, look for output/boot.img, copy it to the shared storage (e.g. ~/storage/shared/), and cleanup (large) temp files (lineageos-*.zip, payload.bin, output folder).
  7. UPDATED: now the boot.img itself is available for download. So instead of 3-4-5-6: download the boot.img directly from https://download.lineageos.org
  8. run Magisk (it'll reinstall itself if it was hidden), choose "Magisk, Install" (confirm "Ramdisk: YES" before), choose "Select and Patch a File", select boot.img on the shared storage, and "Let's Go". Output file (to be sideloaded) is in Download/magisk_patched-{version}_{rand}.img.
  9. adb pull that patched img file.
  10. reboot to fastboot mode with adb reboot fastboot
  11. fastboot flash --slot=all boot magisk_patched_{version}_{random}.img
  12. reboot (fastboot reboot) & enjoy updated LineageOS with Magisk enabled.
  13. IMPORTANT: if Magisk was "hidden" (renamed), don't forget to rename it again in Magisk settings, otherwise apps bypassed checks and worked earlier may stop working. Other settings should be survived during the reinstall/upgrade. Hiding might need a reboot cycle (enable app install permission for Magisk then the actual hide function).
  14. It is recommended to use the latest Play Integrity Fix plugin from here: https://github.com/chiteroman/PlayIntegrityFix
@NicolasWebDev
Copy link

Hi @tothi , because I had the same need than you and in case you're interested, I have created a small bash script that automates the process.

You can find the process here: https://github.com/NicolasWebDev/reinstall-magisk-on-lineageos

@tothi
Copy link
Author

tothi commented Nov 4, 2022

awesome @NicolasWebDev :) just read your update, nice. 👍

@richardlock
Copy link

Hi @NicolasWebDev and @tothi. Thanks for the great script. I've created a PowerShell script based on your bash script for any Windows users out there due to lack of native USB support in WSL.

https://github.com/richardlock/powershell-install-lineagemagiskpatchedbootimage

@mirayashi
Copy link

Hey there,

May I ask in which cases any of this is necessary? The steps I followed are much, much simpler, yet successful on my OnePlus 8 Pro, LineageOS 21:

  1. Download and install update from the Android GUI, but DO NOT reboot yet
  2. Open Magisk, tap Install > Install to inactive slot (after OTA)
  3. Reboot, done

@richardlock
Copy link

Hi @mirayashi. That's great if that method works. I do not currently use LineageOS with my phone so no longer maintain the code on my repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment