[SCRIPTS] IMEI backup/restore scripts (pds partition)

Search This thread

eastdata

Senior Member
Apr 17, 2011
108
38
Hello,
Here are a couple of scripts to backup and restore the device IMEI. They won't help with a lost IMEI. Use them to backup your pds partition that store all the device specific data just in case they are lost. They should also be compatible with any device that has the same partitioning as our Moto G (eg Moto X).

Requirements:
- Device has to be rooted, with USB debugging enabled.
- Motorola fastboot (see attachment).
- ADB installed, minimal or the full ADK.
You can search the forum to find how to meet these requirements or for the terms described in this post beginning here:
http://xdaforums.com/showthread.php?t=2558638

Installation:
Extract imei_scripts.zip (attached) and copy the scripts "imei_backup.bat" and "imei_flash.bat" into the ADB root directory.
Extract mfastboot_only.zip (attached) and copy "mfastboot.exe" into the ADB root directory.

Description/How to use:
These are batch scripts and can be run by double-clicking them or opening a command window from the ADB root. Help is also contained in the scripts. They are run interactively and won't execute anything without the user selecting a choice.

"imei_backup.bat"
Use this script to backup and restore normally using ADB.

"imei_flash.bat"
Use this script to flash the partition as an alternative to the other method using mfastboot while in bootloader mode. The backup, "pds.img" must be located in the ADB directory for the script to run.

The backup is made on the sdcard and is named "pds.img". You'll want to store this elsewhere once backed up. Once done, that's it! You don't need to do anything more. The purpose is as a preventative in the event of the loss of your IMEI. :)

Run the scripts for additional options and help.:angel:

The contents of "imei_backup.bat" (use this script to backup and restore IMEI):
Code:
@ECHO OFF

:: 2014-03-09 script by eastdata @ XDA

:: run script from ADB root
IF NOT EXIST adb.exe (
	ECHO.
	ECHO This script must be run in the ADB root directory.
	ECHO.
	PAUSE
	EXIT /B 0
)

:: set path
SET PATH=.;%PATH%
:: unset android serial if set by dev
SET ANDROID_SERIAL=


:options
CLS
ECHO.
ECHO Moto G and compatible IMEI backup/restore script
ECHO.
ECHO   The device must have root permissions to perform the backup/restore functions in this script (su). USB debugging must be enabled. The backup must be in the sdcard root for restore.
ECHO.
ECHO   The backup will be created in the sdcard directory as "pds.img". The backup can be copied to/from the ADB directory using the script file functions. Use with caution, you won't be prompted again if you choose to restore the pds partition. Store the backup securely either locally or online for later recovery.
ECHO.
ECHO   DISCLAIMER: Use this script only at your own risk!
ECHO.
ECHO Options:-
ECHO.
ECHO   backup:
ECHO         b    - backup pds partition
ECHO.
ECHO   restore:
ECHO         r    - restore pds partition
ECHO.
ECHO   file functions:
ECHO         p    - copy backup from sdcard to pc
ECHO         s    - copy backup from pc to sdcard
ECHO         d    - delete backup from sdcard
ECHO.
ECHO   other:
ECHO         q    - quit
ECHO.
SET /P option="Select an option [b|r|p|s|d|q]: "
ECHO.

SET bad_option=1

:: backup to sdcard
IF /I "%option%" == "b" (
	ECHO Performing backup...
	adb shell su -c "dd if=/dev/block/platform/msm_sdcc.1/by-name/pds of=/sdcard/pds.img"
	GOTO :proc_end
)

:: restore from sdcard
IF /I "%option%" == "r" (
	ECHO Performing restore...
	adb shell su -c "dd if=/sdcard/pds.img of=/dev/block/platform/msm_sdcc.1/by-name/pds"
	GOTO :proc_end
)

:: copy to pc (pull)
IF /I "%option%" == "p" (
	ECHO Performing copy to pc...
	adb pull /sdcard/pds.img
	GOTO :proc_end
)

:: copy to sdcard (push)
IF /I "%option%" == "s" (
	ECHO Performing copy to sdcard...
	adb push pds.img /sdcard/pds.img
	GOTO :proc_end
)

