SDcard emulation

From iDroidWiki

Jump to: navigation, search

Contents

Warnings and Prerequisites

  • This is for enabling SD Cards on your iDroid.
  • ADB is required and you must have ADB installed.

Preparing the Automount (init.rc)

  • Caution should be made when editing init.rc because it may mess up WiFi.
  • Both methods for official releases 0.1a and 0.2 require init.rc to be edited.

1. Boot into iDroid and connect via adb

adb connect xxx.xxx.xxx.xxx:5555
adb pull /init.rc .

2. Edit this file preferably with a terminal editor (nano, joe, vi, mcedit)

  • Add above the lines (around line 249)...
# Define TCP buffer sizes for various networks
#   ReadMin, ReadInitial, ReadMax, WriteMin, WriteInitial, WriteMax,
  • ...the following:
# Enable SD Storage
   setprop EXTERNAL_STORAGE_STATE mounted

3. Connect to device

adb shell

4. Remount / partition as read-write

su
mount -o remount,rw /dev/root /
exit
exit

5. Send the modified file to the device

adb push init.rc /

6. Be sure to check if the file is there.

adb shell
ls -l /init.rc
cat /init.rc    # Check to see it the lines you added are there

7. Reboot

su
reboot

Method for Official Release 0.1a

In order to get this working you will need Linux (or OSX with EXT2FS - follow the same instructions but see OSX notes at the bottom of this page.)

init.rc should already have been edited (see above).

Creating SD Card Image

  • First of all you will have to create a sdcard image, in Terminal:
dd if=/dev/zero of=sdcard.img bs=1024 count=500000
  • This will create a 500 Megabyte empty file. You can change the count and increase it as you see suitable

Formating sdcard.img

1. I formated to ext2 filesystem. In Terminal:

mkfs.ext2 sdcard.img

2. Press y on the block device question

  • Note: If this doesnt work I used /usr/local/sbin/mkfs.ext2 sdcard.img this seemed to work

Getting the file on device

1. Boot into iPhoneOS

2. Transfer sdcard.img through scp, or whatever iPhone File Manager/Explore to /private/var. If by scp, use this command:

scp sdcard.img root@iphone_ip:/private/var

Modifying the startup files (android.img.gz)

1. Mount the file

  • In Linux Terminal:
gunzip android.img.gz
mount -o loop android.img /mnt
  • In Mac Terminal:
gunzip android.img.gz
sudo mkdir -p /mnt/android
sudo fuse-ext2 android.img /mnt/android -o force

2. Edit the init file (using a terminal editor such as nano or vim) located in /mnt to look like this or the one below:

3. Also, to edit the file you may need to run your editor as so to save it:

sudo gedit
#!/bin/bash
[ -d /dev ] || /bin/mkdir -m 0755 /dev
[ -d /root ] || /bin/mkdir --mode=0700 /root
[ -d /sys ] || /bin/mkdir /sys
[ -d /proc ] || /bin/mkdir /proc
[ -d /tmp ] || /bin/mkdir /tmp
[ -d /etc ] || /bin/mkdir /etc
[ -d /mnt ] || /bin/mkdir /mnt
[ -d /android ] || /bin/mkdir /android
[ -e /dev/console ] || /bin/mknod /dev/console c 5 1
cat > /etc/fstab << FSTAB_DONE
FSTAB_DONE
/bin/mount -t sysfs none /sys -onodev,noexec,nosuid
/bin/mount -t proc none /proc -onodev,noexec,nosuid
# We need to load the firmware as quickly as possible because there's a timeout
while [ ! -e /sys/class/firmware/mmc*/loading ]
do
	/bin/sleep 1
done
# Load the helper
echo 1 > /sys/class/firmware/mmc*/loading
/bin/cat /lib/firmware/sd8686_helper.bin > /sys/class/firmware/mmc*/data
echo 0 > /sys/class/firmware/mmc*/loading
/bin/sleep 1
while [ ! -e /sys/class/firmware/mmc*/loading ]
do
	/bin/sleep 1
