In the past, I was able to create an AVD with persistant /system/ storage by copying the system.img file from the base directory (ex: $ANDROID_HOME/platforms/android-10/images/system.img) into the AVD directory (ex: ~/.android/avd/wuntee.avd/) then remount the /system/ partition as rw and finally modify the files on the /system/ partition. This would persist to the AVDs local system.img file and upon reboot, the changes would stay still exist. This process does not work with the emulator version 16...
There are options in the emulator, specifically:
-sysdir <dir> search for system disk images in <dir>
-system <file> read initial system image from <file>
that I would assume write the changes back to the file, but no luck. Has anyone experienced this, and have a workaround (without unyaffs'ing the .img files)? Is this something that was done intentionally by the Android/emulator developers?
apparently rev. 16 copies the system.img file to your OS's temp folder (on my linux box, it's in /tmp/android-username/emulator-*). The changes you make to the /system partition are reflected on that copy instead of the one in the avds folder.
I remounted /system, modified some files, and then before closing the emulator instance, copied the tmp file to my avd folder. Restarted the emulator and my modifications are persistent.
Related
I want to change the kernel and ramdisk.img file to install magisk, however, the folder is "read-only"
My setup:
Android-x86_9.0-r2_(x8) running on Proxmox (using QEMU and qcow2
formatted image)
GRUB, GBT installed, and I selected install with
write permissions at the android installation
I tried to install magisk using the following guide: https://forum.xda-developers.com/android/general/guide-android-x86-rooted-magisk-t4077477
I successfully patched the boot.img and got the new kernel and ramdisk.img file. However, I wanted to replace them now, but I get the following error when I want to modify something in the folder where the old kernel and ramdisk.img is located:
Read-only file system
I connected to android using ADB (but also tried the terminal emulator on android itself). I already tried adb remount and other mounting options, but nothing works. Android runs as root.
The folder where the ramdisk.img and boot is located: /mnt/media_rw/Android-x86_9.0-r2_(x86)/
When running
mount | grep mnt
I receive the following (which means the folder Android-x86_9.0-r2_(x86) where the ramdisk.img etc. is stored is read-only:
/dev/block/vold/public:11,0 on /mnt/media_rw/Android-x86_9.0-r2_(x86) type iso9660 (ro,dirsync,nosuid,nodev,noexec,relatime,nojoliet,utf8,check=s,map=n,blocksize=2048,uid=1023,gid=1023)
When I try to mount it to rw using:
mount -o remount,rw /dev/block/vold/public:11,0 /mnt/media_rw/Andro*
I get:
'/dev/block/vold/public:11,0' is read-only
What can I do to change the ramdisk.img and kernel so I can install magisk?
Thank you very much!
I was having the same issue. All you can do install gearlock and find the img somewhere in gearlock/gearrot folder. You can modify that files as you want.
More info:
https://github.com/axonasif/gearlock
I am using Nougat 7 emulator and was able to root the emulator. But after rebooting all the changes i made to android /system folder are gone. Is there any way to preserve the /system. My real objective is to install xposed on Nougat 7 android emulator .
When you start the Android emulator the system partition comes from a shared image located in the Android SDK. Search for system.img in the subdirectory system-images/android-??/default
If you want to change something on the system partition I would suggest to do the following:
Copy system.img file
Modify it outside of the emulator (uncompress, mount, modify, recompress, see on this page section "SYSTEM.IMG" for details)
Use the modified system.img to start/create a new AVD instance.
I need to do a strange task. I want to move whole android system to external SD card on Android Virtual Device. I need to do this, because android emulator, emulates SD commands, only for external card image. And I want to get SD commands trace, during Android Virtual Device usage.
To be more precise: I want to move at least /system and /data folders to external storage. In such way, that system could still work fine =)
Thank You!
To move some of system folders (/system or /data), to external emulated SD card, you need to do following:
Firstly, /data contents (for example) should be placed on sdcard. Initially they are loaded by emulator from userdata.img file.
So you need to copy userdata.img ($EMUPATH/system-images/android-19/armeabi-v7a/userdata.img) contents to sdcard.iso. $> dd if=userdata.img of=sdcard.iso
I assume, that android virtual device is created. To change boot configuration, you will need to change fstab.goldfish file on ramdisk.img. If it is Android 4.4 AVD, then ramdisk.img could also be find at $EMUPATH/system-images/android-19/armeabi-v7a/
Create a temporary folder, say ramdisk-ext $ mkdir ramdisk-ext
Change directory to ramdisk-ext $ cd ramdisk-ext
Extract the ramdisk.cpio in the ramdisk-ext folder $ gunzip -dcv ../ramdisk.img | cpio -idm
Modify fstab.goldfish $ gedit fstab.goldfish in such way:
String #6 from "/dev/block/mtdblock1 /data ..." to "/dev/block/mmcblk0 /data ..."
Create new ramdisk $ find . | cpio -H newc -o | gzip -9 >../ramdisk_new.img
Everything is done, now you need to start the emulator, with your new ramdisk and custom sdcard:$ ./emulator -avd $AVDNAME -sdcard sdcard.iso -ramdisk $EMUPATH/system-images/android-19/armeabi-v7a/ramdisk_new.img
P.S. Notice that in this example you can move only one of such folders (/system or /data). Maybe it could be changed, by creating sdcard image with several partitions.
I need to patch a file into the system.img file used by the Android emulator, specifically I want to add an ARM binary to the /system/bin directory.
I have this binary pre-compiled and it works in my emulator perfectly, but I can't simply remount system.img as rw and adb push it because the change is non-persistent across reboots. I tried this on a copy of system.img and passing it to the emulator with -system but that was non-persistent to sadly.
In the ideal world I want to modify the "make sdk" process so that the sdk build process automatically includes my binary when it produces system.img. Can this be done?
If this isn't possible, is there anyway of patching it into the image manually?
Thanks a lot.
I was interested in permanently modifying the /system folder and tried unpacking the system.img file which went ok, but I failed to create a new img that the emulator was happy with (using the mkyaffs2 and unyaffs2 tools to extract and create a new system.img).
Instead I found a much easier solution:
Remove everything from the /data/ directory (except lost+found)
Copy the contents of /system into your /data folder
Make your desired changes to /data/
Kill the emulator
You now move your ~/.android/avd/MYANDROID.avd/userdata-qemu.img to ~/system.img (or wherever)
and startup your emulator with your new system image:
emulator -debug all -show-kernel -verbose -avd MYANDROID -no-boot-anim \
-gpu on -partition-size 800 -system [path to your new system.img]
The /data folder is where the userdata-qemu.img file gets mounted.
It gets created the first time the emulator is run and will get recreated if you delete it.
(though your installed apps will disappear).
BY populating it with the contents of the /system folder and then making your desired modifications you have created a replacement for the system.img file.
system.img replace with original one so you need give patches whenever your emulator boots check logcat & then using ADB push you manually push the patches.
I need to copy files to the system partition of the emulator. As it is read only by default, I use the command "adb remount" to have write permissions and I can then copy the files.
My problem is that when I close the emulator and that I restart it, the copied files were missing. It's very annoying because I must write file permissions that are read at startup of the emulator (platform.xml file in /system/etc/permissions)
You may need to add those files to the firmware that was used to create the emulator image.
The system partition you saw is only a tmp file which will be created during each execution is the reason why you will lose all your files.
The emulator will copy the system.img to the tmp file (something like /tmp/emulator-dDiaPX). All your modifications are made there. So it is easy to understand why all your files are gone, since they have never appeared in the real system.img.
In order to see the opened files, You can use:
lsof -p pid-of-emulator
The right method to do so is to place your files at the directory /data/ or /sdcard/.