[ADB | FASTBOOT | LINUX COMMANDS] BootLoader, Kernel, Recovery, ROM, Root, Backup

Search This thread

mirfatif

Senior Member
Oct 18, 2016
675
447
t.me
NOTE:
I'm not a developer or something even near to that. All information provided here is copied from different sources and according to the best of my knowledge.
I have tested this on different devices using Windows 8.1 & 10. I'll not be responsible for any harm to you or your device. It works perfectly for me. You may try it on your own risk.
Save / backup your data before performing any actions.


WHAT IS ADB/FASTBOOT
ADB and fastboot are different protocols used through PC to perform different command line operations on device through USB in ROM/Recovery and bootloader mode respectively.
Android Debugging Bridge is basically used by developers to identify and fix bugs in OS (ROM). ADB works in ROM and recovery both.
Fastboot works in bootloader mode even when phone is not switched on in Recovery or ROM or even if Android isn't installed on phone. In later case, bootloader can be accessed by certain button combination while powering on device; usually Power + Vol. Down. See here the booting process of Android devices.
Fastboot/ADB setup is to be made on PC to use this mode. ADB mode has more flexibility than fastboot as it supports more types of flashable files to be flashed. ADB also supports backing up Apps and Data. ADB/fastboot commands can be used to flash recovery and boot images. It can also flash ROMs and mods like rooting solutions and XPOSED by booting into recovery. And above all, it is the only way to unlock bootloader without which the device functionality is too limited. Read here why we need to unlock bootloader.
In bootloader mode, usually boot logo or fastboot logo appears on device screen.

SETUP
  1. Enable USB Debugging in Settings > Developer Options. If not available, Dev. Options can be accessed by tapping 5 (or 7) times Build Number in Settings > About Phone.
  2. Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
  3. Allow data transfer over ADB when prompted on device screen. Otherwise you might get errors like device unauthorized etc. So keep screen unlocked at first connect.
  4. Disable MTP, PTP, UMS etc. from USB computer connection on device to avoid any interruptions.
  5. Install Android SDK or simply install 15 Seconds ADB Setup 1.4.2. It works up to Android Lollipop (AOSP 5). Credits to Snoop05
    Windows 8.1 users who got error installing this setup should first install Windows Update KB2917929.
  6. You will have to navigate to adb folder each time you start cmd. Or setup adb to work globally. On your PC, go to System Properties > Advanced System Settings > Environment Variables. Click on New (User Variables). Variables Name: ADB ( Or anything you want). Variables Value: ;C:\adb (if installed 15 seconds setup) or ;C:\SDK\paltform-tools.
  7. Install ADB USB Drivers for your Android Device. To do this automatically, download and run ADB Driver Installer. Connect device through USB cable and install drivers.
  8. NOTE: Spaces in file paths don't work in adb commands. Non-English characters and languages don't work either. Also the commands are case-sensitive.

There is a long list of adb/fastboot commands to perform numerous operations. Here are a few of those being listed keeping in view certain tasks:

COMMON COMMANDS
On PC run Command Prompt as Administrator.
  • To check connected devices when ROM is running on phone:
    Code:
    adb devices
  • To boot into bootloader mode:
    Code:
    adb reboot bootloader
  • To check connected devices when in bootloader mode:
    Code:
    fastboot devices
  • To boot into ROM:
    Code:
    fastboot reboot
  • To boot into recovery:
    Code:
    fastboot reboot recovery
There are some common Linux commands which can be used in combination with these commands to perform certain operation. However, ADB | FASTBOOT is not necessarily required for these Linux commands. These can be run directly from Terminal Emulator in ROM or Custom Recovery. Some of them are given below.

UNLOCK BOOTLOADER
NOTE: Some newer devices don't allow unlocking of bootloader directly to ensure more security. Instead an official method is provided to unlock BL using PC.
Read here to know about the risks of BL unlocking.


To check the bootloader status:
Code:
fastboot oem device-info
“True” on unlocked status.
If "false", run the following to unlock:
Code:
fastboot oem unlock

However these are OEM specific commands and may differ or not work on all devices. Fastboot's own commands (which are part of AOSP source and) that can unlock bootloader allowing flashing of partitions:
Code:
fastboot flashing unlock
Allow flashing of bootloader related partitions too:
Code:
fastboot flashing unlock_critical

