SDcard emulation
From iDroid Project
Contents |
Introduction
- From the iDroid MoJo releases, SD card is automatically mounted, emulated and fixed, as long as a folder called sdcard exists in iOS /private/var. If you are not using MoJo, it is suggested that you upgrade by referring to the Installation Guide.
Warnings and Prerequisites
- ADB is required and you must have ADB installed.
- Don't continue if you don't know why: sudo rm -rf / is a bad idea.
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
sdcard.img Method
- 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).
- This method uses a set sdcard.img to serve as the sdcard. You can set the size of the sdcard but that will limit the storage space to the size you set.
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 su 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
Symbolic Link Method
- 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 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