:: delete from sdcard (rm)
IF /I "%option%" == "d" (
	ECHO Performing delete from sdcard...
	adb shell rm /sdcard/pds.img
	GOTO :proc_end
)

:: quit script
IF /I "%option%" == "q" (
	EXIT /B 0
)

:: bad option
IF %bad_option% == 1 (
	ECHO Bad option.
	GOTO :proc_end
)

:proc_end
ECHO.
PAUSE
GOTO :options

The contents of "imei_flash.bat" (alternative to restore IMEI using mfastboot):
Code:
@ECHO OFF

:: 2014-03-09 script by eastdata @ XDA

:: run script from ADB root
IF NOT EXIST adb.exe (
	ECHO.
	ECHO This script must be run in the ADB root directory.
	ECHO.
	PAUSE
	EXIT /B 0
)

:: require Motorola fastboot
IF NOT EXIST mfastboot.exe (
	ECHO.
	ECHO This script requires Motorola fastboot renamed "mfastboot.exe" in the ADB directory.
	ECHO.
	PAUSE
	EXIT /B 0
)

:: is there an existing backup?
IF NOT EXIST pds.img (
	ECHO.
	ECHO Backup file "pds.img" not found in the ADB directory.
	ECHO.
	PAUSE
	EXIT /B 0
)

:: set path
SET PATH=.;%PATH%
:: unset android serial if set by dev
SET ANDROID_SERIAL=


:options
CLS
ECHO.
ECHO Moto G and compatible IMEI flash script
ECHO.
ECHO   The device must be in bootloader mode to flash the pds partition. Use the device functions to reboot into the bootloader. Use with caution, you won't be prompted again if you choose to flash the pds partition.
ECHO.
ECHO   DISCLAIMER: Use this script only at your own risk!
ECHO.
ECHO Options:-
ECHO.
ECHO   flash:
ECHO         f    - flash pds partition
ECHO.
ECHO   device functions:
ECHO         b    - reboot into bootloader (adb)
ECHO         r    - reboot (mfastboot)
ECHO.
ECHO   other:
ECHO         q    - quit
ECHO.
SET /P option="Select an option [f|b|r|q]: "
ECHO.

SET bad_option=1

:: flash partition
IF /I "%option%" == "f" (

	FOR /F "usebackq tokens=1" %%C in (`mfastboot devices ^| find /C "fastboot"`) DO (

		IF %%C% EQU 1 (
			ECHO Performing flash...
			mfastboot flash pds pds.img
		) ELSE (
			ECHO Device not found or too many devices, reboot device into bootloader or disconnect any other devices.
		)

	)

	GOTO :proc_end
)

:: reboot bootloader
IF /I "%option%" == "b" (
	ECHO Performing reboot into bootloader, please wait for the device to become ready...
	adb reboot-bootloader
	GOTO :proc_end
)

:: reboot
IF /I "%option%" == "r" (
	ECHO Performing reboot, please wait for the device to become ready...
	mfastboot reboot
	GOTO :proc_end
)

:: quit script
IF /I "%option%" == "q" (
	EXIT /B 0
)

:: bad option
IF %bad_option% == 1 (
	ECHO Bad option.
	GOTO :proc_end
)

:proc_end
ECHO.
PAUSE
GOTO :options

DISCLAIMER: I've tried to make the scripts foolproof, but in the event that you lose data or they corrupt/break your phone, I won't be held responsible. That is, use only at your own risk!
 

Attachments

  • imei_scripts.zip
    2 KB · Views: 5,304
  • mfastboot_only.zip
    219.3 KB · Views: 3,303

rgonera

Member
Mar 17, 2014
8
1
Hello,
DISCLAIMER: I've tried to make the scripts foolproof, but in the event that you lose data or they corrupt/break your phone, I won't be held responsible. That is, use only at your own risk!

What happens if you restore your imei with a different file from the origin of our phone ?
 

nikky2u20

Senior Member
May 1, 2013
135
41
Pune
Unable to get backup of IMEI

Hi,

I am not able to get backup of IMEI.

I am getting error "Device not found"

However i am able to fine my device using command "fastboot Devices"
 

xips

Senior Member
Feb 29, 2012
78
14
Nexus 7
Moto G
I remember when I first ran the batch I had the same problem. Immediate panic set it in. I thought I had already lost the partition. I am still fuzzy on exactly how the job ran successfully. I should have taken notes.