FORMAT DATA PARTITION
This will erase your data.
Code:
fastboot format:ext4 userdata
It can be performed on other flash partitions as well. A general syntax is 'fastboot format:FS PARTITION'

FLASH RECOVERY
Download recovery.img (specific for your device) to adb folder.
To test the recovery without permanently flashing, run the following:
Code:
fastboot boot recovery.img
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:
Code:
fastboot flash recovery recovery.img
fastboot reboot recovery
Stock ROM's often tend to replace custom recovery with stock one on first reboot. That's why, booting into recovery is recommended before booting into ROM.

FLASH KERNEL
Download boot.img (specific for your device) to adb folder and run following:
Code:
fastboot flash boot boot.img

FLASH ROM
Download ROM.zip (for your device) created for fastboot i.e. with android-info.txt and android-product.txt.
To wipe your device and then to flash .zip:
Code:
fastboot -w
fastboot update </path/to/your/Rom.zip>

PASSING FASTBOOT ARGUMENTS
Fastboot supports passing options. For example, while booting a modified kernel image with FramBuffer Console support, console device and its font can be provided as option:
Code:
fastboot boot -c "console=tty0,115200 fbcon=font:VGA8x8" boot-fbcon.img

GAIN ROOT (Not recommended method. Better flash directly through custom recovery).
Root is required to modify the contents of /system. You can read here further.
Download (flashable) supersu.zip and custom or modified recovery.img (having support to flash .zip files) to adb folder and run the following:
Code:
fastboot boot recovery.img
Now once you are in recovery, adb will work instead of fastboot.
To copy files from PC to device and then to extract files, run the following:
Code:
adb push supersu.zip /tmp
adb shell /sbin/recovery --update_package=/tmp/supersu.zip

BACKUP / RESTORE APPS & DATA (From/To PC)
To backup and restore all apps and their data:
Code:
adb backup -apk -shared -all -system -f C:\backup.ab
adb restore C:\backup.ab
Read here for details.

