SDcard emulation

From iDroidWiki

Revision as of 15:13, 24 May 2022 by Ddominator (Talk | contribs)
Jump to: navigation, search

Contents

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.)

NOTE: Some users have reported that enabling SD Card Emulation breaks Wi-Fi. Proceed with caution especially with editing init.rc.

Creating SD Card Image

- First of all you will have to create a sdcard image:

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

- I formated to ext2 filesystem

mkfs.ext2 sdcard.img

- 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

- Boot into iPhoneOS - Copy via scp the file you created to /private/var:

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

Modifying the startup files

android.img.gz

- Mount the file

gunzip android.img.gz
mount -o loop android.img /mnt

Mac

      gunzip android.img.gz
      sudo mkdir -p /mnt/android
      sudo fuse-ext2 android.img /mnt/android -o force

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

- 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


- Unmount and archive file back to the way it was

umount /mnt
gzip android.img

Mac

      sudo umount /mnt/android
      gzip android.img

- scp the file over to the device in /private/var

Automount

- Boot into iDroid - Connect via adb

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

- 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

- Connect to device

adb shell

- remount / partition as read-write

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

- send the modified file to the device

adb push init.rc /

- be sure to check if the file is there(somehow it wasn't sent over one time I edited it)

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

Finishing up

- reboot your device

adb shell
su
reboot

- to add files to your new sdcard:

adb push whatever_file /sdcard

Method for Official Release 0.2

SD card emulation now works differently with 0.2 release. There is no longer a need for an sdcard.img

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 7.0 GB.

What you need for this is ADB, rooted iDroid, and a way to connect to your iPhone OS (USB cable).

Create your SD Card folder

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

- While in iPhone OS, create a folder named /sdcard in your /private/var

- So it should have the path /private/var/sdcard

- Folder sdcard can be any name you want.

Creating a new symbolic link

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

- Connect to android:

 adb shell

- Gain superuser privileges:

 su

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

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

- Delete the old Symlink

 rm sdcard

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

 ls -l

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

 ln -s  /host/sdcard /sdcard

- Change permissions to allow folder to be modified

 chmod 777 /sdcard

Completion

- Reboot your device

 reboot

- To add files to your new sdcard:

 adb push "whatever_file" /sdcard

Notes

- If you want access to your entire iTunes music library, set your symlink to "/host/mobile/Media" This is for advanced users only as this can mess up your iPhone OS!!!

- Use Android's Media Scanner (Dev Tools -> Media Scanner) to refresh the data and add your music files to your Music App library. Take note that because of iTunes Encryption, an entire album can be split into 5 albums with the same name (ex. Michael Jackson's Dangerous: you could have 5 "Dangerous" albums in your library with each album containing random songs and in no order from their track listing).

- I haven't tested if you need a modified init.rc, if SD card won't show up, then do the steps above (Method for 0.1a) in modifying the startup files.

Really OLD Method

Under Construction - the following guide is no longer needed
IT IS SUGGESTED TO DO NOT FOLLOW THIS GUIDE - IT MAY BREAK WIFI, IF YOU HAVE DONE THE INIT.RC PART AND YOUR WIFI STOPPED WORKING, PLEASE REINSTALL AND WAIT FOR A FIX In order to gain access to the sdcard you will need to emulate it:


Prepare symlink

First of all you need Root Access, follow this tutorial

Connect to android:

 adb shell

Gain superuser privileges:

 su

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

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


Create a symlink from the /sdcard to a folder of your choice:

 ln -s  /sdcard/*whatever* /sdcard

Automounting the emulated SD card

Either download the already premodified init.rc (recommended) here: [1]

Or follow these steps to manually add the commands:

1. Close the previous adb shell (press Ctrl+C) session, making sure root is still mounted as read/write.

2. Type:

 adb pull /init.rc *path to file on your PC*

3. Open the file up in your preferred text editing application. Make sure it is one that keeps formatting in the document (notepad does not keep formatting - it is all packed up into one line)

Under the following line:

 write /proc/sys/kernel/sched_compat_yield 1

Add this:

 setprop EXTERNAL_STORAGE_STATE mounted

(It can actually go anywhere in the document, but its tidier to put it in the mounting phase.)

4. In terminal/command prompt type:

 adb push *path to file on your PC* /

5. Reboot the device in the terminal emulator on your device with:

 su
 reboot

Android should now see an SD card in the settings pane with about 194 MB free space.

To add files to your "SD Card" simply push said files to /sdcard or /data/sdcard.


--- BEGIN OSX NOTES ---

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

Assuming 10.6

This fixes things for ext2fs: sudo ln -s /usr/bin/update_dyld_shared_cache /usr/bin/update_prebinding

Then using http://www.charlessoft.com/Pacifist.dmg install http://sourceforge.net/projects/ext2fsx/files/ext2fsx_dev/1.4d4/Ext2FS_1.4d4.dmg/download - This installs mkfs.ext2 into /usr/local/sbin.

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.

I'll try to clean this up when I wake up again... :)

[edit] these files are saved in /usr/local/sbin/ add this the the start of your commands if adb doesnt work automatically

--- END OSX NOTES ---

Credit

  • 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
  • Personal tools