I assumed there would be no screen requests, so I didn't watch the phone. On successful (i hope) run I vaguely recall getting the job to run by authorizing a request on the phone.
 

deej_roamer

Senior Member
Mar 19, 2014
359
643
Do we actually have a reason now, why people are loosing their pds partition?

I don't think anyone should loose their pds partitions untill and unless someone is doing something nasty.

I mean in all the firmwares and roms, no-one disturbs partitions like pds.
I guess only way for someone to loose a pds is if they manually flash the pds partition with something funny!
 

samwathegreat

Senior Member
Apr 17, 2010
2,096
1,843
I don't think anyone should loose their pds partitions untill and unless someone is doing something nasty.

I mean in all the firmwares and roms, no-one disturbs partitions like pds.
I guess only way for someone to loose a pds is if they manually flash the pds partition with something funny!


I'm hoping a dev will comment on this:

I'm wondering if perhaps we have discovered a method of unlocking our bootloaders...

Imagine you have a dev edition moto X (or carrier unlockable device). Would it be possible to backup the PDS partition, and restore it to an unlockable device such as the AT&T Moto X that has been rooted using the rockmymoto exploit?

If possible, then we should be able to use the same bootloader unlock CODE (token) from Motorola that was used to unlock the donor phone, right? As I understand it the token is verified based on data from the bootloader and PDS...could always be wrong of course.

Anyways, once successfully unlocked, we could restore our PDS partition (giving us back original IMEI/MEID) but with the added benefit of unlocked bootloader.

Ideas?
 

deej_roamer

Senior Member
Mar 19, 2014
359
643
I'm hoping a dev will comment on this:

I'm wondering if perhaps we have discovered a method of unlocking our bootloaders...

Imagine you have a dev edition moto X (or carrier unlockable device). Would it be possible to backup the PDS partition, and restore it to an unlockable device such as the AT&T Moto X that has been rooted using the rockmymoto exploit?

If possible, then we should be able to use the same bootloader unlock CODE (token) from Motorola that was used to unlock the donor phone, right? As I understand it the token is verified based on data from the bootloader and PDS...could always be wrong of course.

Anyways, once successfully unlocked, we could restore our PDS partition (giving us back original IMEI/MEID) but with the added benefit of unlocked bootloader.

Ideas?

I guess this needs a comment from a dev! It would be a big help! Still useless for phones that do not have exploit like rockmymoto!
 

Boss442

Senior Member
Jul 19, 2012
428
551
28
Mar Del Plata
I'm hoping a dev will comment on this:

I'm wondering if perhaps we have discovered a method of unlocking our bootloaders...

Imagine you have a dev edition moto X (or carrier unlockable device). Would it be possible to backup the PDS partition, and restore it to an unlockable device such as the AT&T Moto X that has been rooted using the rockmymoto exploit?

If possible, then we should be able to use the same bootloader unlock CODE (token) from Motorola that was used to unlock the donor phone, right? As I understand it the token is verified based on data from the bootloader and PDS...could always be wrong of course.

Anyways, once successfully unlocked, we could restore our PDS partition (giving us back original IMEI/MEID) but with the added benefit of unlocked bootloader.

Ideas?
Maybe work, but cid partition is the partition that do the tokens i think

Enviado desde mi Moto G mediante Tapatalk
 

