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



## mirfatif (Apr 27, 2017)

*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*

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.
Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
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.
Disable MTP, PTP, UMS etc. from _USB computer connection_ on device to avoid any interruptions.
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.
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_.
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.
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: 
	
	



```
adb devices
```

To boot into bootloader mode: 
	
	



```
adb reboot bootloader
```

To check connected devices when in bootloader mode: 
	
	



```
fastboot devices
```

To boot into ROM: 
	
	



```
fastboot reboot
```

To boot into recovery: 
	
	



```
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: 
	
	



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



```
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: 
	
	



```
fastboot flashing unlock
```
Allow flashing of bootloader related partitions too: 
	
	



```
fastboot flashing unlock_critical
```

*FORMAT DATA PARTITION*
This will erase your data.

```
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:

```
fastboot boot recovery.img
```
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal instead of ADB.
To get SuperUser access (in ROM): 
	
	



```
su
```

To list all available partitions or mount points on device: 
	
	



```
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: 
	
	



```
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:

```
readlink /dev/block/bootdevice/by-name/userdata
```

Run the following to copy partition: 
	
	



```
dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
```
or 
	
	



```
cat /dev/block/mmcblk0p25 > /sdcard/data.img
```
or 
	
	



```
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):

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
cp -a /data/media/0/. /external_sd/internal_backup/
```
Or if you don't have SU permission:

```
cp -a /external_sd/. /sdcard/
```
To copy from SD Card to Internal Memory:

```
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: 
	
	



```
adb shell
```
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
```
To extract from SD Card to Internal Memory (along with path):

```
tar -xvf /external_sd/internal_backup/media.tar
```
To extract from SD Card to some other location, use "-C":

```
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:

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

