Still flashing? Try dual systems !, Two systems are still being installed
1. Preface:
Flash flash seems to be a patent for Android mobile phone users, but the users who will flash are generally new and old roles,
After a system has been used for a long time, you want to switch to another system, or feel that it is not as good as it is, or you want to change it back, so you have to refresh it.
But it is troublesome to brush and brush, and it is not risky to brush each time. Accidentally, it may cause loss of important data.
Is there any solution? Yes! Dual System! Three or even four !!
This article solves this problem, and uses the method described in this article to fully implement one-click installation and one-click Uninstall of the system. It is as easy as installing and uninstalling the system into apk.
(Note: The following method takes Samsung i93xx series mobile phones as an example)
2. Let's briefly introduce the Startup Process of Android:
When the phone is powered on, the first program integrated into a rom on the CPU chip
This program is responsible for loading the boot program on the nand flash or SD card. Generally, the boot program is uboot.
Uboot will initialize some devices. The important part here is nand flash, so that the Linux kernel can be loaded into the memory and run.
The loaded kernel may be the kernel in the boot partition or the kernel in the recovery partition.
After the kernel runs, it first mounts ramdisk to the "/" root directory, and then runs/init to create the first process.
Init reads/init. rc and performs further initialization, such as creating directories, setting permissions, mounting data, system, and cache partitions, and starting a series of services, including important zygote processes.
The zygote process creates a system_server process to complete further initialization and load a series of apk processes.
3. Next, let's take a look at the partitions required by an Android system:
A uboot partition to guide the kernel
One kernel Partition
A system partition used to store Android system programs and files
A data Partition is used to store system data, apk program, and apk program data.
A cache partition is generally used for upgrades. It is used to store ota update packages and update logs.
4. Next, let's look at the implementation solution of the dual-system:
4.1 kernel boot Problems
This is a headache. As mentioned above, the kernel is loaded by uboot through the boot partition or recovery partition.
If you want to load the kernel of another partition, you must consider modifying the uboot configuration parameters or code.
We certainly do not have uboot code,
Although the uboot configuration parameters are usually stored in a partition, they are generally encrypted and cannot be changed.
Therefore, we can only consider using our own partitions.
The simplest method is to overwrite the boot partition and write the boot. img of the second Android server to the boot partition,
Then write an apk and write the boot. img of the system to the boot partition when the system is to be started.
The disadvantage of this method is that switching is troublesome. You must first start one of the systems for each switching, and then run the apk to switch.
Then, we looked greedy at the rediscovery partition.
As you know, the recovery partition is generally used only when the system is upgraded or the factory settings are restored. Therefore, we want to start with the recovery partition.
The simplest way is to put the second Android system boot. img in the rediscovery partition, which triggers the recovery to guide the second Android system.
Of course, you can also add a custom uboot in the recovery partition to achieve more flexible loading methods, such as displaying the boot menu and loading the kernel from the SD card.
However, the source code of uboot is required.
Of course, before using the recovery partition, back up the recovery partition.
Another advantage of using the recovery partition as the linux boot partition of the second system is that the mobile phone usually has a shortcut key to boot into the recovery,
For example, a Samsung mobile phone usually presses the volume plus, HOME, and POWER buttons at the same time when it is turned on.
This facilitates system switching.
4.2 system, data Partition creation problems:
Solve the boot problem. Let's take a look at the problem of system and data Partition creation.
Because cache partitions are only used during upgrade, the two systems can be shared and no longer need to be created.
1) re-partitioning:
That is, to create different partitions for each system, This method requires re-partitioning the storage space, which is obviously troublesome, risky, and feasible.
2) solutions for Using Virtual Disks
You must be very impressed with how ubuntu can be directly installed in windows.
In fact, ubuntu can achieve installation without re-partitioning by using a virtual disk.
Compared with the first scheme, this avoids the trouble of re-partitioning.
The virtual disk is already supported by the kernel in linux and is a mature technology.
Therefore, the virtual disk is the best choice here. With the help of Virtual Disks, we can not only implement dual systems, but also implement three or four systems, depending on the storage space.
5. The theory is clear. Next, let's take a look at how to do it.
First, we need to create a system virtual disk. There are two methods:
One is to directly generate a virtual disk from img, and the other is to write the system partition in an ota update package to the virtual disk.
The first method is relatively simple. You only need to execute a command:
Simg2img system. img system. disk
Simg2img can be found in the out/host/linux-x86/bin/directory after compilation
6.5 if you get a zip-format ota update package, the content is similar to the figure below:
It is a little difficult to create a system virtual disk. Let's take a look at how to make it:
Update-script under the META-INF \ com \ google \ android directory of the compressed package needs to be modified
1) Remove the format and mount/system partition scripts.
format("ext4", "EMMC", "/dev/block/mmcblk0p9", "0", "/system");mount("ext4", "EMMC", "/dev/block/mmcblk0p9", "/system");
2) Remove scripts for writing boot. img and data partitions.
package_extract_file("boot.img", "/dev/block/mmcblk0p5");
Be sure to remove the write operation for boot. img.
In short, remove one operation that is irrelevant to the system partition, and remove the formatting and mounting operations of the/system partition.
Be careful and be careful.
3) Next, package the extracted ota update package into a zip file.
4) then go to the recovery for further operations (here, the recovery is preferably a third-party recovery, such as cm recovery, which has a wide range of commands and is relatively good for operations)
5) connect to your phone via usb. after entering the recovery, adb will automatically connect to the recovery, and then execute the following commands in sequence:
Before executing the following script, make sure that your mobile phone can obtain system permissions in shell.
Upload the upgrade script execution program to the/data/local/tmp directory of the phone, update-binary in the upgrade package's META-INF \ com \ google \ android directory, and updater-script in the same directory.
adb push update-binary /data/local/tmp
Upload the updated update-script ota update package to the corresponding directory on your mobile phone.
adb push ota.zip /data/local/tmp
Switch to root permission
adb shellsu
Create a MB Virtual Disk
cd /data/local/tmpdd if=/dev/zero of=system.disk bs=1024 count=819200
Loop Virtual disk system. disk
busybox losetup /dev/block/loop7 system.disk
Format a Virtual Disk
busybox mkfs.ext2 /dev/block/loop7
Mount a virtual disk to the/system directory
busybox mount -o loop -t ext4 /dev/block/loop7 /system
Modify update-binary to execute
chmod 777 update-binary
Run the update-script to install the ota update package to the/system directory.
./update-binary 2 0 ota.zip
Detach a system Virtual Disk
umount /systembusybox losetup -d /dev/block/loop7
Exit System permission
Exit
Exit adb shell
Exit
Upload system. disk to PC from mobile phone:
Adb pull/data/local/tmp/system. disk
In this way, the system virtual disk is ready for a biscuit :).
7. Next, let's take a look at how to create an ext4 data virtual disk.
dd if=/dev/zero of=data.disk bs=1024 count=30720 busybox losetup /dev/loop0 data.disk mkfs.ext4 -m 1 -v /dev/block/loop7
8. Next, let's take a look at how to mount a virtual disk.
1) first, you need. img needs to be decompressed before performing an operation. There should be decompression tools on the network, but I generally like to write some gadgets to complete some simple tasks, so as to deepen my understanding, second, it facilitates function expansion.
So here we use python to write a program for decompression:
unpack.py""" unsigned char magic[BOOT_MAGIC_SIZE]; unsigned kernel_size; /* size in bytes */ unsigned kernel_addr; /* physical load addr */ unsigned ramdisk_size; /* size in bytes */ unsigned ramdisk_addr; /* physical load addr */ unsigned second_size; /* size in bytes */ unsigned second_addr; /* physical load addr */ unsigned tags_addr; /* physical addr for kernel tags */ unsigned page_size; /* flash page size we assume */ unsigned unused[2]; /* future expansion: should be 0 */ unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ unsigned char cmdline[BOOT_ARGS_SIZE]; unsigned id[8]; /* timestamp / checksum / sha1 / etc */"""import sysimport structimport subprocessBOOT_MAGIC_SIZE = 8BOOT_NAME_SIZE = 16BOOT_ARGS_SIZE = 512boot_img = Nonekernel_img = Noneramdisk_img = Noneramdisk_cpio = Noneramdisk_out = Noneif len(sys.argv) >= 2: boot_img = sys.argv[1]else: boot_img = 'boot.img'if len(sys.argv) >= 3: kernel_img = sys.argv[2]else: kernel_img = 'kernel.img'if len(sys.argv) >= 4: ramdisk_img = sys.argv[3]else: ramdisk_img = 'ramdisk.img'if len(sys.argv) >= 5: ramdisk_cpio = sys.argv[4]else: ramdisk_cpio = 'ramdisk-m.cpio'if len(sys.argv) >= 6: ramdisk_out = sys.argv[5]else: ramdisk_out = 'ramdisk'f = open(boot_img,'rb')magic = f.read(BOOT_MAGIC_SIZE)kernel_size = f.read(4)kernel_size = struct.unpack('I',kernel_size)[0]print kernel_sizekernel_addr = f.read(4)kernel_addr = struct.unpack('I',kernel_addr)[0]print "0x%x"%(kernel_addr,)ramdisk_size = f.read(4)ramdisk_size = struct.unpack('I',ramdisk_size)[0]print ramdisk_sizeramdisk_addr = f.read(4)ramdisk_addr = struct.unpack('I',ramdisk_addr)[0]print "0x%x"%(ramdisk_addr,)second_size = f.read(4)second_size = struct.unpack('I',second_size)[0]print second_sizesecond_addr = f.read(4)second_addr = struct.unpack('I',second_addr)[0]print "0x%x"%(second_addr,)""" unsigned tags_addr; /* physical addr for kernel tags */ unsigned page_size; /* flash page size we assume */ unsigned unused[2]; /* future expansion: should be 0 */"""f.seek(BOOT_MAGIC_SIZE + 3*2*4 + 4+4+4*2)""" unsigned char name[BOOT_NAME_SIZE]; /* asciiz product name */ unsigned char cmdline[BOOT_ARGS_SIZE];""" name = f.read(BOOT_NAME_SIZE)print namecmdline = f.read(BOOT_ARGS_SIZE)print cmdlinepage_size = 2048f.seek(2048)data = f.read(kernel_size)with open(kernel_img,'wb') as ff: ff.write(data) ramdisk_offset = 2048 + (kernel_size+page_size-1)/page_size*page_sizeprint 'ramdisk_offset:',ramdisk_offsetf.seek(ramdisk_offset)data = f.read(ramdisk_size)with open(ramdisk_img,'wb') as ff: ff.write(data)cmd = 'gzip -d -r < %s >%s'%(ramdisk_img,ramdisk_cpio)subprocess.check_output(cmd,shell=True)cmd = 'mkdir %(ramdisk)s;cd %(ramdisk)s;cpio -i < ../ramdisk-m.cpio'%{'ramdisk':ramdisk_out}subprocess.check_output(cmd,shell=True)
This program extracts kernel. img and ramdisk. img from boot. img, and decompress ramdisk. img in zip format to the ramdisk directory by default.
2) Modify fstab. smdk4x12
Original content:
# Android fstab file.#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags># The filesystem that contains the filesystem checker binary (typically /system) cannot# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK/dev/block/mmcblk0p9 /system ext4 ro,errors=panic wait/dev/block/mmcblk0p3 /efs ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check/dev/block/mmcblk0p8 /cache ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check# data partition must be located at the bottom for supporting device encryption/dev/block/mmcblk0p12 /data ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check,encryptable=footer# VOLD/devices/platform/s3c-sdhci.2/mmc_host/mmc1/ /storage/extSdCard vfat default voldmanaged=sdcard:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveA vfat default voldmanaged=sda:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveB vfat default voldmanaged=sdb:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveC vfat default voldmanaged=sdc:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveD vfat default voldmanaged=sdd:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveE vfat default voldmanaged=sde:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveF vfat default voldmanaged=sdf:auto
Modified content:
# Android fstab file.#<src> <mnt_point> <type> <mnt_flags and options> <fs_mgr_flags># The filesystem that contains the filesystem checker binary (typically /system) cannot# specify MF_CHECK, and must come before any filesystems that do specify MF_CHECK/dev/block/mmcblk0p3 /efs ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check/dev/block/mmcblk0p8 /cache ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check# data partition must be located at the bottom for supporting device encryption/dev/block/mmcblk0p12 /dat ext4 nosuid,nodev,noatime,noauto_da_alloc,discard,journal_async_commit,errors=panic wait,check,encryptable=footer# VOLD/devices/platform/s3c-sdhci.2/mmc_host/mmc1/ /storage/extSdCard vfat default voldmanaged=sdcard:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveA vfat default voldmanaged=sda:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveB vfat default voldmanaged=sdb:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveC vfat default voldmanaged=sdc:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveD vfat default voldmanaged=sdd:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveE vfat default voldmanaged=sde:auto/devices/platform/s5p-ehci/usb1 /storage/UsbDriveF vfat default voldmanaged=sdf:auto
Here, the system partition is deleted, and the data Partition is changed from the original mounted to dat to the/dat directory.
Because here we actually want to mount a Virtual Disk
3) In init. rc:
Modify on init:
In
Mkdir/system
Add:
Mkdir/dat
4) In init. smdk4x12. rc, modify on fs
In
Mount_all/fstab. smdk4x12
Add:
Mount ext4 loop @/dat/system. disk/system rw wait noatime mount ext4 loop @/dat/data. disk/data wait nosuid nodev noatime
Summary:
1) First, mount the partition that should be mounted to the/data directory to the/dat directory.
2) The next two lines of scripts mount the virtual disk to/system and/data respectively.
3) Yes, so easy !, However, when the function has not yet been implemented, there is still some experience in the process from brewing to trying, to success, although the key virtual partition mounting is completed with two intentions (watching the CCTV record, haha, never learn ).
9. Re-package the kernel and ramdisk into boot. img.
After the ramdisk is modified, We need to repackage it into boot. img. Three commands are used: mkbootfs, minigzip, and mkbootimg. Mkbootfs packs all the files in ramdisk into cpio files.
Minigzip is compressed. mkbootimg generates boot. img from the kernel and ramdisk. img. The usage is as follows:
Mkbootfs ramdisk | minigzip> ramdisk. img
Mkbootimg -- kernel. img -- ramdisk. img -- output boot. img
10. Next, the last step is to install the second Android operating system?
The installation is really simple. Write boot. img to the recovery partition and copy system. disk and data. disk to the/data Partition.
Of course, you can also put system. disk and data. disk in the external SD card, which involves modifying ramdisk
11. Finally, let's summarize the full text:
It is no longer a new technology to implement dual systems on mobile phones. After using virtual disks to implement dual systems, Baidu later saw an article written in the past 11 years, dual systems are implemented by partitioning on the SD card, which is troublesome to operate,
The switch should also be started to one of the systems by flushing the boot partition to achieve the system switching. It is not as convenient as directly refreshing the recovery partition in this article.
The dual-system implementation in this article is actually relatively simple:
1) convert system. img to a system. disk format that can be directly mounted through loop through simg2img
2) create a data Partition Virtual disk data. disk
3) modify the boot script in boot. img to mount the virtual disk and repackage it.
4) place system. disk and data. disk in the original data partition.
5) refresh the re-packaged boot. img to the recovery partition.
12. Is this the end or just the beginning?
If it is a network set-top box, the above is enough, but we are creating a dual system on the mobile phone, so there is still a way to go, the following are the questions to consider:
1) How to synchronize the communication records in the two systems
2) How to synchronize the data of commonly used tools in the two systems, such as chat records.
3) how to deal with the incompatibility of the baseband of different android versions.
4) how to deal with the incompatibility of efs partitions in different versions of android systems.
5) How to Implement the Android + WP Dual System
6) how to implement three or four systems?
7 )...
(End)
System update or dual system after flashing
Apple cannot be switched to Android or ios.
On Apple or Android, there is no dual-system!
In the previous ppc, there was a dual-system. Taking hd2 as an example, it was a poc. You can 'simulate the android' card. After the device is shut down, it will be restored to ppc.
Android is based on java. It is used for skey/shanzhai. From the wood, all mobile phones are skey systems. without installing any program, only the icons are different.
There is also, who is looking forward to beautiful/advanced things. It is impossible to go back to/or stick to it conservatively. obscenity in what you think is in the world, either mental illness or mental illness.
How to use dual-system mobile phones
Dual-system mobile phones ??
Joke
Let me take a look -------------------
Various software tools of Baidu's software stealing industry are cracked for free!
Non-toxic Haha ------ the bottom of the Forum is a variety of original systems, a variety of large software downloads!
Remember the original version-the website is [msdn I will tell you]
As for activating the key, you should go to the [soaring blog] or [Soft stealing] forum.
Windows 7, nine activation tools, five activation tools ,,,