Guide to Backing Up Essential Partitions After Unlocking Your Device's Bootloader
SpikeWHY EVEN BOTHER?
- After unlocking your bootloader, it is essential to back up critical partitions such as persist, modemst, fsg and so before flashing any custom ROMs or kernels.
- These partitions contain vital information, including your device's IMEI and network settings and even fod stuff, which, if lost or corrupted, can lead to issues like loss of cellular connectivity or a bricked device/component.
- By creating backups of these important partitions, you ensure that you can restore your device to a functional state in case anything goes wrong during the customization process, allowing you to experiment with confidence while safeguarding your device's functionality.
- So this is probably the first thing you should be doing after bootloader unlocking and rooting your device.
REQUIREMENTS:
1. Unlocked bootloader
2. Root access
Assuming that no modifications were made to any partitions except boot / init_boot / recovery (obviously for flashing patched images for rooting via magisk/ksu/apatch and custom recovery if any)
3. Install Termux app (Preferably from fdroid / playstore)
BACKUP INSTRUCTIONS:
It is recommended to not share the backups of critical partitions like imei, persist and so on with anyone cuz certain partitions are device specific and you don't want someone to be roaming around with your imei for eg. Also flashing a persist from a different device in some cases can render the fingerprint sensor non-functional!
1. Grant superuser / root access to termux app via magisk / ksu / apatch manager.
2. Open termux app and type "su" to gain root acccess. Then copy and paste the following commands one by one in same order as stated below based on the scenario that your device fits in:
A. For devices with existing path "/dev/block/bootdevice/by-name" (usually for QCom Platform) (check via any root file manager for existence):
Copy paste these cmds in one go in termux:
mkdir -p /sdcard/partitions_backup
ls -1 /dev/block/bootdevice/by-name | grep -v userdata | grep -v super | while read f; do dd if=/dev/block/bootdevice/by-name/$f of=/sdcard/partitions_backup/${f}.img; done
This will create image files of all partitions except super and userdata to a folder named "partitions_backup" in Internal Storage of the device.
[Optional] In case case the above cmds fail to work, try this:
mkdir -p /sdcard/partitions_backup; for partition in /dev/block/bootdevice/by-name/*; do [[ "$(basename "$partition")" != "userdata" && "$(basename "$partition")" != "super" ]] && cp -f "$partition" /sdcard/partitions_backup/; done
B. For devices with existing path: "/dev/block/by-name/" (usually MTK platform)
Copy paste all the cmds in termux in one go as stated below:
mkdir -p /sdcard/partitions_backup/
cd /sdcard/partitions_backup
mkdir -p /sdcard/partitions_backup/
cd /sdcard/partitions_backup
dd if=/dev/block/by-name/nvram of=/sdcard/partitions_backup/nvram.img
dd if=/dev/block/by-name/nvdata of=/sdcard/partitions_backup/nvdata.img
dd if=/dev/block/by-name/persist of=/sdcard/partitions_backup/persist.img
dd if=/dev/block/by-name/nvcfg of=/sdcard/partitions_backup/nvcfg.img
dd if=/dev/block/by-name/protect1 of=/sdcard/partitions_backup/protect1.img
dd if=/dev/block/by-name/protect2 of=/sdcard/partitions_backup/protect2.img
3. Now transfer the "partitions_backup" folder to your PC or any other forms of secure storage for future reference if required to serve as a backup.
4. For backing up a specific partitions instead you can use the cmds based on existence of "bootdevice" paths as per your device's soc platform:
dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/<partition name>.img (qcom)
or
dd if=/dev/block/by-name/persist of=/sdcard/partitions_backup/persist.img (mtk)
RESTORATION:
MTK users can restore their IMEI and fingerprint sensor info by:
fastboot flash nvram nvram.img
fastboot flash nvdata nvdata.img
fastboot flash nvcfg nvcfg.img
fastboot flash persist persist.img
This should be followed by rebooting to the recovery mode and performing a factory reset before rebooting to the system itself after flashing.
QCOM users can restore their persist and modem related changes (factory reset is not mandatory after flashing though)
fastboot flash persist persist.img
fastboot flash modemst1 modemst1.img
fastboot flash modemst2 modemst2.img