```
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 )

```
adb shell
```
To take ownership of whole "media" directory:

```
chown -R media_rw:media_rw /data/media/
```
To fix permissions of directories:

```
find /data/media/ -type d -exec chmod 775 '{}' ';'
```
To fix permissions of files:

```
find /data/media/ -type f -exec chmod 664 '{}' ';'
```


----------



## theburrus1 (Mar 29, 2018)

*HELP PLEASE! Fastboot is acting funny for first time, Huawei Honor 6X*

Okay, so I have a Huawei Honor 6X. This device has been rooted and and had custom roms of sorts flashed fine, and bootloader has been unlocked several times only to later have me flash the stock firmware back thus locking bootloader, etc. So this isn't my first rodeo. However, have never seen this. Basically, going from the Stock ROM, I had *enabled* USB DEBUGGING and approved the little allow always toast popup. Then using my command line in linux, I issued
	
	



```
adb devices
```
.... saw it was seeing the device. Then issued
	
	



```
adb reboot bootloader
```
. Fine. I see 





> PHONE locked FRP Unlocked

Click to collapse



 on my fastboot screen.  So I know my bootloader is locked. Also, I had previously gotten my unlock code from Huawei as well. But please *see the attached image *attached belowe here for the real picture of things because once in my fastboot mode, issuing 
	
	



```
fastboot devices
```
 shows my Device ID. However when trying to issue the 
	
	



```
fastboot oem unlock bootloader
```
 code, it acts then like it can find the device or either the devices doesn't find the command? It just says waiting for devices as you can see... wtf?  This is all at the same instance. Please see attached and any help, suggestions, etc. are appreciated!


----------



## ahhl (Apr 10, 2018)

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?


----------



## mirfatif (Apr 10, 2018)

ahhl said:


> 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
> ...

Click to collapse



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.


----------



## PIRATA! (Jun 14, 2018)

Hi guys! 

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

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

Thanks! 

Sent from my SM-G950F using Tapatalk


----------



## mirfatif (Jun 22, 2018)

PIRATA! said:


> Hi guys!
> 
> BACKUP / RESTORE APPS & DATA (From/To PC)
> 
> ...

Click to collapse



It's related to adb which is same on Nougat/Oreo, I think. So it should work similarly.


----------



## shashank1320 (Jun 29, 2018)

ahhl said:


> 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

Click to collapse



FRP locked?

---------- Post added at 11:43 AM ---------- Previous post was at 10:50 AM ----------

Very nice guide with detailed information.


----------



## Myat_Thu (Aug 24, 2018)

Thanks


----------



## g7nbp (Sep 28, 2018)

*struggling with fastboot*

Fastboot doesn't want to write out my unlock file???

I'm trying to unlock the bootloader on an old HTC wildfire S, and have followed all the steps listed on the official htcdev.com site to get the unlock token from HTC, but when I run

./fastboot flash unlocktoken Unlock_code.bin

I get

target didn't report max-download-size
sending 'unlocktoken' (0 KB)

but then it just sits these forever

all other fastboot commands seem to work fine, just the flash unlock thats not being written

I can find lots of posts from people with same problem, but no answers that get me any nearer.

enviro here is debian with latest android dev installed from the standard repositories, and fastboot 1:7.0.0+r33-1

phone is wildfire s
Marvel pvt ship s-on rl
hboot 1.09.0099
microp 0451
radio 7.57.39.10m
feb 8 2012,10:29.31

branded for the uk three network.


any help would be appreciated!

chris w


----------



## marklutz35 (Sep 29, 2018)

*Try this with that Huawei.  This should.unlock the oem*

Go into settings . Go all the way to the bottom to about phone, then go find build number press at a bunch of times rapidly that'll take you into developer mode. Once in developer mode back into the main menu of settings scroll down to developer options. You should find OEM bootloader unlock about three or four down in that section click unlock and you should be good to go. Good luck oh and I didn't have to back mine up first so you should be good to go..... 





theburrus1 said:


> Okay, so I have a Huawei Honor 6X. This device has been rooted and and had custom roms of sorts flashed fine, and bootloader has been unlocked several times only to later have me flash the stock firmware back thus locking bootloader, etc. So this isn't my first rodeo. However, have never seen this. Basically, going from the Stock ROM, I had *enabled* USB DEBUGGING and approved the little allow always toast popup. Then using my command line in linux, I issued
> 
> 
> 
> ...

Click to collapse


----------



## whitehat15 (Jan 6, 2019)

*unknown command while flashing through fastboot*

i keep getting unknown command while trying to flash recovery images or firmware, please help me


----------



## shashank1320 (Jan 9, 2019)

whitehat15 said:


> i keep getting unknown command while trying to flash recovery images or firmware, please help me

Click to collapse



What commands are you trying and which phone/android version as command has changed since oreo


----------



## jd1639 (Jan 26, 2019)

@mirfatif  Do you know what the fastboot update command is doing under the hood?  It's obviously flashing the images to the correct partitions but how does it know what image goes where?  fastboot flash boot boot.img makes sense to me but running a fastboot command on a bunch of image files in a zip file doesn't.  Thanks.


----------



## mirfatif (Jan 29, 2019)

jd1639 said:


> @mirfatif Do you know what the fastboot update command is doing under the hood? It's obviously flashing the images to the correct partitions but how does it know what image goes where? fastboot flash boot boot.img makes sense to me but running a fastboot command on a bunch of image files in a zip file doesn't. Thanks.

Click to collapse



Can you give me example of such zip file? Fastboot protocol is provided by application bootloader (aboot) which knows very well the exact boundaries of partitions on device. When flashing images, we are telling fastboot what image it is or where it is to be written.


----------



## jd1639 (Jan 29, 2019)

mirfatif said:


> Can you give me example of such zip file? Fastboot protocol is provided by application bootloader (aboot) which knows very well the exact boundaries of partitions on device. When flashing images, we are telling fastboot what image it is or where it is to be written.

Click to collapse



The Nexus and pixel phones have had a batch file in the factory image zip file that runs fastboot flashes for the bootloader and radio and then runs a command fastboot update xyz.zip. The xyz.zip is another zip file within the factory image zip. This zip contains all the other image files, i.e. system, modem, etc. Also, I have a pixel 3 and there is no aboot partition. The kernel and recovery images are also both contained in the boot.img. These phones are getting more difficult to deal with. 

These are the partitions:

127|:/dev/block/bootdevice/by-name # ls -all
total 0
drwxr-xr-x 2 root root 1440 1970-05-03 01:39:00.159934065 -0500 .
drwxr-xr-x 3 root root 1580 1970-05-03 01:39:00.159934065 -0500 ..
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 ALIGN_TO_128K_1 -> /dev/block/sdd1
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.143269064 -0500 ALIGN_TO_128K_2 -> /dev/block/sdf1
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 ImageFv -> /dev/block/sdf14
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 abl_a -> /dev/block/sde4
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.153268065 -0500 abl_b -> /dev/block/sde16
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 aop_a -> /dev/block/sde1
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.153268065 -0500 aop_b -> /dev/block/sde13
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 apdp_a -> /dev/block/sda15
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.156601065 -0500 apdp_b -> /dev/block/sda16
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.159934065 -0500 boot_a -> /dev/block/sda11
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 boot_b -> /dev/block/sda12
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 cdt -> /dev/block/sdd2
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 cmnlib64_a -> /dev/block/sde7
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 cmnlib64_b -> /dev/block/sde19
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 cmnlib_a -> /dev/block/sde6
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 cmnlib_b -> /dev/block/sde18
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 ddr -> /dev/block/sdd3
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 devcfg_a -> /dev/block/sde8
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 devcfg_b -> /dev/block/sde20
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 devinfo -> /dev/block/sdf7
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 dip -> /dev/block/sdf8
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 dtbo_a -> /dev/block/sde11
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 dtbo_b -> /dev/block/sde23
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 frp -> /dev/block/sda4
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 fsc -> /dev/block/sdf6
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 fsg -> /dev/block/sdf5
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 hyp_a -> /dev/block/sde3
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 hyp_b -> /dev/block/sde15
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 keymaster_a -> /dev/block/sde5
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 keymaster_b -> /dev/block/sde17
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.156601065 -0500 keystore -> /dev/block/sda3
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.159934065 -0500 klog -> /dev/block/sda19
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.146602064 -0500 limits -> /dev/block/sdf10
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 logfs -> /dev/block/sdf12
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.156601065 -0500 metadata -> /dev/block/sda20
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 misc -> /dev/block/sda2
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.156601065 -0500 modem_a -> /dev/block/sda13
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.156601065 -0500 modem_b -> /dev/block/sda14
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 modemcal -> /dev/block/sdd4
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.143269064 -0500 modemst1 -> /dev/block/sdf3
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 modemst2 -> /dev/block/sdf4
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 msadp_a -> /dev/block/sda17
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 msadp_b -> /dev/block/sda18
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 persist -> /dev/block/sdf2
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.143269064 -0500 product_a -> /dev/block/sda7
lrwxrwxrwx 1 root root** 15 1970-05-03 01:38:59.939956043 -0500 product_b -> /dev/block/sda8
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 qupfw_a -> /dev/block/sde9
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 qupfw_b -> /dev/block/sde21
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 sec -> /dev/block/sdd6
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 splash -> /dev/block/sdf15
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.136603063 -0500 spunvm -> /dev/block/sdf9
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.143269064 -0500 ssd -> /dev/block/sda1
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.143269064 -0500 sti -> /dev/block/sdf13
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.146602064 -0500 storsec_a -> /dev/block/sde12
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.149935064 -0500 storsec_b -> /dev/block/sde24
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.153268065 -0500 system_a -> /dev/block/sda5
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.159934065 -0500 system_b -> /dev/block/sda6
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.146602064 -0500 toolsfv -> /dev/block/sdf11
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 tz_a -> /dev/block/sde2
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 tz_b -> /dev/block/sde14
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 uefivar -> /dev/block/sdd5
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.153268065 -0500 userdata -> /dev/block/sda21
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.153268065 -0500 vbmeta_a -> /dev/block/sde10
lrwxrwxrwx 1 root root** 16 1970-05-03 01:39:00.139936063 -0500 vbmeta_b -> /dev/block/sde22
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.143269064 -0500 vendor_a -> /dev/block/sda9
lrwxrwxrwx 1 root root** 16 1970-05-03 01:38:59.939956043 -0500 vendor_b -> /dev/block/sda10
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.139936063 -0500 xbl_a -> /dev/block/sdb1
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 xbl_b -> /dev/block/sdc1
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.146602064 -0500 xbl_config_a -> /dev/block/sdb2
lrwxrwxrwx 1 root root** 15 1970-05-03 01:39:00.149935064 -0500 xbl_config_b -> /dev/block/s

Sent from my [device_name] using XDA-Developers Legacy app


----------



## mirfatif (Jan 29, 2019)

jd1639 said:


> The xyz.zip is another zip file within the factory image zip. This zip contains all the other image files, i.e. system, modem, etc.

Click to collapse



And it also contains *rawprogram_unsparse.xml* or something similar with all partitions listed?



> Also, I have a pixel 3 and there is no aboot partition.

Click to collapse



I haven't used a device so far with A/B partitioning scheme, so I'm not sure what nomenclature they use for partitions but I think *abl_** is the application bootloader.



> The kernel and recovery images are also both contained in the boot.img.

Click to collapse



Yes. There is no recovery partition with A/B scheme.


----------



## jd1639 (Jan 29, 2019)

mirfatif said:


> And it also contains *rawprogram_unsparse.xml* or something similar with all partitions listed?
> 
> 
> I haven't used a device so far with A/B partitioning scheme, so I'm not sure what nomenclature they use for partitions but I think *abl_** is the application bootloader.
> ...

Click to collapse



There's nothing in the zip but image files. There's one text file but it just checks for latest bootloader. There's an image, xbl_config.img. I'm not sure what that does. 

Sent from my [device_name] using XDA-Developers Legacy app


----------



## mirfatif (Jan 29, 2019)

jd1639 said:


> There's nothing in the zip but image files. There's one text file but it just checks for latest bootloader. There's an image, xbl_config.img. I'm not sure what that does.

Click to collapse



Actaully *rawprogram_unsparse.xml* or similar files are used by Factory Flashers such as in Download Mode or ODIN etc. If the device is booted up to the stage of application bootloader (aboot), enough detail of partitions on eMMC is already loaded, including partition names (or labels) that are assigned at the time of creating GUID partition table (GPT). When we execute *fastboot update xyz.zip*, it flashes all images one by one very similar to *fastboot flash boot boot.img*, *fastboot flash system system.img* and so on. Here boot and system are partition names (part_name) while boot.img and system.img are image files (img_name) that should be found in OTA update zip file. Which image file is to be written to which partition is hard-coded in fastboot command's source code:

```
static struct {
    const char* nickname;
    const char* img_name;
    const char* sig_name;
    const char* part_name;
    bool is_optional;
    bool is_secondary;
} images[] = {
    { "boot",     "boot.img",         "boot.sig",     "boot",     false, false },
    { "system",   "system.img",       "system.sig",   "system",   false, false },
...
...
}
```


----------



## jd1639 (Jan 29, 2019)

mirfatif said:


> Actaully *rawprogram_unsparse.xml* or similar files are used by Factory Flashers such as in Download Mode or ODIN etc. If the device is booted up to the stage of application bootloader (aboot), enough detail of partitions on eMMC is already loaded, including partition names (or labels) that are assigned at the time of creating GUID partition table (GPT). When we execute *fastboot update xyz.zip*, it flashes all images one by one very similar to *fastboot flash boot boot.img*, *fastboot flash system system.img* and so on. Here boot and system are partition names (part_name) while boot.img and system.img are image files (img_name) that should be found in OTA update zip file. Which image file is to be written to which partition is hard-coded in fastboot command's source code:
> 
> ```
> static struct {
> ...

Click to collapse



This is great, especially the source code.  It tells me a lot.  I learned something new for the day!


----------



## rafiraza (Jun 29, 2019)

how to use unlock oem command  when no Volume button is available on car GPS T98 10 inches UNIT.?


----------



## mirfatif (Apr 27, 2017)

*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*

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.
Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
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.
Disable MTP, PTP, UMS etc. from _USB computer connection_ on device to avoid any interruptions.
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.
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_.
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.
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: 
	
	



```
adb devices
```

To boot into bootloader mode: 
	
	



```
adb reboot bootloader
```

To check connected devices when in bootloader mode: 
	
	



```
fastboot devices
```

To boot into ROM: 
	
	



```
fastboot reboot
```

To boot into recovery: 
	
	



```
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: 
	
	



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



```
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: 
	
	



```
fastboot flashing unlock
```
Allow flashing of bootloader related partitions too: 
	
	



```
fastboot flashing unlock_critical
```

*FORMAT DATA PARTITION*
This will erase your data.

```
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:

```
fastboot boot recovery.img
```
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal instead of ADB.
To get SuperUser access (in ROM): 
	
	



```
su
```

To list all available partitions or mount points on device: 
	
	



```
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: 
	
	



```
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:

```
readlink /dev/block/bootdevice/by-name/userdata
```

Run the following to copy partition: 
	
	



```
dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
```
or 
	
	



```
cat /dev/block/mmcblk0p25 > /sdcard/data.img
```
or 
	
	



```
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):

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
cp -a /data/media/0/. /external_sd/internal_backup/
```
Or if you don't have SU permission:

```
cp -a /external_sd/. /sdcard/
```
To copy from SD Card to Internal Memory:

```
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: 
	
	



