How to unzip, unpack and convert android rootfs to ext4 - android

Android rootfs is compressed and split into:
super.raw.00.gz, super.raw.01.gz, super.raw.03.gz, super.raw.04.gz
How to unzip, combine, unpack them to ext4 files that can be mounted ?

Steps are:
Unzip each of the multi-zip files:
gzip -d super.raw.00.gz
gzip -d super.raw.01.gz
gzip -d super.raw.02.gz
gzip -d super.raw.03.gz
Concatenate them to a single file:
cat super.raw.00 super.raw.01 super.raw.02 super.raw.03 > super.raw
Unpack the super image using lpunpack tool. Download link.
./lpunpack super.raw
Mount the image- For eg: system_a
mkdir mount_system
sudo mount -t ext4 -o loop system_a.img mount_system

Related

Mount qcow2 image created by Android emulator

I'm trying to mount the userdata-qemu.img.qcow2 file created by the Android emulator. The following procedure does not work:
sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2
First command runs well, but running
sudo qemu-nbd -c /dev/nbd0 ~/.android/avd/Pixel_C_API_27.avd/userdata-qemu.img.qcow2
results in this output:
Fehler: /dev/nbd0: unbekannte Partitionstabelle
Modell: Unbekannt (unknown)
Festplatte /dev/nbd0: 3146MB
Sektorgröße (logisch/physisch): 512B/512B
Partitionstabelle: unknown
Disk-Flags:
Basically it cannot recognize a partition table in the image file. You may wonder what's the output of
fdisk /dev/nbd0 -l
so here it is:
Medium /dev/nbd0: 3 GiB, 3145728000 Bytes, 6144000 Sektoren
Einheiten: sectors von 1 * 512 = 512 Bytes
Sektorengröße (logisch/physisch): 512 Bytes / 512 Bytes
I/O Größe (minimal/optimal): 512 Bytes / 512 Bytes
As you could expect already, mounting fails of course, since no partitions can be recognized if the partition table itself cannot be recognized either. Thanks for any help!
Edit: I've just found out that the problem must have to do with Android's userdata encryption. As I've never changed any password the encryption password of the emulator's userdata partition would have to be the default one "default_password". How can I decrypt the image to be able to mount it?
You can mount userdata-qemu.img.qcow2 using the following procedure
convert the image to a raw image
qemu-img convert -O raw userdata-qemu.img.qcow2 udata-raw.img
use losetup to setup a loopback device for mounting
sudo losetup -f -P userdata.img
use losetup -l to see what device was setup
losetup -l
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO
/dev/loop0 0 0 0 0 /path/to/userdata.img 0
mount the drive
mkdir /tmp/mnt
sudo mount /dev/loop0 /tmp/mnt
Then ls /tmp/mnt/ gives
app benchmarktest benchmarktest64 lost+found misc nativetest nativetest64

Shell Script to remove lines of text in a text file

How can I remove a line of text in a file if it exists?
So far I am guessing
#!/sbin/sh
mount -o remount,rw /system;
# Make a backup first
cp /system/build.prop /system/build.prop.bak;
# Append
if [ grep -o 'wifi.supplicant_scan_interval' <<</system.build.prop > 1 ]; then
echo "YO";
fi;
mount -o remount,ro /system;
however, this shows me YO no matter of it is > 1 or < 1 (it does exist in the file), so this part seems wrong, also, I don't know how I could remove the line?
Can you help?
Code Update
#!/sbin/sh
mount -o remount,rw /system;
function check_prop(){
busybox grep $1 /system/build.prop;
return $?;
}
# Make a backup first
cp /system/build.prop /system/build.prop.bak;
echo $(check_prop 'wifi.supplicant_scan_interval');
# Append
if [ $(check_prop 'wifi.supplicant_scan_interval') > 1 ]; then
# Do my stuff here?
echo 'YO';
fi;
mount -o remount,ro /system;
is returning me a blank line, and YO. If I change it to < 1 it does the same thing
sed '/wifi.supplicant_scan_interval/d' inputfile
would remove lines matching wifi.supplicant_scan_interval
eg
$cat input
hello
world
hai
$sed '/world/d' input
hello
hai
if you want to delete line from file use -i option which is does the action inplace
sed -i '/wifi.supplicant_scan_interval/d' inputfile
EDIT
using grep to print all lines except the lines that match the patter.
grep -v 'wifi.supplicant_scan_interval' inputfile
eg
$ grep -v 'world' input
hello
hai
the -v option does the negation.

Read only file system android (is /mnt not /system)

