• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Root Link2SD: A Tutorial. New and Updated Version

The harmonia gingerbread says it is based on the mirage rom...what do you think of it? I'd like to keep things as simple as possible for myself, lol.
 
You know Leslie Ann's work. She likes things as simple as possible.
No need for any Gapps with her ROM. Just flash ROM and enjoy.
 
  • 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 requeriments 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.

At this point, can anyone help me investigate the root-cause behind the boot-loop problem? Can anyone come up with any idea or satisfactory answer to the query? Does anyone have any idea on how to approach the issue at hand?

  • Please find the relevant scripts below.

00stop_ric
Code:
#!/system/bin/sh
/system/xbin/busybox pkill /sbin/ric
mount -o remount,rw /
rm /sbin/ric
mount -o remount,ro /
/system/xbin/busybox pkill /sbin/ric

11link2sd
Code:
#!/system/bin/sh
#added by link2sd
LOG=/data/link2sd-11link2sd.log
echo "$(date) mounting..." > $LOG
sleep 2
mount -t ext4 -o rw /dev/block/vold/179:34 /data/sdext2 1>>$LOG 2>>$LOG

mount -t ext4 -o rw /dev/block/mmcblk1p2 /data/sdext2 1>>$LOG 2>>$LOG

mount >> $LOG
echo "$(date) mount finished" >> $LOG

install-recovery
Code:
#!/system/bin/sh

# If you're implementing this in a custom kernel/firmware,
# I suggest you use a different script name, and add a service
# to launch it from init.rc

# Launches SuperSU in daemon mode only on Android 4.3+.
# Nothing will happen on 4.2.x or older, unless SELinux+Enforcing.
# If you want to force loading the daemon, use "--daemon" instead

/system/xbin/daemonsu --auto-daemon &

# Some apps like to run stuff from this script as well, that will 
# obviously break root - in your code, just search this file
# for "install-recovery-2.sh", and if present, write there instead.

/system/bin/sysinit

sysinit
Code:
#!/system/bin/sh

export PATH=/sbin:/system/sbin:/system/bin:/system/xbin
/system/bin/logwrapper /system/xbin/run-parts /system/etc/init.d

link2sd-11link2sd
Code:
Wed Jul 23 16:23:57 IST 2014 mounting...
mount: Device or resource busy
mount: Device or resource busy
rootfs / rootfs ro,relatime 0 0
tmpfs /dev tmpfs rw,nosuid,relatime,mode=755 0 0
devpts /dev/pts devpts rw,relatime,mode=600 0 0
proc /proc proc rw,relatime 0 0
sysfs /sys sysfs rw,relatime 0 0
debugfs /sys/kernel/debug debugfs rw,relatime 0 0
none /acct cgroup rw,relatime,cpuacct 0 0
tmpfs /mnt/secure tmpfs rw,relatime,mode=700 0 0
tmpfs /mnt/asec tmpfs rw,relatime,mode=755,gid=1000 0 0
tmpfs /mnt/obb tmpfs rw,relatime,mode=755,gid=1000 0 0
none /dev/cpuctl cgroup rw,relatime,cpu 0 0
/dev/block/platform/msm_sdcc.1/by-name/system /system ext4 ro,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/userdata /data ext4 rw,nosuid,nodev,relatime,noauto_da_alloc,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/cache /cache ext4 rw,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/persist /persist ext4 rw,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/ftmd /ftmd ext4 rw,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/LTALabel /lta-label ext4 rw,nosuid,nodev,relatime,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/ftma /ftma ext4 ro,relatime,nobarrier,data=ordered 0 0
/dev/block/platform/msm_sdcc.1/by-name/modem /firmware vfat ro,relatime,uid=1000,gid=1000,fmask=0337,dmask=0227,codepage=cp437,iocharset=iso8859-1,shortname=lower,errors=remount-ro 0 0
/dev/block/mmcblk1p1 /storage/sdcard1 fuseblk rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096 0 0
/dev/block/vold/179:34 /data/sdext2 ext4 rw,relatime,data=ordered 0 0
/dev/block/vold/259:0 /storage/sdcard0 vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
/dev/block/vold/259:0 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,relatime,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
tmpfs /storage/sdcard0/.android_secure tmpfs ro,relatime,size=0k,mode=000 0 0
/dev/block/dm-0 /mnt/asec/uk.co.aifactory.chessfree-2 ext4 ro,dirsync,nosuid,nodev,noatime 0 0
/dev/block/dm-1 /mnt/asec/com.wave18.adbwireless-1 ext4 ro,dirsync,nosuid,nodev,noatime 0 0
/dev/block/dm-2 /mnt/asec/com.rerware.android.MyBackupRoot-1 ext4 ro,dirsync,nosuid,nodev,noatime 0 0
/dev/block/dm-3 /mnt/asec/com.rootuninstaller.free-2 ext4 ro,dirsync,nosuid,nodev,noatime 0 0
Wed Jul 23 16:23:59 IST 2014 mount finished
 