```
adb shell
```
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
```
To extract from SD Card to Internal Memory (along with path):

```
tar -xvf /external_sd/internal_backup/media.tar
```
To extract from SD Card to some other location, use "-C":

```
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:

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

```
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 )

```
adb shell
```
To take ownership of whole "media" directory:

```
chown -R media_rw:media_rw /data/media/
```
To fix permissions of directories:

```
find /data/media/ -type d -exec chmod 775 '{}' ';'
```
To fix permissions of files:

```
find /data/media/ -type f -exec chmod 664 '{}' ';'
```


----------



## N-Gage4ever (Aug 7, 2019)

Thank you so much


----------



## lordaker (Aug 25, 2019)

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. 


```
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:


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


```
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)


----------



## abense (Jan 13, 2020)

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?


----------



## mirfatif (Jan 13, 2020)

abense said:


> 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?

Click to collapse



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


----------



## Swagnik (Mar 20, 2020)

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:


----------



## fhpiash (Apr 17, 2020)

I got stucked on Fastboot mode. I can't do anything even Vol up+ Vol Down+ Power also is not working. Plz help me.


----------



## Suvorik1969me (Apr 26, 2020)

Screen on the phone is untouchable.
Remind me please which command i've use via fastboot mode to shut off my phone ?


----------



## piotr1953 (Aug 28, 2020)

*Bricked lg g5 in qdl mode*



PIRATA! said:


> Hi guys!
> 
> *BACKUP / RESTORE APPS & DATA* (From/To PC)
> 
> ...

Click to collapse


----------



## heyChristo (Sep 30, 2020)

@mirfatif, Great comprehensive post!  I actually ended up here by googling.


----------



## Uredie (Jan 9, 2021)

Hey, i have one problem. When im trying to backup whole internal storage to PC, im using 

```
adb pull "/sdcard" "C:/11"
```
This works perfectly, but when i try to copy those files to my internal phone storage with command 

```
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 

