Skip to content

Instantly share code, notes, and snippets.

@pexcn
Last active July 25, 2024 18:07
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}
@hubbty
Copy link

hubbty commented Jul 7, 2024

My Pixel 4a 5G aka bramble runs LineageOS for microG. I've installed Magisk via patched boot.img. Therefore Magisk ought to have backuped stock boot.image already on that occasion. But it did not. Additionally I let Magisk patch stock boot.img several times after installation, in the hope it would then create a backup, which it did never.
The magisk_install.log from last installation is this:

- Device platform: arm64-v8a
- Installing: 27.0 (27000)
- Copying image to cache
- Unpacking boot image
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
HEADER_VER      [3]
KERNEL_SZ       [11744698]
RAMDISK_SZ      [2559738]
OS_VERSION      [14.0.0]
OS_PATCH_LEVEL  [2024-05]
PAGESIZE        [4096]
CMDLINE         []
KERNEL_FMT      [lz4]
RAMDISK_FMT     [lz4_legacy]
unexpected ASN.1 DER tag: expected SEQUENCE, got APPLICATION [1] (primitive)
VBMETA
- Checking ramdisk status
Loading cpio: [ramdisk.cpio]
- Stock boot image detected
- Patching ramdisk
- Pre-init storage partition: sda15
Loading cpio: [ramdisk.cpio]
Add file [init] (100750)
Create directory [overlay.d] (0750)
Create directory [overlay.d/sbin] (0750)
Add file [overlay.d/sbin/magisk32.xz] (100644)
Add file [overlay.d/sbin/magisk64.xz] (100644)
Add file [overlay.d/sbin/stub.xz] (100644)
Patch with flag KEEPVERITY=[true] KEEPFORCEENCRYPT=[true]
Loading cpio: [ramdisk.cpio.orig]
Backup [init] -> [.backup/init.xz]
Record new entry: [overlay.d] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/magisk32.xz] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/magisk64.xz] -> [.backup/.rmlist]
Record new entry: [overlay.d/sbin/stub.xz] -> [.backup/.rmlist]
Create directory [.backup] (0000)
Add file [.backup/.magisk] (100000)
Dumping cpio: [ramdisk.cpio]
- Repacking boot image
Parsing boot image: [/data/user_de/0/com.topjohnwu.magisk/install/boot.img]
HEADER_VER      [3]
KERNEL_SZ       [11744698]
RAMDISK_SZ      [2559738]
OS_VERSION      [14.0.0]
OS_PATCH_LEVEL  [2024-05]
PAGESIZE        [4096]
CMDLINE         []
KERNEL_FMT      [lz4]
RAMDISK_FMT     [lz4_legacy]
unexpected ASN.1 DER tag: expected SEQUENCE, got APPLICATION [1] (primitive)
VBMETA
Repack to boot image: [new-boot.img]
HEADER_VER      [3]
KERNEL_SZ       [11744698]
RAMDISK_SZ      [2496732]
OS_VERSION      [14.0.0]
OS_PATCH_LEVEL  [2024-05]
PAGESIZE        [4096]
CMDLINE         []

****************************
 Output file is written to 
 /storage/emulated/0/Download/magisk_patched-27000_Dx8Mh.img 
****************************
cp: can't preserve ownership of 'busybox': Operation not permitted
cp: can't preserve ownership of 'magisk32': Operation not permitted
cp: can't preserve ownership of 'magisk64': Operation not permitted
cp: can't preserve ownership of 'magiskboot': Operation not permitted
cp: can't preserve ownership of 'magiskinit': Operation not permitted
cp: can't preserve ownership of 'magiskpolicy': Operation not permitted
- All done

I wonder, if these not permitted operations are causing this failing to backup the stock boot.img and what I might do about it.

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