Welcome to XDA

Search to go directly to your device's forum

Register an account

Unlock full posting privileges

Ask a question

No registration required
Post Reply

[Dev] Early-ADB v3, a system backup/restore/fixing environment (D838 only)

OP pcfree

11th May 2014, 08:00 AM   |  #1  
OP Junior Member
Thanks Meter: 38
14 posts
Join Date:Joined: Sep 2011
This project may brick you phone. Use at your own risk.

What's New in v3
  1. I don't quiet understand SELinux, so the v2 did not process SELinux contexts while restoring "system", "data" and "cache" partitions. Now v3 fix it. If you'd ever restored them by v2, run v3 sub-menu "Tools"->"Restore SELinux security contexts" to fix it.
  2. Add backup boot.img and "sdcard/Android/data".
  3. Add "Wipe Dalvik cache".
  4. Add functionality to fix common boot-loop problems including "Switch runtime to Dalvik from Art", "Disable Xposed", and "Fix build.prop permission".

What's New in v2
  1. The major functionality added from v1 is to support nandroid backup/restore for "system", "data" and "cache" partitions to/from internal sdcard by using the supplied "ea-menu" shell script.
  2. The "ea-menu" also support partition management such as mount, unmout, ro and rw.

This is a project for developers who need a quick fixing and nandroid backup/restore environment for LG-D838 that still cannot install custom recovery currently. If you want to test, hack or modify system apks and/or Xposed modules but are afraid of bricking, you may try this project. Without this project, although you can recover the phone by flashing official firmware, reconstructing user settings and data is time-consuming. Normal ADB might be a solution for fixing, but you may not have enough time to fix problems before system hang up or goes into boot loop. And normal ADB cannot do nandroid backup/restore.

The Early-ADB sits in the early stage of Linux init process, right after "/system" mounted, far before Android stuffs starting. This way keeps the Early-ADB alive even if the Android stuffs such as apks or jars crash. Therefore, you can fix problems of Android stuffs by ADB through PC console.

The newly added backup/restore functions make it easier to backup and restore /system, /data and /cache partition with archive format compatible with CWM recovery.

More Information
See post #2 for more background information. And welcome to provide any technical information for FURTHER DEVELOPMENT section in post #2.

How It Works
The project hijacks e2fsck to interrupt Linux init process and redirect to its custom ADB daemon, the Early-ADB, so that you can access ADB by PC console in the early stage if required. The hijack concept comes from 2nd-init and Safestrap. While installing this project, the installer backup original e2fsck and replace it with a script. On each boot up, this script determine to go for original e2fsck as normal boot or go for Early-ADB by checking the Volume-Up key.

Basic Q&A
See post #3 for basic Q&A.

  1. Make sure you have backup your user data. Make sure your D838 is rooted. Make sure you have turned on USB Debugging option in your D838.
  2. Prepare Windows ADB utility. Currently the Early-ADB installer script is only for Windows command prompt.
  3. Download "EarlyADB.v1.zip" in the download link below, and extract it into the Windows ADB folder. Please do not process the extracted "packs.zip". Keep it unchange.
  4. Connect the D838 phone to your Windows PC through USB cable.
  5. In your Windows PC, open a command prompt and "cd" to your ADB directory. Type "install" to run the Early-ADB installer.

  1. Walk through the same steps as above Installation 1 to 4.
  2. In your Windows PC, open a command prompt and "cd" to your ADB directory. Type "unins" to run the Early-ADB uninstaller.

How To Use
  1. Power on or reboot your D838.
  2. When you see LG logo, press and hold Volume-Up key. After seeing the screen dims obviously, you can release the Volume-Up key. Now early-ADB daemon is running and Linux init is hold.
  3. Connect D838 to any PC with adb through USB cable.
  4. By using adb shell, run "ea-menu" to backup/restore to/fram internal sdcard, or fix problems manually.
  5. To leave Early-ADB daemon, press and hold power button for at least 8 seconds to reboot the phone.
  6. The internal sdcard is not a safe place for nandroid backup files. Remember to copy them to external sdcard.

Limitations And Known Issues
  1. Only "/system", "/data" and "/cache" are mounted. Manually mount other partitions if required.
  2. The Early-ADB daemon sits in early init stage that many services are not ready to use and some normal adb functionalities cannot work. For examples, you cannot reboot by software commands. You cannot get model name from getprop command. However, you can "push" and "pull" files and access "/system" and "/data" to fix many crash problems.
  3. Don't expect this project as a brick protection. If you destory bootloader, this project can do nothing.
  4. Don't do OTA upgrade. Any system files modification may (or may not, it depends) result in brick.
  5. The Google Music media files are prevented from backup by Early-ADB. Backup them by yourself, otherwise if you recover data partition, you will lose them.

v3: EarlyADB.v3.zip
v2: EarlyADB.v2.zip, obstacle due to SELinux problem. Download it only for research purpose.
v1: EarlyADB.v1.zip, mirror