```
adb push "C:/11/sdcard/DCIM" "/sdcard/"
```
?
Maybe im misunderstanding something, but it dont make difference if i wrote 

```
adb push "C:/11/sdcard/" "/sdcard/"
```
or

```
adb push "C:/11/sdcard/" "/sdcard"
```
It still make sdcard folder in my storage.


----------



## mirfatif (Jan 13, 2021)

@Uredie at least on Linux you can do: `adb push /path/to/sdcard/.* /sdcard/`


----------



## Uredie (Jan 13, 2021)

adb push /path/to/sdcard/.* /sdcard/ 
/path/to/sdcard/.* <- ".*" means everything from folder, right?


----------



## mirfatif (Jan 13, 2021)

Uredie said:


> ".*" means everything from folder, right?

Click to collapse


Yes, including hidden files. You can search about globbing and wildcards. Start from here: https://en.wikipedia.org/wiki/Glob_(programming)#Windows_and_DOS


----------



## DiamondJohn (Jan 13, 2021)

mirfatif said:


> Yes, including hidden files. You can search about globbing and wildcards. Start from here: https://en.wikipedia.org/wiki/Glob_(programming)#Windows_and_DOS

Click to collapse



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.


----------



## mirfatif (Jan 14, 2021)

DiamondJohn said:


