[Android Head-Units] squegie:
How to mount the external sdcard as internal

One frustration I have had with this unit is the lack of storage on the internal sdcard. I have an app called coPilot (really good offline navigation) that wants to download 2GB of maps, but can't because of the sdcard size. At the same time, I have a 16GB microSD card that would be perfect. Today I spent some time in the car to fix this. coPilot insists that there is no way to manually select where the maps get downloaded to and this issue is really the fault of the OEMs. There is a way to fix this (as root) by editing the coPilot configuration file (coPilot configuration file. But I wanted a single solution for any app I might encounter.

This will also help with any music apps that want to read from the sdcard.

My desire:

mount /dev/mnt/mmcblk1p1 as /mnt/sdcard

mount whatever device /mnt/sdcard currently points to as /mnt/intsdcard for backup purposes.

If you want to know how to do it, just skip ahead, but if you'd like to know a bit more, read on..

There are a number of apps on the market that were made to address a very similar issue on tables, especially Samsung Tablets. However, none of them know about the /dev/mnt/mmcblk1p1 mount point, and none seemed to work for me. I know linux fairly well, so I figured I'd take a shot. The first thing I encountered is that /mnt/sdcard was mounted to "/dev/block/vold/259:1". I learned a bit about vold (volume daemon), but none of it helped me to mount this partition to a mountpoint. In the end, I found all the nice device names in /dev/block and ran fdisk -l against all of them to figure out that "/dev/block/vold/259:1" was also known as "/dev/block/mmcblk0p9". Once I knew this, I could easily type the commands to change my mount points, but I would loose them on reboot.

After playing with the /system/etc/init type scripts a bit, I found an app called Script Manager that worked great for running things on boot. If someone can give a few steps to make my script execute on boot without using this app, I'd appreciate the tip. My radio is mounted in the car and one can only sit out there for so long before neighbors start to wonder. So once I got it working, I called it a day.

HOWTO

WARNING: Doing this wrong (or even exactly right) could cause your radio not to boot, lead to loss of data, or being generally disliked by your immediate family. In my case, I did not move any apps to the internal sdcard, but if you have moved apps (like sygic) to it, you may find them no longer working and needing to be reinstalled. Also, once you make this change, you bad things may happen if you decide to eject the microSD card while apps are running from it. In my case, my plan is to tape it in place and put a small dab of elmer's glue over the slot.

Pre-Requisites

Root (The Root my AN21U mentioned in this thread works great.) - http://xdaforums.com/wiki/Tonghai_Create_AN-21_U#Rooting

Busybox https://play.google.com/store/apps/details?id=stericson.busybox

Terminal Emulator - https://play.google.com/store/apps/details?id=jackpal.androidterm

Your favorite text editor. Mine is DroidEdit, but you can also use vi in terminal emulator. - https://play.google.com/store/apps/details?id=com.aor.droidedit&hl=en

Script Manager - this makes the change work on boot - https://play.google.com/store/apps/details?id=os.tools.scriptmanager&hl=en

A wireless keyboard would make this go faster. I like the Logitech K400, but that's just me.

STEPS

In your text editor, create a file called remountsd.sh with the following code. Save it wherever you can, but that will probably be in /mnt/sdcard initially. Just remember where you saved it so we can come back to it later.

#!/system/bin/sh

# Busybox directory. Honestly, the only thing you really need busybox is for the `mount -l` command.
# I'm assuming that it's in /system/xbin. You can type `which busybox` to find out.
BB=/system/xbin

if [ ! -d /mnt/intsdcard ]
then
echo "Creating /mnt/intsdcard"
$BB/mount -o remount,rw /
mkdir /mnt/intsdcard
$BB/mount -o remount,ro /
fi

# lazily unmount existing sdcard
$BB/umount -l /mnt/sdcard

# /dev/block/vold/259:1 -> matches /dev/block/mmcblk0p9
# mount internal sdcard to /mnt/intsdcard
$BB/mount /dev/block/mmcblk0p9 /mnt/intsdcard

# mount microSD to /mnt/sdcard
$BB/mount /dev/block/mmcblk1p1 /mnt/sdcard

Now, open up Terminal Emulator and type the following commands. I am assuming that remountsd.sh is saved as /mnt/sdcard/remountsd.sh

# get root. You'll be prompted for superuser privileges, grant them.
su
# make /system writable
mount -o remount,rw /system
# copy your remountsd.sh file over
cp /mnt/sdcard/remountsd.sh /etc
chmod 755 /etc/remountsd.sh
# make /system readonly again
mount -o remount,ro /system

Now switch back to your home screen and open SManager. When prompted, choose "Browse as root". You'll have to grant the program super user privileges (and remember always).

You can try running the script now to make sure it works. If it doesn't, you should stop here and double-check your work.

To verify it worked, go into Terminal Emulator and run `df`. You should see a number of lines, but two that look like this (the example below shows a 16GB microSD card).

/mnt/intsdcard 5G 4G 980M 4096
/mnt/sdcard 15G 99M 14G 32768

Assuming the script ran properly, we need to set it up for boot. Select the icon for "SU" (superuser) and the one for "boot" to make sure this happens on boot.

Save your work and restart the radio (hint: you can type `reboot` in the terminal).

Once the radio comes back up, go into terminal emulator and run the `df` command again to make sure the mounts are correct.

At this point, you're almost done. The last step is to create a directory /mnt/sdcard/ANDROID. With that directory in place, you can migrate apps to the sdcard with any sort of App2SD type app, or right from settings.

Any old data you used to have is in /mnt/intsdcard. You should be able to copy it over without too much issue.

Let me know if this works, doesn't work, or needs corrections. Other than the script itself, most of this is from memory.