Top Liked Posts

  • There are no posts matching your filters.
  • 9
    Hello,
    Here are a couple of scripts to backup and restore the device IMEI. They won't help with a lost IMEI. Use them to backup your pds partition that store all the device specific data just in case they are lost. They should also be compatible with any device that has the same partitioning as our Moto G (eg Moto X).

    Requirements:
    - Device has to be rooted, with USB debugging enabled.
    - Motorola fastboot (see attachment).
    - ADB installed, minimal or the full ADK.
    You can search the forum to find how to meet these requirements or for the terms described in this post beginning here:
    http://xdaforums.com/showthread.php?t=2558638

    Installation:
    Extract imei_scripts.zip (attached) and copy the scripts "imei_backup.bat" and "imei_flash.bat" into the ADB root directory.
    Extract mfastboot_only.zip (attached) and copy "mfastboot.exe" into the ADB root directory.

    Description/How to use:
    These are batch scripts and can be run by double-clicking them or opening a command window from the ADB root. Help is also contained in the scripts. They are run interactively and won't execute anything without the user selecting a choice.

    "imei_backup.bat"
    Use this script to backup and restore normally using ADB.

    "imei_flash.bat"
    Use this script to flash the partition as an alternative to the other method using mfastboot while in bootloader mode. The backup, "pds.img" must be located in the ADB directory for the script to run.

    The backup is made on the sdcard and is named "pds.img". You'll want to store this elsewhere once backed up. Once done, that's it! You don't need to do anything more. The purpose is as a preventative in the event of the loss of your IMEI. :)

    Run the scripts for additional options and help.:angel:

    The contents of "imei_backup.bat" (use this script to backup and restore IMEI):
    Code:
    @ECHO OFF
    
    :: 2014-03-09 script by eastdata @ XDA
    
    :: run script from ADB root
    IF NOT EXIST adb.exe (
    	ECHO.
    	ECHO This script must be run in the ADB root directory.
    	ECHO.
    	PAUSE
    	EXIT /B 0
    )
    
    :: set path
    SET PATH=.;%PATH%
    :: unset android serial if set by dev
    SET ANDROID_SERIAL=
    
    
    :options
    CLS
    ECHO.
    ECHO Moto G and compatible IMEI backup/restore script
    ECHO.
    ECHO   The device must have root permissions to perform the backup/restore functions in this script (su). USB debugging must be enabled. The backup must be in the sdcard root for restore.
    ECHO.
    ECHO   The backup will be created in the sdcard directory as "pds.img". The backup can be copied to/from the ADB directory using the script file functions. Use with caution, you won't be prompted again if you choose to restore the pds partition. Store the backup securely either locally or online for later recovery.
    ECHO.
    ECHO   DISCLAIMER: Use this script only at your own risk!
    ECHO.
    ECHO Options:-
    ECHO.
    ECHO   backup:
    ECHO         b    - backup pds partition
    ECHO.
    ECHO   restore:
    ECHO         r    - restore pds partition
    ECHO.
    ECHO   file functions:
    ECHO         p    - copy backup from sdcard to pc
    ECHO         s    - copy backup from pc to sdcard
    ECHO         d    - delete backup from sdcard
    ECHO.
    ECHO   other:
    ECHO         q    - quit
    ECHO.
    SET /P option="Select an option [b|r|p|s|d|q]: "
    ECHO.
    
    SET bad_option=1
    
    :: backup to sdcard
    IF /I "%option%" == "b" (
    	ECHO Performing backup...
    	adb shell su -c "dd if=/dev/block/platform/msm_sdcc.1/by-name/pds of=/sdcard/pds.img"
    	GOTO :proc_end
    )
    
    :: restore from sdcard
    IF /I "%option%" == "r" (
    	ECHO Performing restore...
    	adb shell su -c "dd if=/sdcard/pds.img of=/dev/block/platform/msm_sdcc.1/by-name/pds"
    	GOTO :proc_end
    )
    
    :: copy to pc (pull)
    IF /I "%option%" == "p" (
    	ECHO Performing copy to pc...
    	adb pull /sdcard/pds.img
    	GOTO :proc_end
    )
    
    :: copy to sdcard (push)
    IF /I "%option%" == "s" (
    	ECHO Performing copy to sdcard...
    	adb push pds.img /sdcard/pds.img
    	GOTO :proc_end
    )
    
    :: delete from sdcard (rm)
    IF /I "%option%" == "d" (
    	ECHO Performing delete from sdcard...
    	adb shell rm /sdcard/pds.img
    	GOTO :proc_end
    )
    
    :: quit script
    IF /I "%option%" == "q" (
    	EXIT /B 0
    )
    
    :: bad option
    IF %bad_option% == 1 (
    	ECHO Bad option.
    	GOTO :proc_end
    )
    
    :proc_end
    ECHO.
    PAUSE
    GOTO :options

    The contents of "imei_flash.bat" (alternative to restore IMEI using mfastboot):
    Code:
    @ECHO OFF
    
    :: 2014-03-09 script by eastdata @ XDA
    
    :: run script from ADB root
    IF NOT EXIST adb.exe (
    	ECHO.
    	ECHO This script must be run in the ADB root directory.
    	ECHO.
    	PAUSE
    	EXIT /B 0
    )
    
    :: require Motorola fastboot
    IF NOT EXIST mfastboot.exe (
    	ECHO.
    	ECHO This script requires Motorola fastboot renamed "mfastboot.exe" in the ADB directory.
    	ECHO.
    	PAUSE
    	EXIT /B 0
    )
    
    :: is there an existing backup?
    IF NOT EXIST pds.img (
    	ECHO.
    	ECHO Backup file "pds.img" not found in the ADB directory.
    	ECHO.
    	PAUSE
    	EXIT /B 0
    )
    
    :: set path
    SET PATH=.;%PATH%
    :: unset android serial if set by dev
    SET ANDROID_SERIAL=
    
    
    :options
    CLS
    ECHO.
    ECHO Moto G and compatible IMEI flash script
    ECHO.
    ECHO   The device must be in bootloader mode to flash the pds partition. Use the device functions to reboot into the bootloader. Use with caution, you won't be prompted again if you choose to flash the pds partition.
    ECHO.
    ECHO   DISCLAIMER: Use this script only at your own risk!
    ECHO.
    ECHO Options:-
    ECHO.
    ECHO   flash:
    ECHO         f    - flash pds partition
    ECHO.
    ECHO   device functions:
    ECHO         b    - reboot into bootloader (adb)
    ECHO         r    - reboot (mfastboot)
    ECHO.
    ECHO   other:
    ECHO         q    - quit
    ECHO.
    SET /P option="Select an option [f|b|r|q]: "
    ECHO.
    
    SET bad_option=1
    
    :: flash partition
    IF /I "%option%" == "f" (
    
    	FOR /F "usebackq tokens=1" %%C in (`mfastboot devices ^| find /C "fastboot"`) DO (
    
    		IF %%C% EQU 1 (
    			ECHO Performing flash...
    			mfastboot flash pds pds.img
    		) ELSE (
    			ECHO Device not found or too many devices, reboot device into bootloader or disconnect any other devices.
    		)
    
    	)
    
    	GOTO :proc_end
    )
    
    :: reboot bootloader
    IF /I "%option%" == "b" (
    	ECHO Performing reboot into bootloader, please wait for the device to become ready...
    	adb reboot-bootloader
    	GOTO :proc_end
    )
    
    :: reboot
    IF /I "%option%" == "r" (
    	ECHO Performing reboot, please wait for the device to become ready...
    	mfastboot reboot
    	GOTO :proc_end
    )
    
    :: quit script
    IF /I "%option%" == "q" (
    	EXIT /B 0
    )
    
    :: bad option
    IF %bad_option% == 1 (
    	ECHO Bad option.
    	GOTO :proc_end
    )
    
    :proc_end
    ECHO.
    PAUSE
    GOTO :options

    DISCLAIMER: I've tried to make the scripts foolproof, but in the event that you lose data or they corrupt/break your phone, I won't be held responsible. That is, use only at your own risk!
    1
    Do we actually have a reason now, why people are loosing their pds partition?

    The reason is i didnt make pds partition when everything was OK.. So now, im looking for a generous donater who wanna share his own one.
    1
    I'm not aware of anyone that has actually repaired a lost IMEI by restoring the PDS partition. This is however the most likely location where it would be stored and hence why it is suggested you make a backup of it.

    XDA user drfr has repaired his IMEI problem by removing SIM and fastboot flashing new firmware. His story here:

    I'll assume you ran the command "fastboot erase all"? Think I'll suggest it get added to FAQ to prevent future lost souls haunting this thread.
    1
    • Flashed the full GPE 4.4.4, but recovery and boot.img wouldn't flash (Have a XT1032 GB Retail).
    • Full Retail GB 4.4.4 ROM got installed without any errors.
    • Phone boots and Play Store works now. So slightly less of a brick than earlier.
    • BUT still no IMEI.
    I think you should be able to flash everything including recovery and boot.img without error. Try the different versions of fastboot in this zip: https://www.androidfilehost.com/?fid=23578570567719065
    1