> 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.

Click to collapse


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.


----------



## DiamondJohn (Jan 15, 2021)

mirfatif said:


> 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.

Click to collapse



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.


----------



## HemanthJabalpuri (Jan 15, 2021)

DiamondJohn said:


> 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.

Click to collapse



run these in terminal, you can get a better idea.

```
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/`.


----------



## Uredie (Jan 15, 2021)

@HemanthJabalpuri and all others thanks for answers  You are making great community 









						Screenshot
					

Captured with Lightshot




					prnt.sc
				



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:

```
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).


----------



## HemanthJabalpuri (Jan 15, 2021)

@Uredie
You can get answers to your questions by some simple tests yourself.

Thanks


----------



## mirfatif (Jan 15, 2021)

@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.


----------



## mirfatif (Apr 27, 2017)

*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*

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.
Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
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.
Disable MTP, PTP, UMS etc. from _USB computer connection_ on device to avoid any interruptions.
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.
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_.
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.
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: 
	
	



```
adb devices
```

To boot into bootloader mode: 
	
	



```
adb reboot bootloader
```

To check connected devices when in bootloader mode: 
	
	



```
fastboot devices
```

To boot into ROM: 
	
	



```
fastboot reboot
```

To boot into recovery: 
	
	



```
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: 
	
	



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