I'm trying to get comfortable with switching to a gingerbread rom from a froyo rom. I have a Mac, and from what I can tell, I cannot make an ext partition with my disk utility...only FAT32. I know gingerbread roms require ext. Andy told me about an app I can use to partition, called aparted...I will try that once I flash the new rom.

But during my search for info on how to make ext partitions with a mac, I came across this thread another forum about Link2sd and the Optimus S. The author says that there would need to be a FAT32 partition on the card for anything on your sd card that you want to access via your computer, like photos and music. But the Links partition would need to be ext4.

From the thread:

4) Copy everything on your SD card to a folder on your PC or Mac so that you can move it back onto your (new Class 4 or higher) SD card later.

5) On your fast SD card, create two partions; an EXT4 file-system partition for your apps & app-data, and a FAT32 file-system partition for your photos, music, etc. (Your FAT32 partion will be accessible from your PC. Your EXT4 partition will only be accessible to your phone's operating system.) You may be able to partition your SD card using the custom recovery on your phone (depending on your custom recovery) but I'm not going to cover that here because I think it's easier to use a free PC tool like Mini Tool Partition Wizard to partition and format your SD card. There's a Mini Tool partitioning guide here. Per the cache-limitation caveat mentioned in the previous paragraph, a 512MB EXT4 partition should be more than big enough (especially for the Link2SD method because you'll also still have access to your phone's 160MB of internal memory for a total of 672MB). Anything more than 512MB would likely be unusable as a practical matter, but you could create a larger EXT4 partition (say 1GB) if you like.

So, my questions:

Is this necessary?

And if so, how would I make both those partitions? My sd card is currently full and has two partitions for my current use of Link2sd with my Harmonia froyo rom.

And, does this mean that during this "flashing a new rom" activity I would need to completely wipe my entire sd card?

I have backed up to my computer in case...but I'm a bit confused. Any help is appreciated! Thanks!
 
As for partitioning your sd card, i think andy has explained (how to) at the top of this page, under notes 1.) and 2.) Although i don't have a computer, you can partition and change the format in recovery.

As for flashing over to gingerbread ,which is what i'm running, MiRaGe is an excellent choice. You will need to do a clean install , wipe data /factory reset, wipe cache partition, under advanced sub menu, wipe dalvik cache. Then under mounts and storage sub menu, format all partitions except /sd card. Unless your using zengarden recovery, then you only need to do the four options in the wipe section. Here's a good guide to follow that andy made for flashing ...
http://androidforums.com/optimus-v-all-things-root/697813-how-install-flash_image-flash-recovery-rom-theme-updated-10-24-2013-a.html
I hope this helps. :)
 
Thanks, I appreciate the reply! Andy has given me many tips and steps, he is a great help! The instructions in this forum are wonderful...just sometimes overwhelming. I'm just really so technically challenged and easily flustered by all this, haha...I am intimidated by the prospect of switching to gingerbread and setting up my Links again. :)

My mac won't do ext partitions, so I have to use an app, I guess. I was under the impression that my recovery would not partition the sd card for me. I have bob zhome's VR-something-something (LOL) recovery. I also downloaded obi john's wiper...I don't remember why, haha! Will those do the trick?

I'm confused about what happens to my sd card during this process of flashing the new rom. Will my Link2sd partition be erased? Will my entire sd card's contents be erased? Do I need to partition in different formats? I don't want to really mess something up.

Thanks!!
 
Just follow the directions that Andy has already given you starting at post #23 above ^ .

You will have to backup your sd card to your computer.

Use the recovery that andy has linked in post 23 and follow his directions, he tells you exactly what to do, :)
 
Excellent guide, thank you.

Now my sd card is dual partitioned what happens when I make a nandroid in the future? Can both partitions now get backed up? If not, how to back up the new sd-ext partition in case of sd card failure?
 
Excellent guide, thank you.

Now my sd card is dual partitioned what happens when I make a nandroid in the future? Can both partitions now get backed up? If not, how to back up the new sd-ext partition in case of sd card failure?

Newer versions of cwmt and twrp back up both partitions on the SD card + /system, /data, /boot, /cache and dalvik cache from internal memory. When I back up, I do a nandroid + Titanium Backup.
 
Thanks for your reply. I also have Ti Pro and back up with that too.

In the nandroid, how is the new sd-ext partition listed, I'm not sure I'm seeing it backed up separately from the system ext4.

I've compared a nandroid made before creating the new partition, and one after with the new partition and link2sd installed and apps and data moved out of internal.

First one below is before

before.PNG


and next one is after

after.PNG


I don't think the new partition is backed up in my case. I'm using the latest TWRP 2.8.4.0 and ROM is stock KK 4.4.4

I can see the amount of data and system.ext4 is less in the second nandroid, consistent with me moving apps and data out of internal storage, but I don't see the new partition with the moved data backed up in this nandroid.

Am I doing something wrong?
 
Maybe try a different browser, as most of the images are fine (there are a couple in the first post that are broken, but that happens with 6 year old posts)
 
Back
Top Bottom