Android device, I want to touch a file or dir in /mnt, it say "Read only file system", I don't know how to do. i try fix it with that fix /system, but it no work.
root#android:/ # ls -l
.....
drwxrwxr-x root system 2011-01-01 11:33 mnt
.....
root#android:/ #
root#android:/ # mkdir /mnt/test
mkdir failed for /mnt/test, Read-only file system
255|root#android:/ #
root#android:/ # mount -o remount,rw /mnt
Usage: mount [-r] [-w] [-o options] [-t type] device directory
1|root#android:/ #
can't fix it as /system.
how can i do it?
root#android:/ # id
uid=0(root) gid=0(root)
root#android:/ #
But i can make directory in /mnt/xxx/, like this:
root#android:/ # mkdir /mnt/usb_storage/test
root#android:/ # ls /mnt/usb_storage/test/
root#android:/ # ls /mnt/usb_storage/
test
root#android:/ #
And
i fond difference between /mnt and /mnt/usb_storage in init.rc
look /mnt:
# create mountpoints
mkdir /mnt 0775 root system
look /mnt/usb_storage:
# Directory for multi usb storage
mkdir /mnt/usb_storage 0700 root system
mount tmpfs tmpfs /mnt/usb_storage mode=0755 gid=1000
Yes!I fix it!
create mountpoints
mkdir /mnt 0775 root system
add mount tmpfs tmpfs /mnt/ mode=0755 gid=1000
now i can touch file or make directory in /mnt
root#android:/mnt # mkdir /mnt/test
root#android:/mnt # ls -l /mnt/
....
drwxrwxrwx root root 2011-01-01 11:04 test
drwxrwxrwt root system 2011-01-01 11:00 usb_storage
root#android:/mnt #
Resolved
ramdisk rootfs is read only.
mount -o remount,rw /
you should have to add certain permission into your manifest file..
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
and for more see the following which near to what you looking for
Can't create file in sd-card

How to create OBB files USING jobb tool Android

My app has grown to be over 50mb, so I now need to use an expansion file. On searching I came to know that there are different files that can be used as expansion files such as zip, pdf etc. I am trying to put my data in .obb files but I don't know how to create these files and put the data in these files.
Updated
First:
I found out that jobb tool is used to create obb files. But I am confused how this $ jobb -d /temp/assets/ -o my-app-assets.obb -k secret-key -pn com.my.app.package -pv 11 command is run.
I tried to run this ($ jobb -d /temp/assets/ -o my-app-assets.obb -k secret-key -pn com.my.app.package -pv 11 on cmd but my cmd saying jobb is not recognise as internal or external command.
Second:
Which type of files can I put in these obb files? I am thinking layouts, drawable files?
my cmd saying jobb is not recognise as internal or external command
Add /tools to your path or instead of jobb use path/to/sdk/tools/jobb.bat
which type of files are put in these obb files
Big ones. Like drawables, sounds etc. Then, for example, you can use this code to put drawable file into ImageView:
imageView.setImageBitmap(
BitmapFactory.decodeFile(
sm.getMountedObbPath("/path/to/obb/file") +
"path/to/file/in/obb.png")
or, play sound:
mp.setDataSource(AcItem.this,
Uri.fromFile(new File(
sm.getMountedObbPath("/path/to/obb/file") +
"path/to/file/in/obb.png"));
mp.prepare();
mp.start();
As I promised, GitHub link to my obb manager class: https://github.com/uncleLem/AndroidUtils/blob/master/src/io/github/unclelem/androidutils/utils/ObbExpansionsManager.java
I hope it would help.
Just write Like this in command prompt and press enter
C:\>C:\Development\Android\adt-bundle-windows-x86-20140321\sdk\tools\jobb -d C:\
Myworkspace\ImageTargets\assets\ -o Imagetargets.obb -k globe -pn com.ib.globeap
p.activity -pv 200 -v

How to extract ramdisk.img

use ubuntu
I type file ramdisk.img and the Terminal display ramdisk.img: data,
I use cpio and get nothing extracted!
How can I extract such ramdisk.img?
It's highly possible that ramdisk.img actually is a compressed file ramdisk.cpio.gz. To extract it use this commands:
cd /Path/To/Folder/With/ramdisk.cpio.gz/File
mkdir temp_directory && cd temp_directory
gunzip -c ../ramdisk.img | cpio -idm
Check this blog post for more info: http://blog.djodjo.org/?p=536
you can mount images:
mkdir ~/img_mnt
mount -t udf filename.img ~/img_mnt -o loop
Just use p7-zip which is 7z just for POSIX.
7z e ramdisk.e RamdiskExtracted
I'm not sure about repacking and keeping metadata though.
I guess you could mount it as rw??

Categories

Resources