```
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: 
	
	



```
fastboot flashing unlock
```
Allow flashing of bootloader related partitions too: 
	
	



```
fastboot flashing unlock_critical
```

*FORMAT DATA PARTITION*
This will erase your data.

```
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:

```
fastboot boot recovery.img
```
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal instead of ADB.
To get SuperUser access (in ROM): 
	
	



```
su
```

To list all available partitions or mount points on device: 
	
	



```
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: 
	
	



```
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:

```
readlink /dev/block/bootdevice/by-name/userdata
```

Run the following to copy partition: 
	
	



```
dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
```
or 
	
	



```
cat /dev/block/mmcblk0p25 > /sdcard/data.img
```
or 
	
	



```
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):

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
cp -a /data/media/0/. /external_sd/internal_backup/
```
Or if you don't have SU permission:

```
cp -a /external_sd/. /sdcard/
```
To copy from SD Card to Internal Memory:

```
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: 
	
	



```
adb shell
```
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
```
To extract from SD Card to Internal Memory (along with path):

```
tar -xvf /external_sd/internal_backup/media.tar
```
To extract from SD Card to some other location, use "-C":

```
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:

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

```
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 )

```
adb shell
```
To take ownership of whole "media" directory:

```
chown -R media_rw:media_rw /data/media/
```
To fix permissions of directories:

```
find /data/media/ -type d -exec chmod 775 '{}' ';'
```
To fix permissions of files:

```
find /data/media/ -type f -exec chmod 664 '{}' ';'
```


----------



## UnderTheLKW (Oct 9, 2021)

When typing "fastboot oem device-info" nothing is displayed, only bootloader: Without true or false , what can i do ?


----------



## Deleted member 1890170 (Oct 9, 2021)

On computer install the "Android USB Driver" provided by your device's manufacturer, if not already done yet.


Also worthwhile to know: Fastboot is differently implemented by manufacturers, means not all Fastboot commands works on every device..


----------



## UnderTheLKW (Oct 10, 2021)

jwoegerbauer said:


> On computer install the "Android USB Driver" provided by your device's manufacturer, if not already done yet.
> 
> 
> Also worthwhile to know: Fastboot is differently implemented by manufacturers, means not all Fastboot commands works on every device..

Click to collapse



Driver are installed and adb finds my device but If i tipe „fastboot getvar all“ to look at the bootloader status says bootloader: and then nothing


----------



## Deleted member 1890170 (Oct 10, 2021)

You have to establish a Fastboot connection

```
fastboot devices
```


----------



## UnderTheLKW (Oct 10, 2021)

jwoegerbauer said:


