EFS + persist partitions backup guide
RafAfter you unlock your bootloader, before you flash any custom ROM/kernel, make sure you take a backup of persist and efs partitions in case anything goes wrong in the future such as lost/blank/corrupted IMEI, lost Widevine L1 etc.
• Right after unlocking your bootloader, root MIUI either by flashing Magisk zip or by following the "patching images" guide to patch your boot.img using the Magisk app. (Use #root and #magisk notes)
• Download and install Termux app (Play Store version hasn't been updated since 09/2020)
If you want to take a backup of all your device's partitions: (thanks to @mochi_wwww)
• type "su", then enter, give root permission to Termux, then "mkdir /sdcard/backup" (this will create a folder named backup in your internal storage)
• then "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/backup/${f}.img; done" (this should take about 30-40 seconds and will backup all partitions in the backup folder)
• Now copy the backup folder from your internal storage somewhere safe on your PC/external drive/cloud.
If you want to take a backup of your persist + EFS only:
• type "su", then enter, give root permission to Termux
• then "dd if=/dev/block/bootdevice/by-name/persist of=/sdcard/persist.img", then enter. This will create a file named persist.img in your internal storage.
• For EFS, flash TWRP (use #twrp note), boot to it, choose Backup, check only EFS partition and take a backup of it.
• Now copy persist.img and TWRP folder from your internal storage somewhere safe on your PC/external drive/cloud.