done
# Load the main firmware
echo 1 > /sys/class/firmware/mmc*/loading
/bin/cat /lib/firmware/sd8686.bin > /sys/class/firmware/mmc*/data
echo 0 > /sys/class/firmware/mmc*/loading
while [ ! -e /sys/class/block/nand0p2/dev ]
do
	/bin/sleep 1
done
/bin/mknod /dev/loop0 b 7 0 &> /dev/console
/bin/mknod /dev/loop1 b 7 1 &> /dev/console
/bin/mknod /dev/loop2 b 7 2 &> /dev/console
/bin/mknod /dev/loop3 b 7 3 &> /dev/console
/bin/mknod /dev/loop4 b 7 4 &> /dev/console
/bin/mknod /dev/nand0p2 b `/bin/cat /sys/class/block/nand0p2/dev | /usr/bin/tr ':' ' '`
/sbin/fsck.hfsplus -q /dev/nand0p2 &> /dev/null
if [ $? != 0 ]
then
	/sbin/fsck.hfsplus /dev/nand0p2
fi
/bin/mount -o noatime /dev/nand0p2 /mnt
/bin/chmod a+rx /mnt
/sbin/losetup /dev/loop0 /mnt/ramdisk.img
/sbin/losetup /dev/loop1 /mnt/system.img
/sbin/losetup /dev/loop2 /mnt/userdata.img
/sbin/losetup /dev/loop3 /mnt/cache.img
/sbin/losetup /dev/loop4 /mnt/sdcard.img
/sbin/fsck.ext2 -p /dev/loop0
/sbin/fsck.ext2 -p /dev/loop1
/sbin/fsck.ext2 -p /dev/loop2
/sbin/fsck.ext2 -p /dev/loop3
/sbin/fsck.ext2 -p /dev/loop4
/bin/mount -o noatime /dev/loop0 /android
/bin/mkdir /android/host
/bin/mkdir /android/system
/bin/mkdir /android/data
/bin/mkdir /android/cache
/bin/mkdir /android/sdcard
/bin/mount -o noatime,ro /dev/loop1 /android/system
/bin/mount -o noatime,nosuid,nodev /dev/loop2 /android/data
/bin/mount -o noatime,nosuid,nodev /dev/loop3 /android/cache
/bin/mount -o noatime,nosuid,nodev /dev/loop4 /android/sdcard
#/bin/mkdir /android/initrd
/bin/umount /sys
/bin/umount /proc
/bin/mount -n --move /mnt /android/host
cd /android
#/sbin/pivot_root . initrd
exec /usr/sbin/chroot . /init

4. Unmount and archive file back to the way it was

  • In Linux Terminal
umount /mnt
gzip android.img
  • In Mac Terminal
sudo umount /mnt/android
gzip android.img

5. Transfer the modified android.img.gz to the iPhone's /private/var directory. You can use scp, or an iPhone File Manager/Explorer.

Finishing up

  • Boot iDroid.
  • To add files to your new sdcard, connect via ADB:
adb push whatever_file /sdcard

Method for Official Release 0.2

  • SD card emulation works differently with 0.2 release. There is no longer a need for an sdcard.img
  • You need to have init.rc edited (refer to the guide above).
  • This method is an addition to the one posted on Installing iDroid (Linux). The method there only enables up to 194MB. This method gives you access to your iPhone folders (be careful) and maximum storage capacity of that of your iPhone.
  • You need [Root Access|root access]] for this to work.

Create your SD Card folder

  • If you plan to make your SD card your iPhone's Music folder, then skip this section.

1. While in iPhone OS, create a folder named /sdcard in your /private/var using scp or any iPhone File Manager/Explorer

2. So it should have the path /private/var/sdcard

  • Folder sdcard can be any name you want.

Creating a new symbolic link (symlink)

1. Boot into your iDroid and connect to it via ADB.

2. Access the ADB Shell:

 adb shell

3. Gain superuser privileges:

 su

4. Set /data and / (system root) to read and write:

 mount -o remount,rw /dev/root /
 mount -o remount,rw /dev/root /data

5. Delete the old symlink

 rm sdcard

