Skip to content

Instantly share code, notes, and snippets.

@pexcn
Last active April 8, 2024 01:05
Show Gist options
  • Save pexcn/71d7d242c5e805d9346d2dc9db17fb90 to your computer and use it in GitHub Desktop.
Save pexcn/71d7d242c5e805d9346d2dc9db17fb90 to your computer and use it in GitHub Desktop.

Fix magisk stock backup does not exist

# put stock boot.img into /sdcard/boot.img

# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)

# repack boot.img.gz
gzip -9f /sdcard/boot-stock.img

# restore 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}
@karlicoss
Copy link

Note that Pixel 7 Pro (and possibly other newer Pixel phones) are using init_boot.img -- so you need to repack this file (not boot.img which is also present in the OTA image!) and put /data/magisk_backup_${SHA1}/boot.img.gz (yes, the latter path still is boot.img.gz)
Otherwise great manual, thanks!

@Originalimoc
Copy link

mark

@asheroto
Copy link

asheroto commented Feb 6, 2024

It appears that Android 14 uses init_boot.img and boot.img if I'm not mistaken? At least one OnePlus phones...

@giser
Copy link

giser commented Feb 6, 2024

In case of init_boot.img

# put stock init_boot.img into /sdcard/init_boot.img

# get sha1
adb shell
su
SHA1=$(cat $(magisk --path)/.magisk/config | grep SHA1 | cut -d '=' -f 2)

# repack init_boot.img.gz
gzip -9f /sdcard/init_boot.img

# restore backup
mkdir /data/magisk_backup_${SHA1}
mv /sdcard/init_boot.img.gz /data/magisk_backup_${SHA1}/boot.img.gz
chmod -R 755 /data/magisk_backup_${SHA1}
chown -R root.root /data/magisk_backup_${SHA1}

@stanleylhs
Copy link

Everyone, there's no need to calculate sha or write your own script, just use util_function.sh from the magisk folder in adb. Topjohnwu has updated it for init_boot months ago.

Follow this comment for instruction. https://gist.github.com/pexcn/71d7d242c5e805d9346d2dc9db17fb90?permalink_comment_id=4330260#gistcomment-4330260

@asheroto
Copy link

asheroto commented Feb 6, 2024

@giser have you tested this? Looks like it might work if when extracted it just overwrites the init_boot.img partition.

@stanleylhs indeed, but this fix doesn't always work as expected.

@altwu
Copy link

altwu commented Apr 8, 2024

my phone is rooted but no /data/magisk_backup_* directories exist, so i tried to get magisk to create one. i tried using the app to patch a file. a patched boot image was created but no /data/magisk_backup_* directory. the path to the boot image was /sdcard/Documents/boot_images/init_boot_14_0_0_304.img. i tried copying it and giving it the name /sdcard/Documents/boot_images/init_boot.img and patching it. a patched boot image was created but still no /data/magisk_backup_* directory.

my phone is a US oneplus 11(cph2451) running android 14 and magisk 27.0 stable. how do i get the magisk app to patch a file and create a /data/magisk_backup_* directory?

i tried using util_functions.sh and run_migrations and that worked.

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