[Moto Z4 Guides, News, & Discussion] zander21510:
Full disclosure- many of these steps are just copy/pasted from the Magisk install instructions and other areas online, just thought I'd post a full set of instructions for our device. There might be easier steps or I might have added additional unnecessary steps, please let me know and I can update. I'm just posting what worked for me. I also don't like installing things from sketchy fileshare sites, so I provide the way to get everything from official sources.

This is to get root via Magisk on a stock Moto Z4 (I have the Retail model, don't know anything about Verizon or other models). You will need to have a knowledge of how to do some advanced tasks, such as using ADB/Fastboot, installing APKs from unknown sources, and installing drivers on your computer. Google is your friend (or DuckDuckGo in my opinion) I am not responsible for bricked phones, thermonuclear war, etc. This is just a helpful guide.

You might as well start on the latest OTA since during the unlock process you'll have no choice but to erase all your data, make sure you're fully updated and backup your data.

HOW TO ROOT FROM STOCK:

First, you must unlock your bootloader. WARNING: THE UNLOCK PROCESS WILL ERASE ALL OF YOUR DATA!

Follow the instructions on the Motorola website to check if your bootloader can be unlocked and retrieve the ID codes

One step Motorola doesn't mention is that you must enable OEM unlocking from the Developer Options. If you don't know how to get to Developer Options, you'll need to google it. It's very easy, and I think it's a good "test" to figure out if you should even be trying to root your phone :)

Once you have your unlock code, unlock your bootloader according to the instructions here. EVERYTHING ON YOUR PHONE WILL BE DELETED AT THIS POINT!

Next, you must patch the stock boot image.

You will need to retrieve the boot image, please follow the instructions at the bottom of this post on how to download the full OTA archives.

Once you have the stock boot image, copy it to your phone's storage

You need to install Magisk Manager on your phone (it doesn't need to be rooted at this point- it's just needed to patch the boot image) Download the latest Magisk Manager from the official Magisk thread here

Tap "Advanced Settings" in Magisk Manager and check "Recovery Mode"

Press Install → Install → Select and Patch a File, and select your stock boot/recovery image file

Magisk Manager will patch the image, and store it in [Internal Storage]/Download/magisk_patched.img

Copy the patched image from your device to your PC. If you can’t find it via MTP, you can pull the file with ADB:

adb pull /sdcard/Download/magisk_patched.img

Now, flash the modified boot image

Plug your phone in, make sure USB debugging is enabled, open a command line in the same folder that your patched image is in (or, you can put in the full path on step 3 rather than just the filename).

Easiest way to get to fastboot mode is the command (you can also use the volume key trick if you'd rather or if you're having trouble with ADB):

adb reboot bootloader

Then all you have to do is:

fastboot flash boot magisk_patched.img

To reboot:

fastboot reboot

You should be done now! You can check the status of root from Magisk Manager and refer to Magisk documentation for any help with that. You may also want to disable Automatic System Updates from Developer options to prevent issues when updates are released.

HOW TO DOWNLOAD STOCK OTA ZIP & RETRIEVE BOOT IMAGE:

First, you need to download LSMA, Moto/Lenovo's software for managing and recovering phones

Once the software is installed, open it and go to the "Flash" tab, hit "Switch to Upgrade", and connect your phone

When you connect, it will check for an update (Sometimes it will not have the latest update even if you are offered an update on your phone. You'll need to wait until it shows up here)

Download the update

LSMA will download a zip file to C:\ProgramData\LMSA\Download\RomFiles, and once completed it will automatically extract the ZIP. (If you want the full ZIP image for any reason, you must copy it to a different location before the extraction completes, LSMA deletes the zip once the extraction finishes. Just have the window open until the download completes, as soon as the ZIP file appears copy it to another folder, it will not interfere with extraction.)

Retrieve the boot.img from the download folder

HOW TO UPGRADE TO NEW OTA, PRESERVING ROOT & DATA:

Now you can try following the Magisk instructions since our device has an A/B partition layout, but I wasn't able to get it to work, usually the upgrade fails validating the current image so I have an alternate set of steps that did work for me. Backup your data just in case though.

First, you need to download LSMA, Moto/Lenovo's software for managing and recovering phones

Once the software is installed, open it and go to the "Flash" tab, hit "Switch to Upgrade", and connect your phone

When you connect, it will check for an update (Sometimes it will not have the latest update even if you are offered an update on your phone. You'll need to wait until it shows up here)

Download the update, but don't install it yet. The program will download a zip file to C:\ProgramData\LMSA\Download\RomFiles, and once completed it will automatically extract the ZIP.

Retrieve the boot.img from the download folder and copy it to your phone

Patch the boot.img in Magisk Manager per the steps above

Now proceed with installing the update in LSMA (It will say it's going to erase your data, but it does not).

Your phone will reboot to the bootloader and LSMA will flash the update

Once the update is finished and your phone reboots for the final time, close LSMA.

Reboot to the bootloader again:

adb reboot bootloader

Flash boot:

fastboot flash boot magisk_patched.img

Reboot:

fastboot reboot

Upon reboot, you're now updated, and root & data is preserved.