> You have to establish a Fastboot connection
> 
> ```
> fastboot devices
> ```

Click to collapse



C:\adb>adb devices
List of devices attached
xxxxxx device
its connected but then i dont see the bootloader status


----------



## Deleted member 1890170 (Oct 10, 2021)

Again:


```
adb devices
adb reboot fastboot
fastboot devices
fastboot getvar all
fastboot reboot
```


----------



## UnderTheLKW (Oct 10, 2021)

jwoegerbauer said:


> Again:
> 
> 
> ```
> ...

Click to collapse



thats what shows up , i dont see if the bootloader is aktive or not

C:\adb>adb devices
List of devices attached
xxxxxxxxxxx  device


C:\adb>
C:\adb>adb reboot fastboot

C:\adb>
C:\adb>fastboot devices

C:\adb>
C:\adb>fastboot devices
xxxxxx  fastboot

C:\adb>
C:\adb>fastboot getvar all
all:
Finished. Total time: 0.001s

C:\adb>
C:\adb>fastboot reboot
Rebooting                                          OKAY [  0.000s]
Finished. Total time: 0.007s


----------



## UnderTheLKW (Oct 12, 2021)

after typing adb reboot bootloader shows me this: 
C:\adb>fastboot oem unlock
< waiting for any device >
im waiting but nothing happens , what am I doing wrong?


----------



## Deleted member 1890170 (Oct 12, 2021)

My guess is OEM Unlock isn't got enabled in Android's settings.


----------



## UnderTheLKW (Oct 12, 2021)

jwoegerbauer said:


> My guess is OEM Unlock isn't got enabled in Android's settings.

Click to collapse



unfortunately it's up to something else


----------



## UnderTheLKW (Oct 12, 2021)

jwoegerbauer said:


> My guess is OEM Unlock isn't got enabled in Android's settings.

Click to collapse



my device is not found when i have it in the fastboot menu, so i am missing the drivers but cdc drivers are not accepted by the pc and vcon does not accept my pc, what would you do?


----------



## UnderTheLKW (Oct 15, 2021)

fastboot flashing unlock
FAILED (remote: 'Not implemet.')
fastboot: error: Command failed

what can i do if this shows up?


----------



## Deleted member 1890170 (Oct 15, 2021)

Try

```
fastboot oem unlock
```

If this also fails, then bootloader isn't unlockable.


----------



## UnderTheLKW (Oct 15, 2021)

jwoegerbauer said:


> Try
> 
> ```
> fastboot oem unlock
> ...

Click to collapse



I see under recovery,  boot to bootloader but then it goes into safeboot, so you say there is no way to do it ?


----------



## Deleted member 1890170 (Oct 15, 2021)

*Save boot* ( correctly: Booting into Safe mode ) has nothing to do with device's bootloader per se.
Booting into Save mode is used to find problem apps.​

More info here:








						What is Safe Mode on Android Phones and How to fix Safe Mode Android Issues - ITechBrand
					

Safe mode temporarily blocks third-party apps from running, making it the best way to diagnose issues on your Android phone or device.




					itechbrand.com
				



.


----------



## UnderTheLKW (Oct 15, 2021)

jwoegerbauer said:


> *Save boot* ( correctly: Booting into Safe mode ) has nothing to do with device's bootloader per se.
> Booting into Save mode is used to find problem apps.​
> 
> More info here:
> ...

Click to collapse



meant that under Save boot, boot to bootloader is listed, but then by going thought it its start in fastboot, im trying to do it on linux now


----------



## UnderTheLKW (Oct 16, 2021)

trying it on linux but now adb no longer wants to recognize my device


----------



## coolek33 (Jan 29, 2022)

Hi. I'm attempting to downgrade from android 10 to 9 mine sony tv x900h via fastboot. I don't know if it's a good idea. Got images from payload.bin as on the photo. Maybe someone could point me the correct order to manual flash/commands. It has 2 slots and "b" is active one. I want "a" to be flashed with android 9.


----------



## NextB (Jan 30, 2022)

hello everyone i will be thankful if anyone helped me to backup my stock recovery.img in realme gt master edition rmx3363 i have root.


