FORUMS

[TIP][TRICK][SCRIPT] IntSD for Link2SD #2 partition, ExtSD as IntSD, 300MB ExtSD..

4,267 posts
Thanks Meter: 1,823
 
Post Reply Subscribe to Thread Email Thread
I will now tell you how you can use the whole internal SD card for Link2SD's second partition and use your physical SD card in place of it with a 300MB "external sd".

Requirements:
  • A rooted ROM that supports init.d scripts. I use The Blu Kuban.
  • Link2SD.
  • A physical compatible MicroSD card. If you don't have one, this will not work.
  • Either ADB with a text editor, PC, and USB or an on-phone text editor. For PC, I recommend PSPad. For on-phone, I recommend Jota.

I provide this information with no warranties or guarantees and I only tested it on the Sprint Epic 4G Touch and The Blu Kuban ROM. Use it at your own risk.

Please note that this *only* works if your ROM does *not* use the "hidden" partition (/dev/block/mmcblk0p12) for system apps.

  1. Install Link2SD. It will yell at you because there's no second partition on the SD card. Just ignore that.
    Two Options (Option 2 is untested and might not work at all given that the SD card(s) may or may not be mounted when the script runs and prematurely mounting them before the vold.fstab file is executed might break the bind when the vold.fstab file is executed):
    1. Make a file named "11link2sd" with the following contents, copy it to /system/etc/init.d, and give it 777 permissions ("chmod 777 /system/etc/init.d/11link2sd"):
      Code:
      #!/system/bin/sh
      #added by link2sd
      LOG=/data/link2sd-11link2sd.log
      echo "$(date) mounting..." > $LOG
      
      mount -t vfat -o rw /dev/block/mmcblk0p11  /data/sdext2 1>>$LOG 2>>$LOG 
      
      mount  >> $LOG
      echo "$(date) mount finished" >> $LOG
    2. Make a folder on your internal or external SD card named "link2sdext2" (the name is arbitrary, but I will be using it in the script) and make a file named "11link2sd" with the following contents, copy it to /system/etc/init.d, and give it 777 permissions ("chmod 777 /system/etc/init.d/11link2sd"):
      Code:
      #!/system/bin/sh
      #added by link2sd
      LOG=/data/link2sd-11link2sd.log
      echo "$(date) mounting..." > $LOG
      
      # Leave out "/external_sd" if you are using your internal SD card.
      # And check the path, it may be different for your ROM.
      mount -o bind /mnt/sdcard/external_sd/link2sdext2  /data/sdext2 1>>$LOG 2>>$LOG
      
      mount  >> $LOG
      echo "$(date) mount finished" >> $LOG
  2. Edit the file /system/etc/vold.fstab. Comment out (prefix the line with "#") every line that starts with "dev_mount" and add the following lines:
    Code:
    # Mount the physical SD card to /mnt/sdcard
    dev_mount sdcard1 /mnt/sdcard auto /devices/virtual/block/cyasblkdevblk0
    
    # Mount the "hidden" partition of the eMMC to /mnt/sdcard/external_sd.
    # Depending on the ROM, you may need to change this to something else.
    # Check the lines you commented out for the actual paths for your ROM.
    dev_mount sdcard /mnt/sdcard/external_sd 12 /devices/platform/dw_mmc/mmc_host/mmc0/mmc0
    * Basically, you're just going to remove "encryptable_nonremovable," swap "/devices/platform/dw_mmc/mmc_host/mmc0/mmc0" with "/devices/virtual/block/cyasblkdevblk0," and change "11" to "12."
  3. Reboot and start using Link2SD to move/link your data off the /data partition.

I have attached my 11link2sd and vold.fstab for your convenience and illustration. It is *not* a flashable ZIP on purpose, every ROM is different and flashing the scripts blindly may have undesirable consequences; however, both files work on my phone: an Epic 4G Touch from Sprint with The Blu Kuban 1.0.5.4 ROM (ICS FL24 4.0.4).
Attached Thumbnails
Click image for larger version

Name:	mountpoints.jpg
Views:	2435
Size:	46.6 KB
ID:	1823341   Click image for larger version

Name:	screen_20130321_1536.jpg
Views:	3706
Size:	35.2 KB
ID:	1823342  
Attached Files
File Type: zip link2sd-scripts.zip - [Click for QR Code] (1.5 KB, 3218 views)
Last edited by egingell; 1st June 2013 at 11:41 AM.
The Following 10 Users Say Thank You to egingell For This Useful Post: [ View ]
 
 
24th March 2013, 08:49 PM |#2  
cerj's Avatar
Recognized Themer
Flag NOLA
Thanks Meter: 11,589
 