6. Check to make sure it's gone (sdcard is not listed)

 ls -l

7. Create a symlink from the /sdcard to the /private/var/sdcard folder just created:

 ln -s  /host/sdcard /sdcard

8. Change permissions to allow folder to be modified

 chmod 777 /sdcard

Completion

9. Reboot your device and load iDroid.

 reboot

10. To add files to your new sdcard:

 adb push "whatever_file" /sdcard

Having a Shared Library with iPhone OS

Warning: this guide may disable iPhone from booting, or brick your iPhone if performed incorrectly!!!

  • This guide is for you if you want access to your entire iTunes music library.
  • This is for advanced users or people who know and understand what they are doing.
  • Please backup all your files in iDroid, and in iPhone OS as you may need to perform a DFU restore in case anything goes wrong.

Method

1. Boot into your iDroid and connect to it via ADB.

2. Access the ADB Shell:

 adb shell

3. Gain superuser privileges:

 su

4. Set /data and / (system root) to read and write:

 mount -o remount,rw /dev/root /
 mount -o remount,rw /dev/root /data

5. Delete the old symlink

 rm sdcard

6. Check to make sure it's gone (sdcard is not listed)

 ls -l

7. Create a symlink to link iPhone Media library:

 ln -s  /host/mobile/Media sdcard

8. Change permissions and users to allow folders to be modified and accessed:

chmod 755 /host/mobile/
chmod 777 /host/mobile/Media
chmod 777 /host/mobile/Media/iTunes_Control
chmod 777 /host/mobile/Media/iTunes_Control/Music
chown root /host/mobile
chown root /host/mobile/Media
  • Some users reported that the commands below are not needed. You can choose to skip the next 2 commands but if SD emulation doesn't work or you cannot detect your MP3s, try the following in ADB Shell:
chown root /host/mobile/Media/iTunes_Control
chown root /host/mobile/Media/iTunes_Control/Music

9. Reboot your device and load iDroid.

 reboot

10. Check to see if SD card is emulated properly by going to Settings > SD card and storage.

11. Run Media Scanner (Dev Tools > Media Scanner) to add your iPhone's MP3s to your iDroid's Music library.

12. Open Music app to see if the songs were added. The albums are unorganized but there is a script to fix that. Downloaded the script from http://idroid.nickpack.com/iDroid/fixes/. It is android-Music-library-fix.nitestarzz.zip. Extract it (afix_lib.sh) and put it somewhere you know.

13. Connect via ADB and push it into your root folder:

First remount / as read-write on the phone

 ./adb shell
mount -o remount,rw /dev/root /

Then send the file

adb push /folder/afix_lib.sh /
  • folder is the path where you extracted afix_lib.sh to.


14.2 To execute the script, go into Terminal Emulator (Dev Tools > Terminal Emulator), enter the command:

su
sh afix_lib.sh
  • If you have GScript, it would be easier to create a macro/script to run the script.

15. Wait for the script to finish, then exit Terminal Emulator and run Music app. Your albums are now organized. NOTE: You will have to run the script every time you use Media Scanner.

OSX Notes

  • Don't continue if you don't know why: sudo rm -rf / is a bad idea.

Assuming OS 10.6

  • This fixes things for ext2fs:
sudo ln -s /usr/bin/update_dyld_shared_cache /usr/bin/update_prebinding
  • You should already have fuse and fuse-ext2fs installed from the original install - use fuse-ext2 to mount the android.img (just follow the same basic instructions for the mount that you did when you pushed the firmware to the the android.img for mounting and unmounting) Otherwise it's the same flow as the linux instructions.
  • These files are saved in /usr/local/sbin/ add this the the start of your commands if adb doesnt work automatically

Credits

  • Dr_gogeta86 - for finding the "setprop EXTERNAL_STORAGE_STATE mounted"
  • alex - tidying up the guide and adding automount
  • mboeru - method 1
  • boing - poorly drafted OSX notes
  • nitestarzz - for teaching ddominator about symlinks, determining the required permissions and creating the Library Fix script (afix_lib.sh)
  • Personal tools