----------



## bnsmb (Mar 29, 2022)

Hi

is it possible to recover a phone by flashing images created via dd back on the phone using the "fastboot flash" command?

e.g

- boot the phone from a recovery  image with adb support
- create a backup of the important partitions

boot
dtbo
vbmeta
vbmeta_system
vendor_boot
super

via dd:

adb shell dd if=/dev/block/by_name/<partition> |  dd of=./<partition.img>


And then later use fastboot to restore the partitions  from the images, e.g

fastboot flash super  ./super.img

I tried it now a lot  of times in different  configurations (e.g. with  the original Android 11 and Android 12, with ASOPExtended 9.x ;   with and without reseting the phone before restoring the partition images, etc) but it did only work some times; most of the  times the phone did not boot anymore after restoring the partitions. And I do not know why it works sometimes and sometimes not.

Unfortunatley I did not yet found any infos regarding this approach  so:  Should that work?

If not:  Is there  another method to restore the phone using partition images?

and for the records

I'm testing with an ASUS Zenfone 8; the recovery image to create the partition images is the recovery from Lineage 18.x.; the recovery to create the image from the boot partition is TWRP booted via the command "fastboot boot <file>"

regards

Bernd


----------



## mirfatif (Apr 27, 2017)

*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*

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.
Allow ADB root access in Dev. Options or SuperSU. Some commands need root.
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.
Disable MTP, PTP, UMS etc. from _USB computer connection_ on device to avoid any interruptions.
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.
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_.
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.
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: 
	
	



```
adb devices
```

To boot into bootloader mode: 
	
	



```
adb reboot bootloader
```

To check connected devices when in bootloader mode: 
	
	



```
fastboot devices
```

To boot into ROM: 
	
	



```
fastboot reboot
```

To boot into recovery: 
	
	



```
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: 
	
	



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



```
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: 
	
	



```
fastboot flashing unlock
```
Allow flashing of bootloader related partitions too: 
	
	



```
fastboot flashing unlock_critical
```

*FORMAT DATA PARTITION*
This will erase your data.

```
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:

```
fastboot boot recovery.img
```
On next reboot, recovery will be overwritten by previous recovery.
Or to permanently flash recovery, run:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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:

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal instead of ADB.
To get SuperUser access (in ROM): 
	
	



```
su
```

To list all available partitions or mount points on device: 
	
	



```
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: 
	
	



```
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:

```
readlink /dev/block/bootdevice/by-name/userdata
```

Run the following to copy partition: 
	
	



```
dd if=/dev/block/mmcblk0p25 of=/sdcard/data.img
```
or 
	
	



```
cat /dev/block/mmcblk0p25 > /sdcard/data.img
```
or 
	
	



```
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):

```
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: 
	
	



```
adb shell
```
These commands can also be given from Recovery Terminal.
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
cp -a /data/media/0/. /external_sd/internal_backup/
```
Or if you don't have SU permission:

```
cp -a /external_sd/. /sdcard/
```
To copy from SD Card to Internal Memory:

```
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: 
	
	



```
adb shell
```
To get SuperUser access (in ROM): 
	
	



```
su
```
To copy from Internal Memory to SD Card:

```
tar cvpf /external_sd/internal_backup/media.tar /data/media/0/
```
To extract from SD Card to Internal Memory (along with path):

```
tar -xvf /external_sd/internal_backup/media.tar
```
To extract from SD Card to some other location, use "-C":

```
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:

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

```
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 )

```
adb shell
```
To take ownership of whole "media" directory:

```
chown -R media_rw:media_rw /data/media/
```
To fix permissions of directories:

```
find /data/media/ -type d -exec chmod 775 '{}' ';'
```
To fix permissions of files:

```
find /data/media/ -type f -exec chmod 664 '{}' ';'
```


----------



## edufpaz (Mar 29, 2022)

Hi @mirfatif 

Thanks for the guide.
Very important for those who are new and with little knowledge.
I saved it to my bookmark.


----------



## repoman728 (Dec 4, 2022)

ok 
and how flash recovery into partition A only - thats whats it availabe in my phone , pls  I need simple commands for fastboot


----------