Donate to Me
More
Thank you, for taking the time to put this together for the E4GT community. Nice work
The Following 2 Users Say Thank You to cerj For This Useful Post: [ View ]
25th March 2013, 04:07 AM |#3  
Senior Member
Flag Nashville
Thanks Meter: 263
 
More
Great. I always wanted to know how to do it.
The Following User Says Thank You to alammori For This Useful Post: [ View ]
26th March 2013, 11:43 AM |#4  
egingell's Avatar
OP Senior Member
Thanks Meter: 1,823
 
Donate to Me
More
I decided to write a script to do this automatically.

As before, I provide this with no warranties or guarantees. Use at your own risk. Make a NAND backup of at least System and Data before attempting.
  • The script assumes you have busybox and root access.
  • The script does not check for supported hardware. It has only been tested on the SPH-D710.
  • The script will check for /mnt/sdcard/external_sd, /mnt/emmc, and /mnt/sd-ext and that at least one is mounted. It bails otherwise. If your external SD card is mounted elsewhere, you can add it to line 9 of the script file (`mountpoint <real path to external SD (no symlinks)>`).
  • This script must be executed from a live boot (ie, not from recovery) using either Root Explorer, Scripter, a terminal emulator, ADB, or anything else that will run scripts as root.
  • The file must be on an EXT# partition (just put it in /data and you'll be fine) with 777 permissions unless you're using Scripter.
  • The script backs up your vold.fstab file to /data/vold.fstab.bak. If the backup file exists, the script will restore it, delete the Link2SD file, and delete the backup file.
  • Executing the script from Recovery is not advisable.
  • Executing the script after it has already been executed and the backup file no longer exists is also not advisable.
  • Your phone will reboot immediately after the script has executed.

Method 1 (terminal emulator or ADB shell):
  1. Put the file from the zip into the /data directory.
  2. Use the following commands from the shell:
    Code:
    su
    chmod 777 /data/eg.link2sd.sh
    sh /data/eg.link2sd.sh

Method 2 (Root Explorer | Root Browser):
  1. Put the file from the zip into the /data directory.
  2. Long tap the file, click "Permissions", check every box (the bottom row (there are only two boxes in that row) can be unchecked), and tap Ok.
  3. Tap the file and tap "Execute".

Method 3 (Scripter):
  1. Put the file from the zip wherever, but remember where.
  2. Open Scripter, tap the "+", tap "Import", find the file, and tap it.
  3. Tap the file in the list, tap "Run script", make sure "Execute script as root" is checked, and tap "Execute".

The full script:
Code:
#!/system/bin/sh
LOG=/data/testlog.log
VTEMP=/data/eg.vold.fstab
LTEMP=/data/eg.11link2sd
TEMPFILE=/data/eg.temp
BVOLD=/data/vold.fstab.bak

EXTMOUNTED=""
for N in `mountpoint /mnt/emmc` `mountpoint /mnt/sdcard/external_sd` `mountpoint /mnt/sd-ext`
do
	if [ $N ]; then
		echo "Found external card. ($N)";
		EXTMOUNTED="Yes";
		break;
	fi
done

if [ ! $EXTMOUNTED ]; then
	echo "Can't find external SD card. Make sure it's inserted and mounted and try again.";
	exit;
fi

mount -o remount,rw /system

# System files
MOUNTPOINTS=/proc/mounts
VOLD=/system/etc/vold.fstab
LINK2SD=/system/etc/init.d/11link2sd

EXTPATH="";
EXTDEV="";
INTPATH="";
INTDEV="";
LINK2SDPATH="";
LINK2SDDEV="";

x=0;
while [ $x -lt $(cat $MOUNTPOINTS | wc -l) ]
do
	let x=x+1;
	LINE=`head -n $x $MOUNTPOINTS | tail -n 1`;
	DEVICE=`echo "$LINE" | cut -d' ' -f1`;
	POINT=`echo "$LINE" | cut -d' ' -f2`;
	if [ $POINT = "/mnt/sdcard/external_sd" ] || [ $POINT = "/mnt/emmc" ] || [ $POINT = "/mnt/sd-ext" ]; then # It's the external SD
		EXTPATH=$POINT;
		EXTDEV=$DEVICE;
	elif [ $POINT = "/mnt/sdcard" ]; then
		INTPATH=$POINT;
		INTDEV=$DEVICE;
	elif [ $POINT = "/data/sdext2" ]; then
		LINK2SDPATH=$POINT;
		LINK2SDDEV=$DEVICE;
	fi
done

if [ -f $BVOLD ]; then
	echo "Restoring backup. ($BVOLD > $VOLD, '' > $LINK2SD)";
	cp $BVOLD $VOLD;
	rm $LINK2SD;
	rm $BVOLD;
	exit;
else
	echo "Making backup. ($VOLD > $BVOLD)";
	cp $VOLD $BVOLD;
fi

if [ $EXTPATH ] && [ $EXTDEV ]; then
	echo "External SD ==";
	echo "$EXTPATH: $EXTDEV";
fi
if [ $INTPATH ] && [ $INTDEV ]; then
	echo "Internal SD ==";
	echo "$INTPATH: $INTDEV";
fi
if [ $LINK2SDPATH ] && [ $LINK2SDDEV ]; then
	echo "Link2SD ==";
	echo "$LINK2SDPATH: $LINK2SDDEV";
fi

echo "" > $VTEMP;
echo "" > $LTEMP;
echo "" > $TEMPFILE;

echo "#!/system/bin/sh" > $LTEMP;
echo "#added by link2sd" >> $LTEMP;
echo "LOG=/data/link2sd-11link2sd.log" >> $LTEMP;
echo "echo \"\$(date) mounting...\" > \$LOG" >> $LTEMP;
echo "" >> $LTEMP;

VEXT="";
VINT="";

x=0;
while [ $x -lt $(cat $VOLD | wc -l) ]
do
	let x=x+1;
	LINE=`head -n $x $VOLD | tail -n 1`;
	ACTION=`echo "$LINE" | cut -d' ' -f1`;
	DEVID=`echo "$LINE" | cut -d' ' -f2`;
	POINT=`echo "$LINE" | cut -d' ' -f3`;
	PART=`echo "$LINE" | cut -d' ' -f4`;
	DEVICE=`echo "$LINE" | cut -d' ' -f5`;
	if [ "$POINT" = "$EXTPATH" ]; then # It's the external SD
		echo "#$LINE" >> $TEMPFILE;
		echo "INT 1" >> $TEMPFILE;
		VEXT="$ACTION $DEVID $INTPATH $PART $DEVICE";
	elif [ "$POINT" = "$INTPATH" ]; then
		echo "#$LINE" >> $TEMPFILE;
		echo "EXT 1" >> $TEMPFILE;
		VINT="$ACTION $DEVID $EXTPATH 12 $DEVICE";
		echo "mount -t vfat -o rw /dev/block/mmcblk0p$PART /data/sdext2 1>>\$LOG 2>>\$LOG" >> $LTEMP;
	else
		echo "$LINE" >> $TEMPFILE;
	fi
done

x=0;
while [ $x -lt $(cat $TEMPFILE | wc -l) ]
do
	let x=x+1;
	LINE=`head -n $x $TEMPFILE | tail -n 1`;
	ACTION=`echo "$LINE" | cut -d' ' -f1`;
	if [ "$ACTION" = "EXT" ] && [ "$VEXT" ]; then
		echo "$VEXT" >> $VTEMP;
	elif [ "$ACTION" = "INT" ] && [ "$VINT" ]; then
		echo "$VINT" >> $VTEMP;
	else
		echo "$LINE" >> $VTEMP;
	fi
done

echo "" >> $LTEMP;
echo "mount >> $LOG" >> $LTEMP;
echo "\"\$(date) mount finished\" >> \$LOG" >> $LTEMP;

cp $LTEMP $LINK2SD;
cp $VTEMP $VOLD;
rm $LTEMP;
rm $VTEMP;
rm $TEMPFILE;

chmod 777 $LINK2SD;
mount -o remount,ro /system
reboot;
Attached Files
File Type: zip eg.link2sd.zip - [Click for QR Code] (1.2 KB, 717 views)
22nd April 2013, 02:13 PM |#5  
egingell's Avatar
OP Senior Member
Thanks Meter: 1,823
 
Donate to Me
More
I can't seem to get this to work without errors and system app crashes on Stock rooted JB 4.1.2.
23rd April 2013, 01:19 AM |#6  
robrooter's Avatar
Senior Member
Flag Greenville
Thanks Meter: 170
 
More
Nice write up. Thanks for the time spent to put this together

E4GT Rom-a-holic!!!
The Following User Says Thank You to robrooter For This Useful Post: [ View ]
23rd April 2013, 01:40 AM |#7  
CyberpodS2's Avatar
Senior Member
Flag NE Pennsylvania Boonies
Thanks Meter: 473
 
More
Quote:
Originally Posted by egingell

I can't seem to get this to work without errors and system app crashes on Stock rooted JB 4.1.2.

Someone smarter than me can validate or disprove my answer here, but I believe JB has different file system mount points than ICS. (he said he did this on BK)
23rd April 2013, 01:46 AM |#8  
robrooter's Avatar
Senior Member
Flag Greenville
Thanks Meter: 170
 
More
Quote:
Originally Posted by CyberpodS2

Someone smarter than me can validate or disprove my answer here, but I believe JB has different file system mount points than ICS. (he said he did this on BK)

You are correct. JB has a different pre load set up. I think you are rite...this was created on the ICS Kuban.

E4GT Rom-a-holic!!!
23rd April 2013, 01:54 AM |#9  
egingell's Avatar
OP Senior Member
Thanks Meter: 1,823
 
Donate to Me
More
Quote:
Originally Posted by CyberpodS2

Someone smarter than me can validate or disprove my answer here, but I believe JB has different file system mount points than ICS. (he said he did this on BK)

Quote:
Originally Posted by robrooter

You are correct. JB has a different pre load set up. I think you are rite...this was created on the ICS Kuban.

E4GT Rom-a-holic!!!

That's just it, it works fine, but System, Settings, and some other system apps crash consistently while the internal sdcard is mounted to Link2SD's directory and the external sdcard mounted in its place. I even made sure to edit my scripts to change where the external and internal would be remounted to (it's /storage/sdcard0 and /storage/extSdCard respectively).

P.S.: It's 4.2 that changes how mounts are seen by or accessible to apps.

Edit: To clarify, the directories get successfully changed around as intended.

Edit 2: Oh, and the phone reboots itself after a few minutes. I had to fix it via Recovery with ADB because the phone wouldn't stay up long enough to do it the normal* way. * Transferring files to the SD card via USB and moving them to their proper destinations via Root Explorer.
Last edited by egingell; 23rd April 2013 at 01:59 AM.
The Following User Says Thank You to egingell For This Useful Post: [ View ]
6th May 2013, 05:19 AM |#10  
egingell's Avatar
OP Senior Member
Thanks Meter: 1,823
 
Donate to Me
More
I figured out why I was having a problem. I was mounting /dev/block/mmcblk0p12 to /storage/extSdCard. The problem is that Android 4.1.2 stock uses /dev/block/mmcblk0p12 as "overflow" for system apps.

I am currently unwilling to test this on my phone at this time. My setup would require /dev/block/mmcblk0p11 to be an EXT4 file system which, judging by what I see in init.rc, is going to get reformatted as exFAT on boot. Besides, Link2SD has since been fixed to find the second partition on the external SD card for the SGS2.
7th June 2013, 11:21 AM |#11  
egingell's Avatar
OP Senior Member
Thanks Meter: 1,823
 
Donate to Me
More
I have successfully mounted my internal SD card to /data/sdext2, mounted my external SD card to /storage/sdcard0, and bound /storage/sdcard0 to /storage/extSdCard (for backward compatibility) using the following scripts.

I provide this information with no warranties or guarantees and I only tested it on the Sprint Epic 4G Touch with stock rooted Jelly Bean 4.1.2. Use it at your own risk.

Requires:
  • root
  • busybox
  • basic knowledge of shell scripts and Linux (not necessarily required, but it doesn't hurt)

Notes:
  • Make sure /system/etc/init.d/12binds, /system/bin/debuggerd, and /system/bin/debuggerd.bin are executable. Just to be safe, you can execute this from a terminal emulator (the asterisk will make it get multiple files at the same time).
    Code:
    mount -o remount,rw /system
    chmod 755 /system/bin/debuggerd*
    chmod 755 /system/etc/init.d/12binds
    mount -o remount,ro /system
  • The reason I converted my SD card to EXT4 is so I can move&bind internal app data (the stuff in /data/data/app.package.name) to /data/sdext2/data/app.package.name and preserve file permissions. exFAT does not support this.

Terminal emulator - Executing this command will wipe the SD card and convert it to EXT4. This is optional:
Code:
mkfs.ext2 /dev/block/mmcblk0p11
/system/etc/vold.fstab
Code:
## Vold 2.0 Generic fstab
## - San Mehat (san@android.com)
##

#######################
## Regular device mount
##
## Format: dev_mount <label> <mount_point> <part> <sysfs_path1...>
## label        - Label for the volume
## mount_point  - Where the volume will be mounted
## part         - Partition # (1 based), or 'auto' for first usable partition.
## <sysfs_path> - List of sysfs paths to source devices
## storage_struct - ex) series, "/mnt/sdcard/extStorages" / parallel
######################
# internal sdcard
{ 
	ums_sys_path = /sys/class/android_usb/f_mass_storage/lun0/file
	secure_format = enable
	discard = enable
}
#dev_mount sdcard /storage/sdcard0 11 /devices/platform/dw_mmc/mmc_host/mmc0/mmc0 encryptable_nonremovable
dev_mount sdcard /storage/sdcard0 1 /devices/virtual/block/cyasblkdevblk0

# external sdcard
{
	ums_sys_path = /sys/class/android_usb/f_mass_storage/lun1/file
	android_secure_containers = enable
}
# This partition is 300MB (the smallest I could make it using MiniTool Partition
# Widard) and is not set to active. It does not mount, which is how I want it. I know
# I'm wasting 300MB of disk space, but that's ok by me.
# This line is here to prevent "damaged SD card" errors.
dev_mount sdcard1 /storage/extSdCard 2 /devices/virtual/block/cyasblkdevblk0
/system/bin/debuggerd - Make sure you rename the original to /system/bin/debuggerd.bin if you haven't already done so.
Code:
#!/system/bin/sh
LOG=/data/link2sd-debuggerd.log
echo "$(date) mounting..." > $LOG

# Delete or comment out this line if you want to make your external SD card into
# an internal and external SD card (both partitions set to active).
# I have not tried setting both partitions on my external SD card to active, so
# I don't know if they will both mount.
# This line binds the internal SD card's directory to the external SD card's
# directory. In other words both internal and external SD cards will be
# the same physical media. You will have duplicates in Music and Gallery.
# If you are not concerned with backward compatibility, you
# can delete or comment out this line.
mount -o bind /storage/sdcard0 /storage/extSdCard 1>>$LOG 2>>$LOG

# Change "ext4" to "vfat" if you did not convert your internal SD card to EXT4.
mount -t ext4 -o rw,noatime,barrier=0,nobh,errors=continue /dev/block/mmcblk0p11 /data/sdext2 1>>$LOG 2>>$LOG

echo "" >> $LOG
echo "init.d" >> $LOG

# Leave this line in if you want init.d support.
busybox run-parts /system/etc/init.d 1>>$LOG 2>>$LOG

echo "" >> $LOG

mount >> $LOG
echo "$(date) mount finished" >> $LOG
echo debuggerd.bin launched >> $LOG
exec /system/bin/debuggerd.bin
/system/etc/init.d/12binds - This is optional and requires more work than you might think and requires your internal card be EXT4, exFAT will not work. It also requires the "run-parts" line in /system/bin/debuggerd.
Code:
#!/system/bin/sh
LOG=/data/symlink.log;
echo "Symlink" > $LOG

busybox mount -o rw,remount /system
busybox mount -o rw,remount /

cd /data/sdext2/data/

for APP in *; do
	cd /data/sdext2/data/$APP;
	for DIR in *; do
		if [ $DIR != "lib" ]; then # don't bind the lib folder, Link2SD does stuff with it.
			echo "" 1>>$LOG 2>>$LOG;
			echo "Binding /data/sdext2/data/$APP/$DIR => /data/data/$APP/$DIR" 1>>$LOG 2>>$LOG;
			mount -o bind "/data/sdext2/data/$APP/$DIR" "/data/data/$APP/$DIR" 1>>$LOG 2>>$LOG;
		fi
	done
done

busybox mount -o ro,remount /system
busybox mount -o ro,remount /
Make sure it is executable (chmod 755 /system/etc/init.d/12binds)

To make the above work:
If this is too much for you, don't do it.
  1. Copy /data/data/app.package.name to /data/sdext2/data or if the folder already exists in /data/sdext2/data, copy the contents of /data/data/app.package.name to /data/sdext2/data/app.package.name. Use Root Explorer or any other root file explorer that will preserve the owner of the files and their permissions. Do not use the "move" option or you will be making new folders and trying to figure out what the owner and group should be!
  2. Open each folder except lib in /data/data/app.package.name and delete everything in them.
  3. Execute /system/etc/init.d/12binds or reboot.
The Following User Says Thank You to egingell For This Useful Post: [ View ]

Read More
Post Reply Subscribe to Thread

Tags
e4gt, init.d, link2sd, script, sgs2

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes