Skip to content

Instantly share code, notes, and snippets.

@muink
Created November 8, 2025 14:53
Show Gist options
  • Select an option

  • Save muink/d3cb6856ef0d0886a0f0b038d69faa8c to your computer and use it in GitHub Desktop.

Select an option

Save muink/d3cb6856ef0d0886a0f0b038d69faa8c to your computer and use it in GitHub Desktop.
Android root Backup and Restore

Android Boot users Backup and Restore

Users that are new to rooting and/or with a new device NEED to back up critical partitions related to signal and fingerprint.

Backup

adb kill-server
adb devices

adb shell
bakdir=my_backup_$(date --utc "+%Y%m%dT%H%M%S")
su -c mkdir /tmp/$bakdir
# EFS (baseband)
su -c dd if=/dev/block/bootdevice/by-name/fsc      of=/tmp/$bakdir/fsc.img
su -c dd if=/dev/block/bootdevice/by-name/fsg      of=/tmp/$bakdir/fsg.img
# modemst1 (Contains IMEI)
su -c dd if=/dev/block/bootdevice/by-name/modemst1 of=/tmp/$bakdir/modemst1.img
# modemst2 (Contains IMEI)
su -c dd if=/dev/block/bootdevice/by-name/modemst2 of=/tmp/$bakdir/modemst2.img
# ocdt (Contains device identifers)
su -c dd if=/dev/block/bootdevice/by-name/ocdt     of=/tmp/$bakdir/ocdt.img
# persist (Contains Attestation Key and security items)
su -c dd if=/dev/block/bootdevice/by-name/persist  of=/tmp/$bakdir/persist.img
# metadata (FBE key stoarge)
# You should back it up along with  `userdata` partition.
su -c dd if=/dev/block/bootdevice/by-name/metadata of=/tmp/$bakdir/metadata.img
exit

adb pull /tmp/my_backup_*

Restore

adb kill-server
adb devices

adb reboot fastboot

fastboot flash fsc      fsc.img
fastboot flash fsg      fsg.img
fastboot flash modemst1 modemst1.img
fastboot flash modemst2 modemst2.img
fastboot flash ocdt     ocdt.img
fastboot flash persist  persist.img
# do not restore it unless your `userdata` cannot be decrypted.
fastboot flash metadata metadata.img

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