Install TWRP to only one slot or offline boot.img file, not both I want to install TWRP on my phone that uses the A/B partition schema. The official TWRP installer ZIP by default installs to both boot_a and boot_b. This always breaks the system in the inactive slot because I install Magisk after flashing/OTA.

Can I install TWRP to only one slot, or an offline boot.img file (like Magisk Manager supports)?
So this way, I ended up creating a script on my own.

Lucky enough, installing TWRP to boot.img isn't hard at all. The install script in TWRP just replaces ramdisk.cpio with the one ramdisk-twrp.cpio provided in the ZIP.

The effective part of the script is as following, root is of course required.

ln -s /system/bin/linker64 /sbin/linker
cp &lt;path-to-magiskboot&gt; /sbin/magiskboot
mkdir /data/local/tmp/twrp
cd /data/local/tmp/twrp
/sbin/magiskboot --unpack &lt;path-to-boot.img&gt;
cat &lt;path-to-[ramdisk-twrp.cpio]&gt; &gt; ramdisk.cpio
/sbin/magiskboot --repack boot.img
cp new-boot.img /sdcard/new-boot.img


Now the TWRP-installed new-boot.img is located at /sdcard/.

To install to a single slot, dd the boot image out and apply the same process as shown above and dd the new image back.