Android

What is Link2SD?

Link2SD is an app for Android 2.0+ users on their phone to move applications to the SD card by dual-partitioning the card. First partition gets mounted as external SD and remains available for general use, while the second partition (preferably formatted with an *NIX type file-system, e.g. ext2, ext3, ext4 etc.) holds executable(.apk), data, dalvik-cache(.dex) and library files(.so) for linked/moved application.Link2SD mounts the second partition of your SD card as /data/sdext2 and makes OS mounts it at boot time. When you select an application and press “Create Link” button you can select which files of the application will be linked and moved to SD card. Apk, dex and lib files can be moved and you can select all three or any two of three or even only one of them. Depending on what you select, Link2SD moves apk file, dalvik-cache (.dex) file and lib files (.so) to SD card’s second partition and creates symbolic links in original directories. Phone must be Rooted, of course.


How does mounting of second SD partition work?

After the partitioned SD card is put in the phone, Link2SD asks you to select the file-system of the second partition on SD, just chose the one you used. Once /system/etc/init.d/11link2sd script is created, you have to restart the phone.


What is init.d support and why is it needed?

init.d directory is the container of start-up scripts in a *NIX type system. These scripts are execute during system boot.Link2SD relies on the execution of /system/etc/init.d/11link2sd script which, in turn, mounts the second partition of SD card as /data/sdext2.


What is the Boot-Loop problem?

The SD card storage is dual-partitioned and put in the phone. Then, Link2SD generates mount script for the second partition of SD card and phone needs to be re-started. Some phones, e.g. Sony Xperia-L runs into infinite boot-sequence a.k.a. boot-loop. In this state, phone boot sequence starts, manufacturer logo is displayed proceeds for a few seconds and restarts. Only solution is to long press the power button or taking out the battery to switch the phone off. Interestingly, if the dual-partitioned SD card is taken out and the phone is booted without SD card inserted, it boots normally.


What did I do with my Xperia-L so that it started boot-looping?

  1. Rooted Xperia using Rootkit method. It leaved /system/etc/install_recovery.sh and /system/etc/init.d/00stop_ric scripts on the phone’s file-system. (Script code listed below). I am using the rooted phone for months without any trouble.
  2. Using an un-partitioned 32GB microSD card, formatted with FAT32, in the phone.
  3. Deciding to give a try to Link2SD, I dual-partitioned the SD using Minitool Partition Manager. First partition was formatted with FAT32 while the second one was formatted with ext4. Sizes of partitions were around ~25GB and ~4.5GB respectively.
  4. Installed Link2SD on phone.
  5. Switched the phone OFF.
  6. Put the dual-partitioned SD back in the phone slot.
  7. Switched the phone ON.
  8. Opened Link2SD app.
  9. Link2SD immediately recognized the second partiton, asking me for its file-system type.
  10. Selected ext4 from the list.
  11. Link2SD generated the mount script and prompted for restart.
  12. Restarted the phone.
  13. Boot-Loop!!!
  14. Switched the phone OFF by taking out battery.
  15. Took the dual-partitioned memory card out.
  16. Switched the phone ON.
  17. Phone starts normally!!!

How did I solve the problem?

  1. I installed Init.d Toggler app as described here.
  2. As described here, I experienced the problem of first partition not being mounted. The error was related to SD Card being empty or the file-system damaged.
  3. I re-formatted the first partition of SD with NTFS.
  4. Installed Paragon exFAT, NTFS & HFS+ app.
  5. Now, the first partition got mounted.

What does Init.d Toggler do?

  1. Appends the following command at the end of /system/etc/install_recovery.sh: /system/bin/sysinit
  2. Creates /system/bin/sysinit script.
  3. Creates /system/etc/init.d directory to put the start-up scripts in.

Does REALLY lack of init.d support cause boot-loop problem?

As the Init.d Toggler solution says,

One of the requirements to use the Link2SD is the support to init.d scripts. Most of the custom roms support this, but not the stock one, giving a boot loop.

I doubt that to be the “real” problem underlying the hood. Why?

  1. How come lack of init.d support cause the mount script /system/etc/init.d/11link2sd malfunction? At most, what could have happened is, it would NOT mount the second partition, that’s it. Right? But, isn’t it surprising to crash or the like during boot?
  2. As stated, even prior to installing Link2SD, there always existed /system/etc/init.d/00stop_ric, which contains almost similar set of commands as that of mount script /system/etc/init.d/11link2sd created by Link2SD. It used to work like a charm. I guess, because of init.d support not being there in stock ROM, the script had never been executed before I used Init.d Toggler.
  3. Had the lack of init.d support been the reason of boot-loop, how did the phone manage itself to boot normally with the dual partitioned SD card taken out? Please note that, the mount script was still residing in init.d directory.
  4. To be noted that, Xperia L (Stock ROM) boots fine with a dual-partitioned SD card put in, though it never mounts the second partition.

Please find the relevant scripts below.