Magisk Manager — Stock backup does not exist

asheroto
3 min readMay 25, 2023
Magisk Manager logo

When using Magisk Manager, are you get the error Stock backup does not exist when tapping Restore Images? There’s a fix for that!

Thanks to pexcn for posting the commands.

You don’t need to boot into the bootloader, simply run these commands while the Android is running.

NOTE: It is highly recommended that you perform a backup of the partitions and files before you begin just in case something goes wrong.

Here are the steps in order:

  • A checksum is a concise combination of alphanumeric characters used to uniquely identify a file based on its content. When the checksum value matches the value you’re comparing it with, it indicates that the file’s content is identical to the expected content. This way we can know for sure that we’re dealing with the correct file. The checksum is NOT case sensitive.
  • Make sure to run the checksum verification commands in a separate window, not in the same window as the adb, gzip, or mkdir, etc, commands.
  • Get the SHA1 checksum of the boot image from the Magisk config. This is the file hash of the boot.img file that Magisk is trying to restore, but is missing. This does not calculate the hash, rather it only retrieves the expected hash from the .config text file on the Android.
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)
  • That will set the SHA1 variable to the SHA1 checksum value.
  • Now type…
echo $SHA1
  • That will output the value. Your value may be different, but in my case, the value was…
f902a87747a1076f1568d33e8083d9454cfe8e3d
  • That is the file hash that Magisk is expecting.
  • Find the original boot.img file from the OTA ROM image installed on your Android. You want the original image, not the patched image. You’ll want to Google <your model> OTA ROM image or <your model OTA ROM boot image and locate the expected boot image. Or use Oxygen Updater and get the full version.
  • If the image extension is something other than .img such as .img.gz or .img.zst then you must extract that image until you get the boot.img file itself.
  • If you only have a payload.bin file, you’ll need to use payload_dumper to dump the payload.
  • Keep searching for your Android OTA ROM version until you find the matching SHA1 checksum.
  • You can verify you have the right image by checking the image’s checksum. You may be able to simply Google the SHA1 checksum value and see if it’s posted online. Just make sure it’s actually the right file by calculating the hash!
  • In a separate window in PowerShell, run the command…
(Get-FileHash -Path .\boot.img -Algorithm SHA1).Hash.ToLower()
  • In a separate window on Linux, the command is
sha1sum boot.img
  • Once you’ve confirmed you have the right image, rename the file to boot-stock.img.
  • Push the image on to your Android using this command:
    adb push .\boot-stock.img /sdcard/boot-stock.img
  • With the boot-stock.img on the Android, compress the file into gzip format:
gzip -9f /sdcard/boot-stock.img
  • Now we can restore the backup:
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/boot-stock.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}

That should do it! Refer to the original GitHub Gist for discussion and more information.

If something goes wrong, you can flash the boot image using fastboot. Check out this post for more information. Also on A/B devices, if something goes wrong you can switch back to the other slot. First find out which slot you’re using…

fastboot getvar current-slot

Then switch the slot using…


fastboot --set-active=b

Where “b” is the other slot.

WARNING: If you have a new phone, switching the active slot may brick the device, resulting in recovery only through EDL download mode. Make sure you’ve updated the phone to a new OTA release at least once.

Consider becoming a Medium member if you appreciate reading stories like this and want to help me as a writer. It costs $5 per month and gives you unlimited access to Medium content. I’ll get a little commission if you sign up via my link.

--

--

asheroto

🌎 Full Stack Developer 🔗 Systems Administrator 😎Innovation through Automation ✔ Privacy Advocate ♥ Startup Facilitator