2015-08-04, 06:45
Intro
i was asked to write up a little tutorial on how to manually backup the partitions in the newer 64 bit MTK based phones. this should include any of the MT67XX based phones, probably the MT6595, and any Mediatek phone running Android 4.4.4 or higher (that is until Mediatek decides to support Android M/5.2, then this will probably all have to be changed. great job on consistency, Mediatek!). Starting with the ROM images for kitkat 4.4.4, mediatek changed the layout of their filesystem. gone are the days of the MBR/EBR. the flash memory in the newer ROMs have a GPT partition table ( ). This, believe it or not, is actually a really really good thing. for one thing, it makes it much harder for unscrupulous phone manufactures to put a fake amount of memory in the phone (claiming it has 32gb of onboard storage when it only has 4gb). it also means that on the Linux side of android, things are much easier to deal with. on the down side, it breaks compatibility with MTK Droid and Root tools and a lot of the older tools written for the 32 bit mediatek platform. not to worry though, because since Android is essentially linux, we can use some skills to backup our phones the same way that MTK Droid And Root tools did
prerequisites
there are a couple of caveats i will point out before we get started:
ok, so if you have made it this far, and i haven’t scared you off yet, you have a phone and you are prepared to make a SP Flash Tools compatible backup. your phone is rooted, it has busybox installed. you have ADB turned on, and you are able to connect to it with your computer. you have a scatter file for your phone, so that this backup is not just useless. and you are comfortable with using the command line and typing commands. i will include some screen shots. i use a chromebook with linux, and my phone is a Jiayu S3s, though these commands should will work fine on windows and should be able to be adapted to any other MT67xx or MT6595 based phone. so lets get started!
process
step 1: connect your phone with a USB cable
this should be a no-brainer. yes, you can use ADB wirelessly, but i am not going to cover it here. we are going to be working on our device using our computer. be sure you have a high quality USB cable. i can’t stress this enough. i have probably 30 different USB cables. the only one that i am able to do ADB stuff with my phone is the one that came with my Kindle HDX. all the rest are just charging cables.
step 2: open a command prompt of some sort and test to see if your phone is connectable
in windows, you will want to open up a command prompt. in linux, you will want to open up a terminal. either way, get to a command prompt. when you are there, type this:
you should get something like this:
it says the device is attached, it gives my fake jiayu serial number, and says it is a device (look at your phone when you connect it, you will probably get a pop up telling you that something is trying to connect to ADB. just click “ok”)
step 3: shell into your device
now we are going to connect to our device and work directly on it. if you don’t have any experience with linux, you are about to get some. android is based on linux, and for this basic backup directly on the phone, the easiest way to do it is directly on the phone. it will also help you with learning some of the partition names and locations for future reference. so now type:
notice how your command prompt changed… mine now lists a user name (shell) at (@) the computer i am working on (my phone, JY-S3), then the directory location i am on that computer (:/ meaning i am at the root directory), and a prompt telling me what class user i am ($ which means i am non-privliged). so, lets poke around a bit.
linux/unix uses a hierarchical file system. if you are use to windows where you have a C:\, D:\ etc drive listing, you might feel a bit lost. Unix organizes everything starting at the root, refered to as “/”. there are folders or directories off of this. these directories can have specialized files in them, or they can contain a whole different media, or they can just contain files. if you type
it will list what is available at the root file system.
i know there is a lot going on on that screen. we dont have to worry about too much in it. if you read from the left, you will see a bunch of dashes with letters. the only thing you have to worry about at the moment is the “drwx---”. this means that the name all the way to the right is a directory. there are several directories we are going to focus on:
/dev this is a special directory that contains device specific files. it is complicated to describe, but everything in unix is a file. that means the whole flash memory device is just a file. each partition on that device is another file. the screen is a file. the speaker is a file. this is very handy for what we and to do.
/storage this is where file systems are mounted. we want to back up our memory, we have to have a location to put it. it will be on our SD card (hopefully external)
/proc this contains information about the active running system. one of the files can be used to list partitions and generate a scatter file if we need to. just know about this for now, we will look at it in the future.
step 4 get your mount points
because of the way unix works, disks and partitions have individual mount directories. to get a list, just type
there is a lot of information on this screen, and a lot of it can be ignored. there are several things that we do care about however:
/dev/block/platform/mtk-msdc.0/by-name/system /system ext4 rw,seclabel,noatime,nodiratime,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/userdata /data ext4 rw,seclabel,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/cache /cache ext4 rw,seclabel,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/protect1 /protect_f ext4 rw,seclabel,nosuid,nodev,noatime,nodiratime,nodelalloc,noauto_
and
/dev/fuse /storage/sdcard1 fuse rw,nosuid,nodev,noatime,nodiratime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
the first group gives us the /dev location of where the partitions are listed. this is very handy. in my case it is /dev/block/platform/mtk-msdc.0/by-name/. the second one tells me where my external sd card is mounted (though i already knew this because i use my phone)... /dev/fuse /storage/sdcard1 /dev/fuse is the file that is mounted (dont worry about it), and /storage/sdcard1 is where it is mounted. it might be /sdcard, it might be /storage/sdcard0, it all depends on your ROM and how your manufacturer made your phone.
step 6 choose what we want to back up
lets change our directory location to where the partitions are and take a look at what is there, so we can choose what we want to back up. type:
this gives us a list of partitions. some of them are important to backup, some of them don’t really matter. my phone (a Jiayu S3 advanced running Kitkat 4.4.4) shows 19 partitions. your phone may have more or less. it doesn’t matter, because we are only going to backup a couple of these partitions. the other ones are created on the fly by SP Flash Tool when you use it to flash your phone, or you can get the from a current ROM image from your manufacturer. what are important are: boot, lk, logo, nvram, recover, secro, system, cache, and if you want to backup installed apps, userdata. these should be consistently named on whatever phone you are on. you can backup every single partition here if you really want to, but these are all that are really needed. we can also backup the preloader, but without several scripts to clean up the file we backup, it is a useless file. and as anyone who has read anything about SP Flash Tool knows, you should NEVER EVER EVER flash the preloader. there is no need to do it.
step 7 running the backup commands
to backup these partitions, we are going to use a very very old unix tool called dd. dd will read a partition and dump it into a file for us. then this collection of files will be able to be used with SP Flash Tool if we ever need to restore our backup. just a side note, dd has gotten the reputation to be known as “data destroyer” because if you use it incorrectly, it will definitely destroy your data. it is a dumb copy program and all it knows to do is copy bits from one location to another location. if you get your files messed up, or you get confused, it is very easy to write the wrong thing to the wrong file. but as long as you follow the command syntax below, you should be fine. that being said, if you do something stupid, i am not responsible for any bad outcome. you are messing with your phone on a very low level at this point, so be careful.
because we are accessing your system on such a low level, you need root to use it in the way we are going to. if you don't have root access, this will fail.
the command to run, per partition looks something like this:
so lets take an example and dissect it. we will backup the recovery partition. the command will look like this:
so, lets look at the parts:
su -c : this means invoke root powers to run the following command. be sure that the command is surrounded in “”, otherwise it will only run the first command given
dd : dd, the command we are going to use to backup
if=/dev/block/platform/mtk-msdc.0/by-name/recovery : the name of the partition that we are going to back up
of=/storage/sdcard1/recovery.img : the file we are going to copy this partition to.
bs=512 : how many bytes to copy at a time.
it holds for a few seconds and then gives us this output:
32768+0 records in
32768+0 records out
16777216 bytes transferred in 2.537 secs (6613013 bytes/sec)
so the 32768 records in/out shows how many times it copied 512 bytes of data (512 * 32768 = 16777216 bytes). the last line reiterates the total bytes and how long it took. 16777216 is 16 megabytes… my phone has a 16 megabyte recovery partition, so this all checks out.
step 8 full list of commands to back up the needed partitions
we now know how to backup, we just need a list of commands to backup the other needed partitions. just replace the if partition name with what you are backing up next and the of command with the name you are backing it up too.
this provides you a system image backup of your phone. you will probably run in to an issue with the last one. depending on your phone, your userdata partition is going to be from 3gb to 12 gb. with these commands, you are creating one monolithic file. anyone that has experimented with large files on a FAT32 file system (what your external sdcard has) knows that the file size limit is 4gb. if your userdata partition is only 3gb, then you're in luck, and you will be fine. if your partition is larger, like my S3 at 12gb, you will need another option. luckily there is one, but we can address that in the next tutorial.
you also can skip the first line of the backup. it will backup the file that contains the preloader... the problem is that it also backs up extra data that is not part of the preloader. you need to run some commands to modify this file, which will be covered in the next tutorial.
Next Tutorial...
in the next tutorial, i will explain a method to backup your phone using these same commands, but instead of saving them to your internal storage, you can pipe them over your ADB connection and save them directly on your computer. we will go over a basic cygwin install (if you don't run linux, you will need some unix tools to do this, and cygwin provides them). we will also discuss shrinking images (your userdata image may be 12gb, but it is probably several gb of just zeros). and i will discuss methods of generating a scatter file, and ways to modify the space your internal partitions take up.
thanks
yuweng on XDA has been the inspiration for most of this work/research. it was him that provided the listing and location of partition names here
scandium on XDA gave me a solution for backing up the partition over ADB, and though they aren't mentioned in this tutorial, they will be in the next. his method is here
syserr did a lot of work with the early mediatek phones the same time that MTK Droid and Root tools came out. some of his methods are used in chunking up entire flash backups. he also created a method for fixing the wonky preloader backup that this script creates.
rua1 for being an inspiration with MTK Droid and Root Tools.
i was asked to write up a little tutorial on how to manually backup the partitions in the newer 64 bit MTK based phones. this should include any of the MT67XX based phones, probably the MT6595, and any Mediatek phone running Android 4.4.4 or higher (that is until Mediatek decides to support Android M/5.2, then this will probably all have to be changed. great job on consistency, Mediatek!). Starting with the ROM images for kitkat 4.4.4, mediatek changed the layout of their filesystem. gone are the days of the MBR/EBR. the flash memory in the newer ROMs have a GPT partition table ( ). This, believe it or not, is actually a really really good thing. for one thing, it makes it much harder for unscrupulous phone manufactures to put a fake amount of memory in the phone (claiming it has 32gb of onboard storage when it only has 4gb). it also means that on the Linux side of android, things are much easier to deal with. on the down side, it breaks compatibility with MTK Droid and Root tools and a lot of the older tools written for the 32 bit mediatek platform. not to worry though, because since Android is essentially linux, we can use some skills to backup our phones the same way that MTK Droid And Root tools did
prerequisites
there are a couple of caveats i will point out before we get started:
- 1 i think this is a horrible way to backup your phone. TWRP/CWM and a backup through a custom recovery is a much better option. first of all, this is inline with the rest of the android community, and there are tons of tools out on XDA, the play store, and other forums to work with these types of backups. they are smaller (in general) and they don’t suffer from issues such as files being big (which we will touch on later).
- 2 i understand not everyone has a custom recovery made for their devices, which necessitates a backup like this. i urge you to seek out a custom recovery anyway. check xda-forums, check another forum, check movilesdualsim.com, or contact me and i will try to help you. i have never made a custom recovery, but i have ported several, and i might be able to help you track one down.
- 3 if you are set on this backup (and it is not a bad idea to have one of these hanging around just in case), to use this method, your phone must be rooted and you must have a working copy of busybox installed. there is another way to backup your phone if you phone if you are not rooted using SP Flash Tools readback (
) though the method would have to be changed because the “dumpsplitter’ tool they list will not work on the GPT type rom image. in a future tutorial i will include the script to split up this dump file (or you can p.m. me for it). - 4 you have to have ADB debugging enabled and working with your device. No fancy Mediatek drivers are required for this (the ones you will need for SP Flash Tools) but ADB Debugging has to be enabled on your phone and you have to have ADB installed on your computer. you can get ADB for your windows computer here:
, if you are on linux follow your distribution instructions to install it. to enable ADB on your phone, you will need to go into settings->developer options and turn on ADB. (you actually could install a terminal emulator on your phone and type all these commands in yourself, but i wouldn’t recommend it… also, you can’t pipe your backup to your computer if you do it this way) - 5 you have to have a working SP Flash Tool compatible ROM image already. or at least you need to have a working scatter file. on the old mediatek phones, there was a file on the phone that could be easily dumped and you could create a scatter file out of it (this is what MTK Droid and Root tools did). this file does not exist on the new Mediatek ROMs. there are manual ways to create a scatter file if need be, and i have a little script that can sort of kludge together one, but there are a million different partition types and scatter entries out there based on each individual phone manufacturer. the only way i have found to create a scatter is knowing what each of these partitions are and putting them in to the scatter file by hand. until someone discovers some way to dump a scatter file out of a MT67xx phone, you should have one already.
ok, so if you have made it this far, and i haven’t scared you off yet, you have a phone and you are prepared to make a SP Flash Tools compatible backup. your phone is rooted, it has busybox installed. you have ADB turned on, and you are able to connect to it with your computer. you have a scatter file for your phone, so that this backup is not just useless. and you are comfortable with using the command line and typing commands. i will include some screen shots. i use a chromebook with linux, and my phone is a Jiayu S3s, though these commands should will work fine on windows and should be able to be adapted to any other MT67xx or MT6595 based phone. so lets get started!
process
step 1: connect your phone with a USB cable
this should be a no-brainer. yes, you can use ADB wirelessly, but i am not going to cover it here. we are going to be working on our device using our computer. be sure you have a high quality USB cable. i can’t stress this enough. i have probably 30 different USB cables. the only one that i am able to do ADB stuff with my phone is the one that came with my Kindle HDX. all the rest are just charging cables.
step 2: open a command prompt of some sort and test to see if your phone is connectable
in windows, you will want to open up a command prompt. in linux, you will want to open up a terminal. either way, get to a command prompt. when you are there, type this:
Code:
adb devices
you should get something like this:
it says the device is attached, it gives my fake jiayu serial number, and says it is a device (look at your phone when you connect it, you will probably get a pop up telling you that something is trying to connect to ADB. just click “ok”)
step 3: shell into your device
now we are going to connect to our device and work directly on it. if you don’t have any experience with linux, you are about to get some. android is based on linux, and for this basic backup directly on the phone, the easiest way to do it is directly on the phone. it will also help you with learning some of the partition names and locations for future reference. so now type:
Code:
adb shell
notice how your command prompt changed… mine now lists a user name (shell) at (@) the computer i am working on (my phone, JY-S3), then the directory location i am on that computer (:/ meaning i am at the root directory), and a prompt telling me what class user i am ($ which means i am non-privliged). so, lets poke around a bit.
linux/unix uses a hierarchical file system. if you are use to windows where you have a C:\, D:\ etc drive listing, you might feel a bit lost. Unix organizes everything starting at the root, refered to as “/”. there are folders or directories off of this. these directories can have specialized files in them, or they can contain a whole different media, or they can just contain files. if you type
Code:
ls -l
i know there is a lot going on on that screen. we dont have to worry about too much in it. if you read from the left, you will see a bunch of dashes with letters. the only thing you have to worry about at the moment is the “drwx---”. this means that the name all the way to the right is a directory. there are several directories we are going to focus on:
/dev this is a special directory that contains device specific files. it is complicated to describe, but everything in unix is a file. that means the whole flash memory device is just a file. each partition on that device is another file. the screen is a file. the speaker is a file. this is very handy for what we and to do.
/storage this is where file systems are mounted. we want to back up our memory, we have to have a location to put it. it will be on our SD card (hopefully external)
/proc this contains information about the active running system. one of the files can be used to list partitions and generate a scatter file if we need to. just know about this for now, we will look at it in the future.
step 4 get your mount points
because of the way unix works, disks and partitions have individual mount directories. to get a list, just type
Code:
mount
there is a lot of information on this screen, and a lot of it can be ignored. there are several things that we do care about however:
/dev/block/platform/mtk-msdc.0/by-name/system /system ext4 rw,seclabel,noatime,nodiratime,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/userdata /data ext4 rw,seclabel,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/cache /cache ext4 rw,seclabel,noatime,nodiratime,discard,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/mtk-msdc.0/by-name/protect1 /protect_f ext4 rw,seclabel,nosuid,nodev,noatime,nodiratime,nodelalloc,noauto_
and
/dev/fuse /storage/sdcard1 fuse rw,nosuid,nodev,noatime,nodiratime,user_id=1023,group_id=1023,default_permissions,allow_other 0 0
the first group gives us the /dev location of where the partitions are listed. this is very handy. in my case it is /dev/block/platform/mtk-msdc.0/by-name/. the second one tells me where my external sd card is mounted (though i already knew this because i use my phone)... /dev/fuse /storage/sdcard1 /dev/fuse is the file that is mounted (dont worry about it), and /storage/sdcard1 is where it is mounted. it might be /sdcard, it might be /storage/sdcard0, it all depends on your ROM and how your manufacturer made your phone.
step 6 choose what we want to back up
lets change our directory location to where the partitions are and take a look at what is there, so we can choose what we want to back up. type:
Code:
cd /dev/block/platform/mtk-msdc.0/by-name
ls -l
this gives us a list of partitions. some of them are important to backup, some of them don’t really matter. my phone (a Jiayu S3 advanced running Kitkat 4.4.4) shows 19 partitions. your phone may have more or less. it doesn’t matter, because we are only going to backup a couple of these partitions. the other ones are created on the fly by SP Flash Tool when you use it to flash your phone, or you can get the from a current ROM image from your manufacturer. what are important are: boot, lk, logo, nvram, recover, secro, system, cache, and if you want to backup installed apps, userdata. these should be consistently named on whatever phone you are on. you can backup every single partition here if you really want to, but these are all that are really needed. we can also backup the preloader, but without several scripts to clean up the file we backup, it is a useless file. and as anyone who has read anything about SP Flash Tool knows, you should NEVER EVER EVER flash the preloader. there is no need to do it.
step 7 running the backup commands
to backup these partitions, we are going to use a very very old unix tool called dd. dd will read a partition and dump it into a file for us. then this collection of files will be able to be used with SP Flash Tool if we ever need to restore our backup. just a side note, dd has gotten the reputation to be known as “data destroyer” because if you use it incorrectly, it will definitely destroy your data. it is a dumb copy program and all it knows to do is copy bits from one location to another location. if you get your files messed up, or you get confused, it is very easy to write the wrong thing to the wrong file. but as long as you follow the command syntax below, you should be fine. that being said, if you do something stupid, i am not responsible for any bad outcome. you are messing with your phone on a very low level at this point, so be careful.
because we are accessing your system on such a low level, you need root to use it in the way we are going to. if you don't have root access, this will fail.
the command to run, per partition looks something like this:
Code:
su -c “dd if=<partiton to backup> of=<name of file to backup to> bs=512”
so lets take an example and dissect it. we will backup the recovery partition. the command will look like this:
Code:
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/recovery of=/storage/sdcard1/recovery.img bs=512”
so, lets look at the parts:
su -c : this means invoke root powers to run the following command. be sure that the command is surrounded in “”, otherwise it will only run the first command given
dd : dd, the command we are going to use to backup
if=/dev/block/platform/mtk-msdc.0/by-name/recovery : the name of the partition that we are going to back up
of=/storage/sdcard1/recovery.img : the file we are going to copy this partition to.
bs=512 : how many bytes to copy at a time.
it holds for a few seconds and then gives us this output:
32768+0 records in
32768+0 records out
16777216 bytes transferred in 2.537 secs (6613013 bytes/sec)
so the 32768 records in/out shows how many times it copied 512 bytes of data (512 * 32768 = 16777216 bytes). the last line reiterates the total bytes and how long it took. 16777216 is 16 megabytes… my phone has a 16 megabyte recovery partition, so this all checks out.
step 8 full list of commands to back up the needed partitions
we now know how to backup, we just need a list of commands to backup the other needed partitions. just replace the if partition name with what you are backing up next and the of command with the name you are backing it up too.
Code:
su -c “dd if=/dev/block/mmcblk0boot0 of=/storage/sdcard1/preloader.bin bs=512c count=512 skip=4”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/boot of=/storage/sdcard1/boot.img bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/lk of=/storage/sdcard1/lk.bin bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/logo of=/storage/sdcard1/logo.bin bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/recovery of=/storage/sdcard1/recovery.img bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/secro of=/storage/sdcard1/secro.img bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/nvram of=/storage/sdcard1/nvram.bin bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/system of=/storage/sdcard1/system.img bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/cache of=/storage/sdcard1/cache.img bs=512”
su -c “dd if=/dev/block/platform/mtk-msdc.0/by-name/userdata of=/storage/sdcard1/userdata.img bs=512”
this provides you a system image backup of your phone. you will probably run in to an issue with the last one. depending on your phone, your userdata partition is going to be from 3gb to 12 gb. with these commands, you are creating one monolithic file. anyone that has experimented with large files on a FAT32 file system (what your external sdcard has) knows that the file size limit is 4gb. if your userdata partition is only 3gb, then you're in luck, and you will be fine. if your partition is larger, like my S3 at 12gb, you will need another option. luckily there is one, but we can address that in the next tutorial.
you also can skip the first line of the backup. it will backup the file that contains the preloader... the problem is that it also backs up extra data that is not part of the preloader. you need to run some commands to modify this file, which will be covered in the next tutorial.
Next Tutorial...
in the next tutorial, i will explain a method to backup your phone using these same commands, but instead of saving them to your internal storage, you can pipe them over your ADB connection and save them directly on your computer. we will go over a basic cygwin install (if you don't run linux, you will need some unix tools to do this, and cygwin provides them). we will also discuss shrinking images (your userdata image may be 12gb, but it is probably several gb of just zeros). and i will discuss methods of generating a scatter file, and ways to modify the space your internal partitions take up.
thanks
yuweng on XDA has been the inspiration for most of this work/research. it was him that provided the listing and location of partition names here
scandium on XDA gave me a solution for backing up the partition over ADB, and though they aren't mentioned in this tutorial, they will be in the next. his method is here
syserr did a lot of work with the early mediatek phones the same time that MTK Droid and Root tools came out. some of his methods are used in chunking up entire flash backups. he also created a method for fixing the wonky preloader backup that this script creates.
rua1 for being an inspiration with MTK Droid and Root Tools.