[G1 Android Development] midnite23:
Grrrr. I thought I might have had a way to start swap on boot, but of course my phone is still suffering from the com.android.phone force close, so i can't really do much with it right now, and must do a wipe/flash.

However, if somebody wants to test this out, then please feel free. This was sent to me earlier this month bilcintonsdaman, and I've been sitting on it since then.

2. Remount your /system read write. Either do adb remount or:

# mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

3. Modify your /system/init.rc file by adding the following to the end:

service sysctl /system/xbin/bb/sysctl -p

on system

mknod /dev/mmcblk0p3 b 179 3 1000

The service sysctl will be explained later. The numbers in the mknod line identify the location and file system type on the sd card. Check the mknod man page for more information. 3 is the number of the partition. My sd card has 3 partitions: first is the regular fat for storage, second is ext3 for apps2sd, third is the new ext2 one. Make sure you're using the correct location.

Reboot

4. Remount read-write, make a directory to mount the partition on, and mount it:

# mkdir /system/swap

# mount /dev/mmcblk0p3 /system/swap

5. Swap needs an actual file to swap to, not just free memory, so make a swap file the size of the new partition. Also, creating a new ext2 file system creates a lost+found directory. I deleted that before creating the file:

# cd /system/swap

# rmdir lost+found

# dd if=/dev/zero of=swap bs=1M count=32

dd: writing 'swap': No space left on device

31+0 records in

29+1 records out

# mkswap /system/swap/swap

Setting up swapspace version 1, size = 31338496 bytes

6. A variable called swappiness sets how agressively the os swaps. The default is 60. You can check it by:

# cat /proc/sys/vm/swappiness

60

This is far too aggressive for what we're doing, and will render the phone unusably slow quickly. 20 is a much better setting. The sysctl line we added to init.rc will run sysctl on boot and set whatever is in /etc/sysctl.conf, so let's make that file:

# echo vm.swappiness=20 > /system/etc/sysctl.conf

Now, whenever the phone boots the variable will be set to 20. For more information on the boot process, check out Android Initialization Process. Here's my init.rc file for reference (CyanogenMod v3.3.6):

# cat /system/init.rc

on system

mount cramfs loop@/system/modules/modules.cramfs /system/modules ro

mount cramfs loop@/system/xbin/xbin.cramfs /system/xbin ro

service reboot /system/bin/shutdown -r

disabled

oneshot

service poweroff /system/bin/shutdown

disabled

oneshot

service sysctl /system/xbin/bb/sysctl -p

on system

mknod /dev/mmcblk0p3 b 179 3 1000

7. Make a script to mount your partition and swapon the new file. I have a script called remount that will also remount the /system partion read-write or read only. Here's the full script:

#!/system/bin/sh

if [ $# = 0 ] || [ "$1" != rw ] && [ "$1" != ro ] && [ "$1" != swap ]; then

echo 'remount COMMAND

rw for read/write

ro for read only (normal)

swap to mount swapspace'

elif [ "$1" = swap ]; then

mount /dev/mmcblk0p3 /system/swap

swapon /system/swap/swap

else

mount -o $1,remount -t yaffs2 /dev/block/mtdblock3 /system

fi

Put the script somewhere in your path (mine's in /system/bin) and make it executable:

# cp remount /system/bin

# chmod 755 /system/bin/remount

8. Reboot. You should now be able to do remount swap as root and it'll set up your swap file for you. Run free to check:

# remount swap

# free

total used free shared buffers

Mem: 98536 96436 2100 0 892

Swap: 30232 52 30180

Total: 128768 96488 32280

I also have a script that I called config that sets up some customizations for when I upgrade to a new rom. Parts of it will probably be useful, so I'll include it here:

#!/system/bin/sh

#mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

cp /sdcard/backup/remount /system/bin

chmod 775 /system/bin/remount

mkdir /system/swap

rm /system/init.rc

cp /sdcard/backup/init.rc /system

cp /sdcard/backup/mountd.conf /system/etc

cp /sdcard/backup/sysctl.conf /system/etc

cp /sdcard/backup/AudioFilter.csv /system/etc

cp /sdcard/backup/AudioPara4.csv /system/etc

cp /sdcard/backup/AudioPara_TMUS.csv /system/etc

cp /sdcard/backup/profile /system/etc

reboot

After an upgrade, I remount read-write, then:

# cp /sdcard/backup/config /system/bin

# chmod 700 /system/bin/config

# config

And then, after the reboot, delete config.

The End

Hope this helps. And has anybody else experienced the force close of the com.android.phone process or am a single case?