eladbd daemon source: eladb_mod.zip, modified from https://source.android.com/source/downloading.html branch android-4.4.2_r2, only modified part is included in the zip.

v3 (2014/05/21)
  1. BUGFIX: Restore SELinux security contexts if restoring /system, /data or /cache partition.
  2. Add backup/restore kernel (boot.img)
  3. Add backup/restore /sdcard/Android/data contents
  4. Add Tools sub-menu to "Wipe Dalvik cache".
  5. In Tools sub-menu, add fix to common boot-loop problems including "Switch runtime to Dalvik from Art", "Disable Xposed" and "Fix build.prop permission".
  6. In Tools sub-menu, add fix to v2 bug "Restore SELinux security contexts".
  7. Reduce package size by minimizing installer busybox.
  8. Auto mount partitions for backup/restore operations.
  9. Ask user to confirm restore operation.

v2 (2014/05/18)
  1. Run early then v1, right after /system mounted.
  2. Default mount system, data and cache partitions.
  3. Add "ea-menu" to run from adb shell, so you can do nandroid backup/restore for system, data and cache partitions.
  4. Introduce new "SAFE" mount concept by mounting partitions in non-standard /mnt/system, /mnt/data, and /mnt/cache to prevent from accessing accidentally by other unknown background services while restoring.
  5. Build busybox from source code 1.22.1 (source available from http://www.busybox.net)
  6. Build pigz 2.3.1 for using by nandroid backup/restore (source available from http://zlib.net/pigz/)
  7. Build static verion of mksh, so that in SAFE mount we don't have to rely on system partition for shell. (source available from https://source.android.com/source/downloading.html branch android-4.4.2_r2 )

v1 (2014/05/11)
  1. Initial testing release

Savoca of directing me to Safestrap and 2nd-init concepts
Hashcode with Safestrap project for concept of hijacking e2fsck

XDA:DevDB Information
Early-ADB, Tool/Utility for the LG G Pro 2


Version Information
Status: Testing

Created 2014-05-11
Last Updated 2014-05-21
The Following 8 Users Say Thank You to pcfree For This Useful Post: [ View ]
11th May 2014, 08:00 AM   |  #2  
OP Junior Member
Thanks Meter: 38
14 posts
Join Date:Joined: Sep 2011
Somthing about this project
After hacking the TOT file format to root D838 with ioroot (see my post [Tutorial] How to root D838 that cannot enter recovery mode), I start thinking of customizing my phone. Without custom recovery, it make me uncomfortable to hack system apks or try out Xposed. This leads to my first attempt.

1st Attempt -- Porting Loki-Friendly aboot.img
Initially, I want to port loki-friendly D802 JellyBean aboot.img to D838. If it successes, we would have custom recovery, custom kernel and custom ROM. Choosing D802 is because they use the same QualComm S800 chip and both com from LG. I studied the bootloader chain and tried to make lokified stock kernel with the help from xda Recognized Developer Savoca. I found the possibly best solution would be install D802 JB aboot.img and laf.img into D838 with a lokified custom-made rebuilt D838 stock kernel. However, I cannot make sure if my phone will survive from brick if the testing is failed.

If D838 KK sbl1.img (1st secondary bootloader) cannot accept D802 JB aboot.img, the phone will enter bulk device mode which can be recovered from brick in Linux PC. On the other hand, if D802 aboot.img is accepted to run but hang up due to other issues, the thing becomes more complicated. My D838 is for my daily work use. Without a backup phone, I am not ready to try the concept. The project is not dead yet, but pending now.

2nd Attempt -- 2ndrec
Savoca also direct me to Safestrap project. As new to Android dev, it is complex for me to port such a job. However, I think it may be possible to run a recovery environment by 2nd-init. Some attemptions were made to port D802 ramdisk of cwm recovery by 2nd-init without success, then I try to study my own "2ndrec" without 2nd-init. I want to make a modified recovery-like program to be injected into Linux init process. Without understanding of displaying things to the framebuffer, I pending this project too.

3rd Attempt -- Early-ADB
As eager to have a fix/recovery environment, I start to focus on adbd (adb daemon). I've found it is much easier to run adbd if I can prepare the basic environment for it and rebuild a custom adbd without unnecessary check. And this the project here.

You are welcome to provide information for the following subjects

Manually Mount Internal SDCARD
In normal environment (means non-Early-ADB), internal sdcard is a virtual device which is mapped by fuse from "/data/media/0" directory. I don't know if it is a good idea, but you may do the following commands to link it by yourself in adb shell for Early-ADB.
mount -o remount,rw rootfs
rm /sdcard
ln -s /data/media/0 /sdcard
The side effect for the soft link method is all files/dirs created would be root owned. This is different from uid 1023 (media_rw) created by fuse. However, this may not be a problem because in noraml environment fuse oversides all permissions. It means after reboot you can still get full access of all files on fuse mapped virtual sdcard.

Starting from Early-ADB v2, it is not recommanded to link sdcard because SAFE mount makes the internal sdcard path vary.

If you want to do thing such as manually backup "/data" contents to "/sdcard", remember to exclude "/data/media/0" because "/sdcard " is linked to "/data" contents. This is not a problem for "ea-menu" script because it automatically excludes virtual internal sdcard.

Manually Mount External SDCARD
You are welcome to provide information on how to manually mount D838 external sdcard. I know the exact block device of external sdcard is "/dev/block/mmcblk1p1". However, direct mount command does not succeed for my exfat sdcard. If we can mount external sdcard, we can do thing much more for Early-ADB. For example, we can backup and restore "/system" and "/data" partition as custom recovery does. For newer un-rootable stock firmware, you may build custom stock system.img by injecting "su" and "Early-ADB" first, then install it by this project.
Last edited by pcfree; 18th May 2014 at 06:17 AM.
The Following 3 Users Say Thank You to pcfree For This Useful Post: [ View ]
11th May 2014, 08:00 AM   |  #3  
OP Junior Member
Thanks Meter: 38
14 posts
Join Date:Joined: Sep 2011
Basic Q&A
Can I use Early-ADB to install apks or run adb backup/restore command?
Better not to try. I have not tried it yet. However, many system services do not start up yet. You will probably fail to do these works.

Can I use adb push/pull command to exchange files?

Is the Early-ADB daemon rooted?
Yes, the Early-ADB daemon runs as root. After installed, it does not rely on "su" binary. Even if your "su" is deleted suddently, you can use Early-ADB to push it back.

Can I do OTA update after installing Early-ADB?
No, never try it. It depends on OTA update script and update contents, but you never know. Any "/system" partition modification may cause OTA fail if the modified files are in the OTA update list. However, currently we cannot modify bootloader stacks, usually we can flash stock firmware to recover from OTA fail.

By using Early-ADB, you have many ways to manually upgrade stock firmware while keeping root. Since Early-ADB v2, a custom nandroid compatible stock firmware files is also a solution.

May I use the Early-ADB for F350 series G Pro 2?
Some parameters are reterieved from D838. It may or may not works with F350 series. Try at your own risk. Use "install -f" and "unins -f" instead in the last step of installation and uninstallation procedures.

How to use "ea-menu" shell script?
Use "adb shell" to connect to your phone in Early-ADB mode. Then type "ea-menu" to run it. It is a menu-driven script and not too hard to learn how to use it.

Why is the internal sdcard not a safe place to keep nandroid backup files?
The internal sdcard is a fuse device located on data partition. If you do factory reset, you will lose these backup files too. Keep them on external sdcard or other place for safety.
Last edited by pcfree; 18th May 2014 at 06:29 AM.
The Following 5 Users Say Thank You to pcfree For This Useful Post: [ View ]
12th May 2014, 04:17 PM   |  #4  
Senior Member
Thanks Meter: 138
541 posts
Join Date:Joined: Aug 2007
Donate to Me
good post, thanks
18th May 2014, 06:40 AM   |  #5  
OP Junior Member
Thanks Meter: 38
14 posts
Join Date:Joined: Sep 2011
Early-ADB now upgrades to v2. Now you can use it to do nandroid backup and restore for "system", "data", and "cache" partitions to/from internal sdcard. Thus it may be more useful than just fixing.

With the backup/restore function, you may also safely upgrade to future stock firmware by making custom nandroid archive files from stock firmware while keeping root and Early-ADB.
The Following 4 Users Say Thank You to pcfree For This Useful Post: [ View ]
21st May 2014, 07:52 PM   |  #6  
OP Junior Member
Thanks Meter: 38
14 posts
Join Date:Joined: Sep 2011
Release v3. This release includes one bugfix and several improvements:

BUGFIX: In v2, while restoring "system", "data" or "cache" partitions, SELinux security contexts are not processed. Now v3 fix it. If you've ever used v2 to restore partitions, you'd better use v3 new Tools sub-menu => "Restore SELinux security contexts" to fix it. The backup archive files created by v2 are still ok, but you have to use v3 to restore them.

  1. Add backup/restore kernel (boot.img)
  2. Add backup/restore /sdcard/Android/data contents
  3. Add "Wipe Dalvik cache" in Tools sub-menu.
  4. In Tools sub-menu, add fix to common boot-loop problems including "Switch runtime to Dalvik from Art", "Disable Xposed" and "Fix build.prop permission".
  5. Reduce package size by minimizing installer busybox (rebuild).
  6. Auto mount partitions required for backup/restore operations.
  7. Ask user to confirm restore operation.
The Following 4 Users Say Thank You to pcfree For This Useful Post: [ View ]
20th November 2014, 01:27 PM   |  #7  
Flag Derbyshire
Thanks Meter: 5
41 posts
Join Date:Joined: Jul 2014
Hello, so can this make a FULL backup? And a full restore? Essentially using your pc as the recovery?

Post Reply Subscribe to Thread
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes