FORUMS
Remove All Ads from XDA

[TIP][TRICK][SCRIPT] ISD for Link2SD #2P, ESD as ISD, 300MB ESD, VM#, NTP.

6,065 posts
Thanks Meter: 12,027
 
By cerj, Recognized Themer on 24th March 2013, 07:49 PM
Post Reply Email Thread
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 ] Gift cerj Ad-Free
 
 
25th March 2013, 03:07 AM |#2  
Senior Member
Flag Nashville
Thanks Meter: 266
 
More
Great. I always wanted to know how to do it.
The Following User Says Thank You to alammori For This Useful Post: [ View ] Gift alammori Ad-Free
26th March 2013, 10:43 AM |#3  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
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, 1327 views)
22nd April 2013, 01:13 PM |#4  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
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, 12:19 AM |#5  
robrooter's Avatar
Senior Member
Flag Greenville
Thanks Meter: 178
 
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 ] Gift robrooter Ad-Free
23rd April 2013, 12:40 AM |#6  
CyberpodS2's Avatar
Senior Member
Flag NE Pennsylvania Boonies
Thanks Meter: 536
 
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, 12:46 AM |#7  
robrooter's Avatar
Senior Member
Flag Greenville
Thanks Meter: 178
 
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, 12:54 AM |#8  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
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.
The Following User Says Thank You to egingell For This Useful Post: [ View ] Gift egingell Ad-Free
6th May 2013, 04:19 AM |#9  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
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, 10:21 AM |#10  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
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 ] Gift egingell Ad-Free
4th July 2013, 04:54 AM |#11  
egingell's Avatar
Senior Member
Thanks Meter: 2,070
 
Donate to Me
More
I bought an SGS4 and promptly broke the SD card I got for it, so I took the one from my S2 and put it in the S4. I then changed the vold.fstab file back to stock. Unfortunately since the internal SD card is EXT formatted, it won't mount as an SD card. This means that any app that relies on the SD card may not work. Apps that use the path work if I mount the SD card via shell script, but there's a caveat: the files that get put there (e.g. $sdcard/Android/data/<app name>/cache/<stuff>) have their owner/group set to that of the app and no other app can use it without changing the files' owner, group, and permissions first. Camera and Gallery apps won't work at all regardless of whether or not I mount the SD card, at least not the ones I've tried (stock camera and gallery, Camera ICS, Gallery ICS, and Social Gallery). Otherwise the phone works fine without error.

Edit: If I mount a temporary file system (mount -t tmpfs /dev/null /storage/sdcard0), I can get the Camera to work, but the Gallery still complains and any pictures get deleted after reboot. This gave me an idea, though: mount the tmpfs and then bind /data/sdext2 to /storage/sdcard0. This worked, for the most part. Gallery apps still don't like it, but the Camera works. I still have to change the owner, group, and permissions to be able to do anything with pics.

For the record, this seems to work the best:
Code:
chown media_rw:media_rw /data/sdext2
chown media_rw:media_rw /data/sdext2/DCIM
chown media_rw:media_rw /data/sdext2/DCIM/*
chown media_rw:media_rw /data/sdext2/DCIM/Camera/*
chmod -r 775 /data/sdext2
/system/bin/debuggerd
Code:
#!/system/bin/sh

LOG=/data/debuggerd.log
echo "$(date) mounting..." > $LOG

mount -t ext4 -o rw,noatime,barrier=0,nobh,errors=continue /dev/block/mmcblk0p11 /data/sdext2 1>>$LOG 2>>$LOG
mount -t tmpfs /dev/null /storage/sdcard0 1>>$LOG 2>>$LOG
mount -o bind /data/sdext2 /storage/sdcard0 1>>$LOG 2>>$LOG

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

/system/xbin/busybox run-parts /data/local/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
I could change it back to exFAT, but I don't wanna.
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