tarball over adb exec-in without temporary files - Android Q&A, Help & Troubleshooting

I'm looking for a way to transfer files with the correct permissions over adb. I can create a tarball and push it to my phone on the fly but for some reason I can't extract it without creating a temporary file. What I mean is that
Code:
tar -c file | adb exec-in 'cat > /file.tar' && adb shell 'tar -xf /file.tar -C dir'
works but
Code:
tar -c file | adb exec-in 'tar -xf - -C dir'
doesn't. Actually, it does but not all files are transferred over. Am I missing out on something?

@Ciren__
adb exec-out and/or adb exec-in
writes/reads to/from only files

I've used this:
Bash:
tar czplf - --acls --selinux --xattrs --numeric-owner -C /mnt/tmp/ data/com.android.messaging | adb exec-in tar -f - -x -p -z -v -C /data
... to restore an app from a whole partition image backup (mounted with `kpartx` and `mount -t ext4 -o ro,noload`).
I'm not sure if all those flags are actually needed, but that was my first guess at something which I thought would work.

Related

[Q] Nandroid Backup in CWM 6.0.1.5

So I have been having this issue lately that I cant seem to figure out.
In CWM 4, I could create a backup, move the files to my computer, then I run the following script to put that backup onto another galaxy tab.
@echo off
set devicename=%1
echo Copying the Images
adb -s %devicename% shell mount /data
adb -s %devicename% shell "mkdir -p /data/media/clockworkmod/backup/current"
adb -s %devicename% shell sync
adb -s %devicename% push boot.img /data/media/clockworkmod/backup/current/boot.img
adb -s %devicename% shell sync
adb -s %devicename% push cache.img /data/media/clockworkmod/backup/current/cache.img
adb -s %devicename% push data.img /data/media/clockworkmod/backup/current/data.img
adb -s %devicename% push system.img /data/media/clockworkmod/backup/current/system.img
adb -s %devicename% shell sync
echo Producing new MD5 Hash
adb -s %devicename% shell "cd /data/media/clockworkmod/backup/current ; md5sum *img > nandroid.md5"
rem adb shell mount /system
rem echo "Getting MAC Address"
rem adb shell grep mac /system/etc/wifi/nvram_net.txt
rem adb shell umount /system
rem adb -s %devicename% reboot
echo You can Restore now
Click to expand...
Click to collapse
I could then restore that backup on the second tablet with very little issues. I would get some stale data in various apps but for the most part, it worked.
Since installing CM10 Jelly Bean, I had been getting the rolling recovery screen until I updated to CWM6. I had both the Rolling Recovery issue, as well as the Rolling Wake-Up issue. I have been able to resolve both of those but one thing continues to plague me.
I knew I had to modify the script to reflect the new file names of the backup.
@echo off
set devicename=%1
echo Copying the Images
adb -s %devicename% shell mount /data
adb -s %devicename% shell "mkdir -p /data/media/clockworkmod/backup/current"
adb -s %devicename% shell sync
adb -s %devicename% push boot.img /data/media/clockworkmod/backup/current/boot.img
adb -s %devicename% shell sync
adb -s %devicename% push cache.ext4.dup /data/media/clockworkmod/backup/current/cache.ext4.dup
adb -s %devicename% push data.ext4.dup /data/media/clockworkmod/backup/current/data.ext4.dup
adb -s %devicename% push system.ext4.dup /data/media/clockworkmod/backup/current/system.ext4.dup
adb -s %devicename% shell sync
echo Producing new MD5 Hash
adb -s %devicename% shell "cd /data/media/clockworkmod/backup/current ; md5sum *img > nandroid.md5"
rem adb shell mount /system
rem echo "Getting MAC Address"
rem adb shell grep mac /system/etc/wifi/nvram_net.txt
rem adb shell umount /system
rem adb -s %devicename% reboot
echo You can Restore now
Click to expand...
Click to collapse
Any backups I create in CWM6 will not restore on the secondary tablet. Both run CWM6, Both run the same bootloader, both are identical in every way. But when I try and restore, I get:
CWM-based Recovery v6.0.1.5
Checking MD5 sums...
Erasing boot before restore...
Restoring boot image...
Restoring system...
Error while restoring /system!
Click to expand...
Click to collapse
I have to restore an "image" to several hundred Galaxy Tablets and I need the system to be pretty much completely customized; as far as homescreen placement of apps, background, USB debugging, locked apps, etc.
Can anyone explain why I could back up one tablet "image" and restore to another on CWM4 but not on CWM6? Is there something wrong with the script I'm running to move the files? Specifically the portion about Producing a new MD5 Hash. Would TWRP be a better option here? I use that recovery on my HTC One S.
Or better yet, give me some kind of Rom Kitchen for the Galaxy Tab 10.1 wifi?? I'm not smart enough to build a rom from scratch, but then again, this was all jargon to me 5 years ago.
I am very appreciative of any advice the community can provide. I've been using this forum for years and can pretty much give credit to XDA for every piece of mobile development knowledge I do have, little as it may be.
cmw 6 probably doesnt have system.img
it's probably system.tar

[Q] Stuck on boot animation after flashing modified factoryfs.img via Odin

Hi,
I wanted to take stock Odin ROM, add one file to /system partition. That's all.
I managed to create such ROM, flashed it on device, but it's fails to complete the boot (stucks on the Samsung boot animation).
What I did wrong?
What I did:
(working on OpenSuse 12.x, Samsung 9100, Odin 3.0.9, some stock ROM in Odin format)
Code:
#!/bin/bash
#file that should be added to the system image
_myFile=$1
#path to the stock Odin ROM (tar.md5)
_sourceOdinPackage=$2
#path to the output folder
_targetFolder=$3
#name (without extension) of the output Odin ROM
_targetOdinPackageName=`basename $_sourceOdinPackage`
#path to folder with compiled ext4_utils
_toolsDir=/tmp/ext4_utils
#path to the temporary folder
_tempDir=/tmp/me
mkdir -p "$_tempDir/package"
cd "$_tempDir/package"
#unpack the tar archive
tar xvf $_sourceOdinPackage
#convert ext4 sparsed image to normal ext4, which can be mounted
$_toolsDir/simg2img "$_tempDir/package/factoryfs.img"" "$_tempDir/system.ext4.img"
#remove original system image
rm $_tempDir/package/factoryfs.img
mkdir -p $_tempDir/system
#mount the system
mount -t ext4 -o user_xattr $_tempDir/system.ext4.img $_tempDir/system
#put the file I wanted into system
cp $_myFile $_tempDir/system/
#create the new ext4 sparsed image
$_toolsDir/make_ext4fs -s -l 512M $_tempDir/package/factoryfs.img $_tempDir/system
#release mount
umount $_tempDir/system
#pack files to tar archive
_toTarFiles=`find * -type f 2>/dev/null | tr '\n' ' '`
tar -H ustar -c $_toTarFiles > $_targetFolder/$_targetOdinPackageName.tar
cd $_targetFolder
#add MD5 checksum
md5sum -t $_targetOdinPackageName.tar >> $_targetOdinPackageName.tar
mv $_targetOdinPackageName.tar $_targetOdinPackage.tar.md5
I am using ext4_utils before SELINUX change, as I am flashing 4.0.4
Update: also tried ext4_utils after SELINUX change, it works if "-a" parameter is not given. Same result.
SOLVED - Using EpicAOSP make_ext4 binaries

[Q] Need urgent help with adb fastboot nandroid backup (paid assistance)

Hi,
I have idea like "backup all data (include apps, accounts, system settings) -> wipe all data -> upload backup -> start device", but backup upload on server by ftp/sftp.
After few times another script download necessary backup and upload on phone by adb/fastboot and start device.
Now i create backup by this script (sorry, i`m only learn)
Code:
adb wait-for-device
set dirname=%date:~0,2%%date:~3,2%%date:~8,2%%time:~0,2%%time:~3,2%
mkdir %dirname% > NULL
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep system | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\system.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep boot | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\boot.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep recovery | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\recovery.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep cache | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\cache.img
adb shell rm /sdcard/blkbackup.img
adb shell su -c "dd if=/$(ls -la /dev/block/platform/msm_sdcc.1/by-name | grep userdata | sed -r 's/.* .//') of=/sdcard/blkbackup.img"
adb pull /sdcard/blkbackup.img %dirname%\userdata.img
adb shell rm /sdcard/blkbackup.img
adb shell "pm list package -s" > %dirname%\system.apps.list
adb shell "pm list package -3" > %dirname%\3d-party.apps.list
i think what this logicaly work, but in realy - dont work and i cant upload backup in server.
can you explain me how i can create fully backup android device and restore it adter few days in device by shellscript.
In an ideal world I see it this way:
1) made a backup using http://forum.xda-developers.com/showthread.php?t=1620255
2) loading on server
3) another script download the desired backup and load it on your phone or PC
4) install
4.1) profit
PS Since I need it urgently enough and I tried huge amount of scripts and commands - asking for your help (in debt will not stay).
PPS ubuntu
Skype: a.roman2403

Installing SuperSU root on Mi 5c

Here's a guide + script for installing SuperSU root on the Mi 5c.
I haven't yet managed to build a TWRP recovery image for it (I haven't really tried) - so this can be used to get root in the mean-time. (I also saw a Chinese TWRP ROM on the MIUI forums, but I haven't tried it myself)
Obviously modifying the phone system is risky, you may void the warranty, break it etc. I take no responsibility for that, and you use the instructions below at your own risk.
The script, and a few other tools I'm using for the Mi 5c can be found in my git repo: github.com/usedbytes/meri_tools
To use the script, you'll need a linux (or Mac, probably) computer with gcc and git installed, as well as a new-ish version of adb and fastboot. I'm running it on Arch Linux fine.
First get the phone into developer mode (tap on the MIUI version in About Phone 7 times), and enable adb debugging, and approve your computer to access debugging.
Then you need to download and extract the SuperSU "Installable Recovery" zip, and the Xiaomi stock ROM, which we will use for the install files.
Then, run the script below (meri_root.sh in the git repo).
The script installs all the bits needed, then reboots the phone with a rooted boot image. To make the root persistent, you need to flash the boot.supersu.img to the boot partition with fastboot (it just boots it by default).
Code:
#!/bin/bash
#
# Script to root the Xiaomi Mi 5c, by manually installing SuperSU
#
# Copyright 2017 Brian Starkey
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
# -- Disclaimer
#
# Obviously modifying your phone can be dangerous, void the warranty etc. etc.
# Use this script and the instructions within it at your own risk.
#
# -- Description
#
# The SuperSU installer seems to assume you already have root, and is intended
# to be run from a custom recovery (like TWRP). We don't have that, so we'll do
# some funny dances to do a systemless root without having root to begin with.
#
# The crux of the matter is using SuperSU's tools to patch the ramdisk and
# sepolciy (in /data/local/tmp, without root), then building a ramdisk with
# those components
#
# -- Usage
#
# Plug in the phone, make sure you have (persistent) adb debugging permissions
# and run this script like so:
# meri_root.sh SUPERSU_DIR ROM_DIR
# Where SUPERSU_DIR is a directory where you have downloaded and extracted the
# SuperSU "Recovery Flashable" zip file: http://www.supersu.com/download
# and ROM_DIR is a directory where you have downloaded and extracted the ROM
# from Xiaomi's download page: http://en.miui.com/download-322.html
#
# The script will make and boot a boot.img which enacts a systemless root.
# To make it persisent, you must flash it instead:
# fastboot flash boot.supersu.img
#
# By default, SuperSU removes dm-verity from /system and encryption from /data
# To prevent this, set PRESERVE_VERITY=1 before running the script:
# PRESERVE_VERITY=1 ./meri_root.sh ...
if [ $# -ne 2 ];
then
cat >&2 <<EOM
Usage: $(basename $0) SUPERSU_DIR ROM_DIR
Extract SuperSU zip file into SUPERSU_DIR, and the Xiaomi ROM into ROM_DIR,
then run this script.
EOM
exit 1
fi
SUPERSU_DIR=$1
echo ${SUPERSU_DIR}/arm64/su
if [ ! -f ${SUPERSU_DIR}/arm64/su ]
then
echo "Invalid SUPERSU_DIR" >&2
exit 1
fi
ROM_DIR=$2
if [ ! -f ${ROM_DIR}/boot.img ]
then
echo "Invalid ROM_DIR" >&2
exit 1
fi
# 1. Get mkbootimg and build it
git clone --depth 1 https://github.com/osm0sis/mkbootimg.git || exit 1
cd mkbootimg
make || ( cd .. && exit 1 )
cd ..
# 2. Copy the SuperSU binaries to the device
echo "Waiting for device..."
adb wait-for-usb-device
adb push ${SUPERSU_DIR}/arm64/*su* /data/local/tmp/ || exit 1
adb shell chmod +x /data/local/tmp/su*
# 3. Create the SuperSU systemless root image
# Ideally we'd set up security contexts too, but then you need to be running
# on an SELinux-enabled kernel in permissive mode.
# Instead, we will fix it on first boot.
dd if=/dev/zero bs=1M count=96 of=su.img
mkfs.ext4 su.img
mkdir mnt
sudo mount su.img mnt
sudo mkdir mnt/{bin,xbin,lib,etc,su.d}
sudo chmod 0751 mnt/bin
sudo chmod 0755 mnt/{xbin,lib,etc}
sudo chmod 0700 mnt/su.d
sudo cp ${SUPERSU_DIR}/arm64/{su,sukernel} mnt/bin/
sudo cp ${SUPERSU_DIR}/arm64/su mnt/bin/daemonsu
sudo cp ${SUPERSU_DIR}/arm64/supolicy mnt/bin/supolicy_wrapped
sudo ln -s /su/bin/su mnt/bin/supolicy
sudo chown root:root mnt/bin/{su,daemonsu,sukernel,supolicy_wrapped}
sudo chmod 0755 mnt/bin/{su,daemonsu,sukernel,supolicy_wrapped}
sudo cp ${SUPERSU_DIR}/arm64/libsupol.so mnt/lib/libsupol.so
sudo chown root:root mnt/lib/libsupol.so
sudo chmod 0644 mnt/lib/libsupol.so
# Run a script at first-boot to fix up the SELinux contexts on the image
# It will remove itself after running
sudo bash -c "cat > mnt/su.d/firstboot.rc" <<EOF
#/system/bin/sh
chcon -hR u:object_r:system_data_file:s0 /su /data/local/tmp/su.img
rm /su/su.d/firstboot.rc
sync
EOF
sudo chmod 0750 mnt/su.d/firstboot.rc
sync
sudo umount mnt
# 4. Copy the systemless root image to the device
adb push su.img /data/local/tmp/su.img
# 5. Extract boot.img
mkdir bootimg
mkbootimg/unpackbootimg -o bootimg -i ${ROM_DIR}/boot.img
# 6. Unzip the ramdisk
cat bootimg/boot.img-ramdisk.gz | gunzip > ramdisk
# 7. Copy the ramdisk to the device, for patching
adb push ramdisk /data/local/tmp
# 8. Patch sepolicy and the ramdisk, using the SuperSU tools we copied over
# earlier
adb shell "
cd /data/local/tmp
LD_LIBRARY_PATH=. ./supolicy --file /sepolicy ./sepolicy.patched
LD_LIBRARY_PATH=. ./sukernel --patch ./ramdisk ramdisk.patched
"
# 9. Pull back the patched files
adb pull /data/local/tmp/sepolicy.patched /data/local/tmp/ramdisk.patched .
# 10. Extract the patched ramdisk, and install the patched sepolicy into it
mkdir ramdir
cat ramdisk.patched | sudo cpio --no-absolute-filenames -D ramdir -i
sudo cp sepolicy.patched ramdir/sepolicy
sudo chown root:root ramdir/sepolicy
sudo chmod 0644 ramdir/sepolicy
# 11. Install the SuperSU init scripts
sudo mkdir ramdir/su
sudo chmod 755 ramdir/su
sudo cp ${SUPERSU_DIR}/common/launch_daemonsu.sh ramdir/sbin
sudo chmod 744 ramdir/sbin/launch_daemonsu.sh
sudo chown root:root ramdir/sbin/launch_daemonsu.sh
sudo cp ${SUPERSU_DIR}/common/init.supersu.rc ramdir
sudo chmod 750 ramdir/init.supersu.rc
sudo chown root:root ramdir/init.supersu.rc
# 12. Patch the initscript for our img location and set the su.img context
sudo sed -i 's;/data/su.img;/data/local/tmp/su.img;' ramdir/init.supersu.rc
sudo sed -i '\;on property:sukernel.mount=1;a\ \ \ \ restorecon /data/local/tmp/su.img' ramdir/init.supersu.rc
sudo bash -c "echo /data/local/tmp/su.img u:object_r:system_data_file:s0 >> ramdir/file_contexts"
# Optional: Preserve dm-verity on /system, encryption on /data
if [ ! -z "$PRESERVE_VERITY" ] && [ $PRESERVE_VERITY -ne 0 ]
then
echo "Preserving dm-verity"
mkdir ramdir-stock
cat ramdisk | sudo cpio --no-absolute-filenames -D ramdir-stock -i
sudo cp ramdir-stock/{fstab.song,verity_key} ramdir/
sudo rm -rf ramdir-stock
fi
# 13. Repack the ramdisk
cd ramdir
sudo find . ! -path . | sudo cpio -H newc -o | gzip > ../ramdisk.gz
cd ..
# 14. Repack the boot image
mkbootimg/mkbootimg \
--kernel bootimg/boot.img-zImage \
--ramdisk ramdisk.gz \
--cmdline "console=ttyS0,115200 earlyprintk=uart8250-32bit,0xF900B000 androidboot.hardware=song no_console_suspend debug user_debug=31 loglevel=8" \
--base 0x0 \
--pagesize 4096 \
--kernel_offset 0x0a080000 \
--ramdisk_offset 0x0c400000 \
--dt bootimg/boot.img-dtb \
--tags_offset 0xc200000 \
--os_version 0.0.0 \
--os_patch_level 0 \
--second_offset 0x00f00000 \
--hash sha256 \
--id \
-o boot.supersu.img
# 15. Boot it! (flash it if you want to make it persistent)
adb reboot-bootloader
fastboot boot boot.supersu.img
echo "Waiting for device..."
adb wait-for-usb-device
Hi ,
Can you give me some advice on how to run this on Windows? I can get a adb shell but thats as far as I can get. I don't know how I am supposed to run the script.
Thanks
Stewart
Hello,
I am trying to root my mi 5c with your script, but I can't find sepolicy file on my phone, so for example this line can't be executed:
Code:
LD_LIBRARY_PATH=. ./supolicy --file /sepolicy ./sepolicy.patched
Do you know where I could find this file? I am using xiaomi.eu_multi_MI5c_7.4.6_v8-7.1 rom.
Hello,
I've had exactly the same issue on a multirom and on xiaomi.eu_multi_MI5c_7.4.20(although i'm not sure if installed rom has something to do with it)
blagon said:
...I am trying to root my mi 5c with your script, but I can't find sepolicy file on my phone...
Click to expand...
Click to collapse

Tolino e-Reader with broken android

Hey Guys,
i got a broken Tolino Vision 3 HD from a friend to fix the issues with the android. It´s a popular ebook reader in Germany.
At the moment I got the device it stuck in language selection and the partition for the ebooks wasn´t shown after USB connection.
So I downloaded the new software version from the vendor "mytolino" (I am not allowed to post urls). I tried to update via
fastboot update
Click to expand...
Click to collapse
but i got this error:
archive does not contain 'android-info.txt'
error: update package '..\update.zip' has no android-info.txt
Click to expand...
Click to collapse
. So I unpack the .zip and try to flash the images manualy. This didn´t work. After this is tried to copy the update.zip to /sdcard via adb push but this didn´t work, too.
Question:
Is there any way to flash the device with the given update.zip?
Regards and all good wishes from sunny Germany
Did you tried to do factory reset? Are you able to boot into recovery using key-combination?
The more heavy way I used yesterday to reanimate my Tolino page after trying to install OpenGapps on them (no, did not work oO).
I am not allowed to post URL's because of "Noob-Protection" in Forum. There is a "Tolino Vision 2 rooten" howto in web. Some parts of them you can use to solve your problem.
1. Create own ADB-Enabled custom recovery (Did worked for me only with 10.0.1 update package). Should be done on Linux
Code:
$ mkdir custom_recovery
$ cd custom_recovery
$ unzip ../update.zip recovery.img
$ mv recovery.img recovery.img.orig
$ abootimg -x recovery.img.orig
$ mv initrd.img initrd.img.orig
$ mkdir initrd
$ cd initrd
$ zcat ../initrd.img.orig | cpio -vid
Adjust default.prop with values "ro.secure=0", "ro.debuggable=1" und "persist.sys.usb.config=mass_storage,adb".
Code:
$ find . | cpio --create --format='newc' | gzip > ../initrd_adb_enabled.img
$ cd ..
$ abootimg --create recovery_adb_enabled.img -f bootimg.cfg -k zImage -r initrd_adb_enabled.img
You get error : "updated is too big for the Boot Image" with new size value. Calculate this value to hexadecimal and adjust the "bootsize" in "bootimg.cfg" to hex-value
Do abootimg again.
2. Use the custom recovery to trigger update manually
Code:
$ fastboot boot ../custom_recovery/recovery_adb_enabled.img
$ adb shell
# mount -t vfat /dev/block/mmcblk0p4 /sdcard/
# exit
$ adb push update.zip /sdcard/update.zip
$adb shell
# cd /sdcard
# busybox unzip update.zip META-INF/com/google/android/update-binary -d /tmp
# busybox chmod u+x /tmp/META-INF/com/google/android/update-binary
# /tmp/META-INF/com/google/android/update-binary 3 1 /sdcard/update.zip # Update installieren
# sync && sleep 5 && sync # sicherheitshalber, wenn man dran glaubt
# reboot
Source: google for "e-reader-forum Toolino vision 2 rooten"

Categories

Resources