COPY WHOLE PARTITION IMAGE (within device)
This method can be used to backup whole device e.g. to backup /data/ including /data/media/ i.e. Internal SD Card which isn't backed up by custom recovery (TWRP). Or you can get any partition image for development purpose. This method retains complete directory structure as well as file permissions, attributes and contexts.
  • To jump from windows command prompt to android device shell:
    Code:
    adb shell
    These commands can also be given from Recovery Terminal instead of ADB.
  • To get SuperUser access (in ROM):
    Code:
    su
  • To list all available partitions or mount points on device:
    Code:
    cat /proc/partitions
    Or go to "/dev/block/platform/" folder on device. Search for the folder having folder "by-name" inside it. It's msm_sdcc.1 (on Nokia X2). Run the following:
    Code:
    ls -al /dev/block/platform/*/by-name
    Or simply use DiskInfo app to get partition name you want to copy. Say you want to copy /data (userdata) partition. On Nokia X2DS, it is mmcblk0p25.
    To confirm:
    Code:
    readlink /dev/block/bootdevice/by-name/userdata
  • Run the following to copy partition:
    Code:
    dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
    or
    Code:
    cat /dev/block/mmcblk0p25 > /sdcard/data.img
    or
    Code:
    dd if=/dev/block/bootdevice/by-name/userdata of=/sdcard/data.img
    data.img will be copied to your SD card.
    It also works inversely (restore):
    Code:
    dd if=/sdcard/data.img of=/dev/block/mmcblk0p25
    data.img from your SD card will be written to device.
    Similarly you can copy system.img, boot.img or any other partition. However boot.img and other partitions may not be copied in ROM but in recovery mode only. So better use recovery for dd except if you're​ going to dd recovery partition itself. You can read here more about android partitions.

COPY WHOLE FOLDER (within device)
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).

To jump from windows command prompt to android device shell:
Code:
adb shell
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM):
Code:
su
To copy from Internal Memory to SD Card:
Code:
cp -a /data/media/0/. /external_sd/internal_backup/
Or if you don't have SU permission:
Code:
cp -a /external_sd/. /sdcard/
To copy from SD Card to Internal Memory:
Code:
cp -a /external_sd/internal_backup/. /data/media/0/
However, if you are copying to an SD card with FAT32 file system, android permissions of files won't be retained and you would have to fix permissions yourself. In this case, you can use tar command to create archive of files along with their attributes ( permissions: mode & ownership + time-stamps) and security contexts etc. But FAT32 FS has also a limitations of 4GB maximum file size. You may use "split" command along with "tar" to split the archive in smaller blocks. Or use exFat or Ext4 filesystem for larger file support. Ext4 would give higher writing speed in Android but not supported in Windows i.e. SD card can't be mounted in Windows. MTP however works.
To jump from windows command prompt to android device shell:
Code:
adb shell
To get SuperUser access (in ROM):
Code:
su
To copy from Internal Memory to SD Card:
Code:
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
To extract from SD Card to Internal Memory (along with path):
Code:
tar -xvf /external_sd/internal_backup/media.tar
To extract from SD Card to some other location, use "-C":
Code:
tar -xvf /external_sd/internal_backup/media.tar -C /data/media/0/extracted_archive/

COPY WHOLE FOLDER (From/To PC)
This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).

To copy from PC to device:
Code:
adb push \path\to\folder\on\PC\ /path/to/folder/on/device/
To copy from device to PC:
Code:
adb pull /path/to/folder/on/device/ \path\to\folder\on\PC\

After copying from PC to device's Internal Memory (/data/media/), you might get Permission Denied error e.g. apps can't write or even read from Internal Memory. It's because Android (Linux) and Windows have different file permissions system. To FIX PERMISSIONS, boot into recovery and run following commands:
(Credits to xak944 :))
Code:
adb shell
To take ownership of whole "media" directory:
Code:
chown -R media_rw:media_rw /data/media/
To fix permissions of directories:
Code:
find /data/media/ -type d -exec chmod 775 '{}' ';'
To fix permissions of files:
Code:
find /data/media/ -type f -exec chmod 664 '{}' ';'
 
Last edited:

lordaker

Member
Aug 11, 2019
5
0
Dakar
Afternoon,

I try to reinstall my Infininx Smart 2 X5515 by using the firmware from the url below:
https://forum.hovatek.com/thread-23850.html

Infinix X5515 Smart 2 (X5515-H398DEG-GO-180903V166) [Factory / Signed]

But nothing work and the phone is unusable. I install the recovery.img file by using ADB/Fastboot(macOS)
But when I reboot to recovery mode, the logo of Infinix appear and reboot again, appear for a while and reboot
again. :(:(:(:(:(:confused::confused::confused::confused::confused:

Code:
the-webinarts:tools thewebinarts$ ./fastboot update 
.DS_Store                        emulator                         recovery-verified.img
NOTICE.txt                       emulator-check                   recovery.img
X5515-H398DEG-GO-180903V166.zip  fastboot                         source.properties
adb                              lib/                             support/
android                          mksdcard                         system.img
bin/                             monitor                          twrp/
boot-verified.img                package.xml                      twrp.img
boot.img                         proguard/                        vendor.img
the-webinarts:tools thewebinarts$ ./fastboot update X5515-H398DEG-GO-180903V166.zip 
--------------------------------------------
Bootloader Version...: 
Baseband Version.....: 
Serial Number........: 
--------------------------------------------
archive does not contain 'android-info.txt'
fastboot: error: could not read android-info.txt

When I type the following cmd below to know the version of fastboot I use and the product:

Code:
the-webinarts:tools thewebinarts$ ./fastboot getvar version
version: 0.5
Finished. Total time: 0.003s
the-webinarts:tools thewebinarts$

Code:
the-webinarts:tools thewebinarts$ ./fastboot getvar product
product: KEYTAK6580_WEG_L
Finished. Total time: 0.003s
the-webinarts:tools thewebinarts$ ;

Do you have a good process who works well for my model?
S/N: H6N2 (This is the Serial number of my phone)
 
Last edited:

mirfatif

Senior Member
Oct 18, 2016
675
447
t.me
Is there a way to use adb to backup the entire /data partition without root? I swear I have done it before but I can't seem to get it to work anymore. Perhaps I need to switch to an older version of adb?
No you can't. (Why? See first paragraph of this answer: https://android.stackexchange.com/a/219926/218526). Your "adbd" must have been running with root privileges previously which now is not: https://android.stackexchange.com/a/213429/218526
 
Last edited:

Swagnik

Senior Member
Aug 21, 2018
58
4
20
Kolkata
Asus ZenFone 2
Zenfone 2 Laser
Few months ago I was actually I was trying to fix a Moto device!!!
At that time I found a adb or Fastboot command (most probably fastboot) which displays every single details about the device starting from root access, cpu, gpu, clock speeds and every single details!!!

But unfortunately I lost the command nd now I need it!!!
So if anybody knows it plz ...........!!
Thanks.................:good:
 

piotr1953

Member
Jun 30, 2019
32
1
Bricked lg g5 in qdl mode

Hi guys!

BACKUP / RESTORE APPS & DATA (From/To PC)

Is it still possible on Android Nougat/Oreo on last Samsung devices?

Thanks!

BRICKED LG G5 IN QDL MODE
[35158.598244] usb 2-3: Qualcomm USB modem converter now attached to ttyUSB0
[email protected]:/$ adb tcpip ttyUSB0
error: device '(null)' not found

[email protected]:/$ adb devices -l
List of devices attached

[email protected]:/$

[email protected]:~$ fastboot devices
[email protected]:~$

May I ask how to use it???
Vale Piotr
 

Uredie

Member
May 20, 2014
27
5
Hey, i have one problem. When im trying to backup whole internal storage to PC, im using
Code:
adb pull "/sdcard" "C:/11"
This works perfectly, but when i try to copy those files to my internal phone storage with command
Code:
adb push "C:/11/sdcard/" "/sdcard/"
It makes just SDCARD(with copied files) folder in internal storage instead of copy files from this folder to Internal storage.

How to copy from PC folder named SDCARD to internat storage? Do i need to copy every catalog with another command specified
Code:
adb push "C:/11/sdcard/DCIM" "/sdcard/"
?
Maybe im misunderstanding something, but it dont make difference if i wrote
Code:
adb push "C:/11/sdcard/" "/sdcard/"
or
Code:
adb push "C:/11/sdcard/" "/sdcard"
It still make sdcard folder in my storage.
 

mirfatif

Senior Member
Oct 18, 2016
675
447
t.me
Just a question as I dont need to do any of this, but what happens with files without an extension? ie no dot in the filename.
Globs has nothing to do with file extensions. On mostly shells * matches only non-hidden files. dotglob (.*) ensures that hidden files (starting with a .) are also matched.
 
Last edited:

DiamondJohn

Recognized Contributor
Aug 31, 2013
6,168
6,050
Sydney
Globs has nothing to do with file extensions. On mostly shells * matches only non-hidden files. dotglob (.*[/ICODE) ensures that hidden files (starting with a [ICODE].) are also matched.
Aa I said, its no biggie for me, but, by "globs", there are plenty of files other than "globs" that do not have file extensions. My understanding (and I did a quick check) of a "glob", is that specifically HAS a file extension. eg. *.txt And yes, I inderstand that hidden files are basically all file extension (if they dont have one already). But I am taking about files specifically without any dot.

I am NIOT talking about hidden files, I am taking abourt ones without any dot whatsoever. First to mind are boot scripts (which you may have backed up on your SDCard), also album art is stored as a JPG without any extension, and on your SDCard (so you would hope to back that up). Android has many uses of files without dots in the name. So I dont see how .* could match a file name important_secret_data i.e. no dot

Clearl;y I do not care too much personally, otherwise I would do the test, but :meh: Someone who does care should simply check if I am wrong before depending on it.
 
  • Like
Reactions: Uredie

HemanthJabalpuri

Senior Member
Android has many uses of files without dots in the name. So I dont see how .* could match a file name important_secret_data i.e. no dot

Clearly I do not care too much personally, otherwise I would do the test, but :meh: Someone who does care should simply check if I am wrong before depending on it.
run these in terminal, you can get a better idea.
Code:
echo >./.hasdot
echo >./noext
ls .*

@mirfatif
It seems like this dotglob is copying the parent directory contents too, since .. is also a hidden entry. With this it pushes the same entries two times.

@Uredie
you can try this adb push C:/11/sdcard/. /sdcard/.
 
Last edited:

Uredie

Member
May 20, 2014
27
5
@HemanthJabalpuri and all others thanks for answers :) You are making great community ;)

Looks like it works, it put file from FolderA directly to /sdcard on phone without making folder :)

So if im not wrong, the best idea to copy all files from phone and then copy everything directly to phone is:
Code:
adb pull /sdcard C:/BackupFolder


then


adb push C:/BackupFolder/. /sdcard/

I have couple more questions.

1)The same files are overwrited or skipped while copying?
2)Did somebody have problem that when you copied files by this way and then backed up, photos have f. up made date? Like old photos have new date and it show as new in Google Photos.
3)I forgot what else I was supposed to write, I edit later if I remember
Edit 3) Remember already. I Was curious about 1 thing but it's already cleared.
When you have for example DCIM on phone, then backed up from PC folders with DCIM inside it will merge folders, just like copy files from DCIM pc to DCIM phone.
I was curious because if i was copying files on phone it was making something like DCIM(1).
 
Last edited:

mirfatif

Senior Member
Oct 18, 2016
675
447
t.me
@Uredie @DiamondJohn @HemanthJabalpuri thanks for your contribution.

In fact the behavior of globbing and wildcards differs widely even among *NIX shells. Windows is a different world altogether. The debate seems to be off-topic here. And I'm no way more than an ordinary shell user. That's why I linked the basic explanation on Wikipedia. There are great resources on internet like this and this which satisfactorily resolve this matter already.

Hope it helps.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 37
    NOTE:
    I'm not a developer or something even near to that. All information provided here is copied from different sources and according to the best of my knowledge.
    I have tested this on different devices using Windows 8.1 & 10. I'll not be responsible for any harm to you or your device. It works perfectly for me. You may try it on your own risk.
    Save / backup your data before performing any actions.


    WHAT IS ADB/FASTBOOT
    ADB and fastboot are different protocols used through PC to perform different command line operations on device through USB in ROM/Recovery and bootloader mode respectively.
    Android Debugging Bridge is basically used by developers to identify and fix bugs in OS (ROM). ADB works in ROM and recovery both.
    Fastboot works in bootloader mode even when phone is not switched on in Recovery or ROM or even if Android isn't installed on phone. In later case, bootloader can be accessed by certain button combination while powering on device; usually Power + Vol. Down. See here the booting process of Android devices.
    Fastboot/ADB setup is to be made on PC to use this mode. ADB mode has more flexibility than fastboot as it supports more types of flashable files to be flashed. ADB also supports backing up Apps and Data. ADB/fastboot commands can be used to flash recovery and boot images. It can also flash ROMs and mods like rooting solutions and XPOSED by booting into recovery. And above all, it is the only way to unlock bootloader without which the device functionality is too limited. Read here why we need to unlock bootloader.
    In bootloader mode, usually boot logo or fastboot logo appears on device screen.

    SETUP
    1. Enable USB Debugging in Settings > Developer Options. If not available, Dev. Options can be accessed by tapping 5 (or 7) times Build Number in Settings > About Phone.
    2. Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
    3. Allow data transfer over ADB when prompted on device screen. Otherwise you might get errors like device unauthorized etc. So keep screen unlocked at first connect.
    4. Disable MTP, PTP, UMS etc. from USB computer connection on device to avoid any interruptions.
    5. Install Android SDK or simply install 15 Seconds ADB Setup 1.4.2. It works up to Android Lollipop (AOSP 5). Credits to Snoop05
      Windows 8.1 users who got error installing this setup should first install Windows Update KB2917929.
    6. You will have to navigate to adb folder each time you start cmd. Or setup adb to work globally. On your PC, go to System Properties > Advanced System Settings > Environment Variables. Click on New (User Variables). Variables Name: ADB ( Or anything you want). Variables Value: ;C:\adb (if installed 15 seconds setup) or ;C:\SDK\paltform-tools.
    7. Install ADB USB Drivers for your Android Device. To do this automatically, download and run ADB Driver Installer. Connect device through USB cable and install drivers.
    8. NOTE: Spaces in file paths don't work in adb commands. Non-English characters and languages don't work either. Also the commands are case-sensitive.

    There is a long list of adb/fastboot commands to perform numerous operations. Here are a few of those being listed keeping in view certain tasks:

    COMMON COMMANDS
    On PC run Command Prompt as Administrator.
    • To check connected devices when ROM is running on phone:
      Code:
      adb devices
    • To boot into bootloader mode:
      Code:
      adb reboot bootloader
    • To check connected devices when in bootloader mode:
      Code:
      fastboot devices
    • To boot into ROM:
      Code:
      fastboot reboot
    • To boot into recovery:
      Code:
      fastboot reboot recovery
    There are some common Linux commands which can be used in combination with these commands to perform certain operation. However, ADB | FASTBOOT is not necessarily required for these Linux commands. These can be run directly from Terminal Emulator in ROM or Custom Recovery. Some of them are given below.

    UNLOCK BOOTLOADER
    NOTE: Some newer devices don't allow unlocking of bootloader directly to ensure more security. Instead an official method is provided to unlock BL using PC.
    Read here to know about the risks of BL unlocking.


    To check the bootloader status:
    Code:
    fastboot oem device-info
    “True” on unlocked status.
    If "false", run the following to unlock:
    Code:
    fastboot oem unlock

    However these are OEM specific commands and may differ or not work on all devices. Fastboot's own commands (which are part of AOSP source and) that can unlock bootloader allowing flashing of partitions:
    Code:
    fastboot flashing unlock
    Allow flashing of bootloader related partitions too:
    Code:
    fastboot flashing unlock_critical

    FORMAT DATA PARTITION
    This will erase your data.
    Code:
    fastboot format:ext4 userdata
    It can be performed on other flash partitions as well. A general syntax is 'fastboot format:FS PARTITION'

    FLASH RECOVERY
    Download recovery.img (specific for your device) to adb folder.
    To test the recovery without permanently flashing, run the following:
    Code:
    fastboot boot recovery.img
    On next reboot, recovery will be overwritten by previous recovery.
    Or to permanently flash recovery, run:
    Code:
    fastboot flash recovery recovery.img
    fastboot reboot recovery
    Stock ROM's often tend to replace custom recovery with stock one on first reboot. That's why, booting into recovery is recommended before booting into ROM.

    FLASH KERNEL
    Download boot.img (specific for your device) to adb folder and run following:
    Code:
    fastboot flash boot boot.img

    FLASH ROM
    Download ROM.zip (for your device) created for fastboot i.e. with android-info.txt and android-product.txt.
    To wipe your device and then to flash .zip:
    Code:
    fastboot -w
    fastboot update </path/to/your/Rom.zip>

    PASSING FASTBOOT ARGUMENTS
    Fastboot supports passing options. For example, while booting a modified kernel image with FramBuffer Console support, console device and its font can be provided as option:
    Code:
    fastboot boot -c "console=tty0,115200 fbcon=font:VGA8x8" boot-fbcon.img

    GAIN ROOT (Not recommended method. Better flash directly through custom recovery).
    Root is required to modify the contents of /system. You can read here further.
    Download (flashable) supersu.zip and custom or modified recovery.img (having support to flash .zip files) to adb folder and run the following:
    Code:
    fastboot boot recovery.img
    Now once you are in recovery, adb will work instead of fastboot.
    To copy files from PC to device and then to extract files, run the following:
    Code:
    adb push supersu.zip /tmp
    adb shell /sbin/recovery --update_package=/tmp/supersu.zip

    BACKUP / RESTORE APPS & DATA (From/To PC)
    To backup and restore all apps and their data:
    Code:
    adb backup -apk -shared -all -system -f C:\backup.ab
    adb restore C:\backup.ab
    Read here for details.

    COPY WHOLE PARTITION IMAGE (within device)
    This method can be used to backup whole device e.g. to backup /data/ including /data/media/ i.e. Internal SD Card which isn't backed up by custom recovery (TWRP). Or you can get any partition image for development purpose. This method retains complete directory structure as well as file permissions, attributes and contexts.
    • To jump from windows command prompt to android device shell:
      Code:
      adb shell
      These commands can also be given from Recovery Terminal instead of ADB.
    • To get SuperUser access (in ROM):
      Code:
      su
    • To list all available partitions or mount points on device:
      Code:
      cat /proc/partitions
      Or go to "/dev/block/platform/" folder on device. Search for the folder having folder "by-name" inside it. It's msm_sdcc.1 (on Nokia X2). Run the following:
      Code:
      ls -al /dev/block/platform/*/by-name
      Or simply use DiskInfo app to get partition name you want to copy. Say you want to copy /data (userdata) partition. On Nokia X2DS, it is mmcblk0p25.
      To confirm:
      Code:
      readlink /dev/block/bootdevice/by-name/userdata
    • Run the following to copy partition:
      Code:
      dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
      or
      Code:
      cat /dev/block/mmcblk0p25 > /sdcard/data.img
      or
      Code:
      dd if=/dev/block/bootdevice/by-name/userdata of=/sdcard/data.img
      data.img will be copied to your SD card.
      It also works inversely (restore):
      Code:
      dd if=/sdcard/data.img of=/dev/block/mmcblk0p25
      data.img from your SD card will be written to device.
      Similarly you can copy system.img, boot.img or any other partition. However boot.img and other partitions may not be copied in ROM but in recovery mode only. So better use recovery for dd except if you're​ going to dd recovery partition itself. You can read here more about android partitions.

    COPY WHOLE FOLDER (within device)
    This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).

    To jump from windows command prompt to android device shell:
    Code:
    adb shell
    These commands can also be given from Recovery Terminal.
    To get SuperUser access (in ROM):
    Code:
    su
    To copy from Internal Memory to SD Card:
    Code:
    cp -a /data/media/0/. /external_sd/internal_backup/
    Or if you don't have SU permission:
    Code:
    cp -a /external_sd/. /sdcard/
    To copy from SD Card to Internal Memory:
    Code:
    cp -a /external_sd/internal_backup/. /data/media/0/
    However, if you are copying to an SD card with FAT32 file system, android permissions of files won't be retained and you would have to fix permissions yourself. In this case, you can use tar command to create archive of files along with their attributes ( permissions: mode & ownership + time-stamps) and security contexts etc. But FAT32 FS has also a limitations of 4GB maximum file size. You may use "split" command along with "tar" to split the archive in smaller blocks. Or use exFat or Ext4 filesystem for larger file support. Ext4 would give higher writing speed in Android but not supported in Windows i.e. SD card can't be mounted in Windows. MTP however works.
    To jump from windows command prompt to android device shell:
    Code:
    adb shell
    To get SuperUser access (in ROM):
    Code:
    su
    To copy from Internal Memory to SD Card:
    Code:
    tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
    To extract from SD Card to Internal Memory (along with path):
    Code:
    tar -xvf /external_sd/internal_backup/media.tar
    To extract from SD Card to some other location, use "-C":
    Code:
    tar -xvf /external_sd/internal_backup/media.tar -C /data/media/0/extracted_archive/

    COPY WHOLE FOLDER (From/To PC)
    This method can be used to backup folders like /data/media/ which isn't backed up by custom recovery (TWRP).

    To copy from PC to device:
    Code:
    adb push \path\to\folder\on\PC\ /path/to/folder/on/device/
    To copy from device to PC:
    Code:
    adb pull /path/to/folder/on/device/ \path\to\folder\on\PC\

    After copying from PC to device's Internal Memory (/data/media/), you might get Permission Denied error e.g. apps can't write or even read from Internal Memory. It's because Android (Linux) and Windows have different file permissions system. To FIX PERMISSIONS, boot into recovery and run following commands:
    (Credits to xak944 :))
    Code:
    adb shell
    To take ownership of whole "media" directory:
    Code:
    chown -R media_rw:media_rw /data/media/
    To fix permissions of directories:
    Code:
    find /data/media/ -type d -exec chmod 775 '{}' ';'
    To fix permissions of files:
    Code:
    find /data/media/ -type f -exec chmod 664 '{}' ';'
    3
    i also have problem trying to issue some fastboot command
    bootloader have been unlock
    except fastboot reboot command, the rest of fastboot cannot be execute
    the error were
    ...
    FAILED (remote: Command not allowed)
    finished. total time: 0.00s

    can i issue fastboot command from twrp terminal
    i want to enable charge reboot

    on fastboot
    fastboot oem off-mode-charge disable

    how to issue comand from within twrp terminal?
    All vendors don't allow all fastboot commands. Despite of unlocked bootloader, some commands might not work or work differently on certain devices.
    No you can't control fastboot from TWRP. Bootloader / fastboot come at lower level in boot process. Recovery itself is loaded by bootloader. We can't control fastboot from recovery. However a few adb commands work in TWRP as well.
    2
    ".*" means everything from folder, right?
    Yes, including hidden files. You can search about globbing and wildcards. Start from here: https://en.wikipedia.org/wiki/Glob_(programming)#Windows_and_DOS
    2
    Just a question as I dont need to do any of this, but what happens with files without an extension? ie no dot in the filename.
    Globs has nothing to do with file extensions. On mostly shells * matches only non-hidden files. dotglob (.*) ensures that hidden files (starting with a .) are also matched.
    2
    Is there a way to use adb to backup the entire /data partition without root? I swear I have done it before but I can't seem to get it to work anymore. Perhaps I need to switch to an older version of adb?
    No you can't. (Why? See first paragraph of this answer: https://android.stackexchange.com/a/219926/218526). Your "adbd" must have been running with root privileges previously which now is not: https://android.stackexchange.com/a/213429/218526