HowTo CreateSwap

  1. (Feel free to bother AlexanderLash with questions and such.)
    1. ITOS2006 / Maemo 2.0
(!) **Note, the Internet Tablet 2006 operating system includes a control panel applet to do this for you.**

Swap files are used as virtual memory when the use of physical memory is not possible or not desired. Better explanations can be found on Wikipedia (http://en.wikipedia.org/wiki/Swap_file).

DO THIS AT YOUR OWN RISK: I take no responsibility for shortening the life of your MMC. Swap files tend to be frequently written to, and all flash memory has a noticeably finite number of writes before failure. Under no circumstances create a swap file in internal memory!

Please note that OS .51 does not handle swap files in excess of 24MB (24576B) correctly and will in fact crash, reboot, or otherwise fail to function when swap is enabled on a file larger than 24MB.

(All of the following must be run as root)

To create and initialize the swap file:

dd if=/dev/zero of=/media/mmc1/swapfile bs=1024 count=24576
mkswap /media/mmc1/swapfile 24576

To begin using the swap file:

swapon /media/mmc1/swapfile

To verify that swap was enabled:

free

To stop using swap (must be done before the card is unmounted):

swapoff /media/mmc1/swapfile

I recommend adding

user ALL = NOPASSWD: /sbin/swapon /media/mmc1/swapfile
user ALL = NOPASSWD: /sbin/swapoff /media/mmc1/swapfile

to /etc/sudoers for easy inclusion of swapon/swapoff in shell scripts.

/!\ Warning! Be extremely careful when editing the /etc/sudoers file. The slightest typo could brick the device.

(Feel free to bother AlexanderLash with questions and such.)

If you're sure you want it activated on bootup and deactivated on shutdown, modify the system startup and shutdown scripts (as root):

echo -e "/media/mmc1/swapfile\tnone\tswap\tsw\t0\t0">>/etc/fstab
sed -i '/exit/iswapon -a 2>/dev/null' /etc/init.d/minircS
sed -i '/umount/iswapoff -a 2>/dev/null' /etc/init.d/minireboot /etc/init.d/minishutdown

What's best about my way of (de)activating swap is that this works independently of the actual swap file or partition. The startup, reboot and shutdown scripts will work the same no matter if there's swap available or not. To add or remove a swap file or partition, simply modify /etc/fstab (after manually deactivating swap with swapoff -a), without having to touch the scripts again. Even if you decide against swap, it's enough to delete or comment out the line(s) in /etc/fstab, the scripts will keep working. I'd actually like Nokia to include something like that in their own system scripts with a future version of the 770's OS. -- StefanDanielSchwarz

Instead of editing your Nokia 770 system boot scripts to auto-activate the swap on boot, you might install the CPU/Mem/Screenshot applet with SwapOn/Off (load-plugin-aw), see ApplicationCatalog Wiki.

/!\ '''There's an important problem to keep in mind when using a swapfile on the memory card:** The first (and, by default, only) partition is unavailable to the Nokia 770 whenever a USB connection to a computer is established. Then the swapfile becomes unavailable, too, which can crash the system. To avoid this, either modify the scripts or repartition the card, both options can be difficult and dangerous (but so is using swap, too, of course). A compromise between creating a swapfile and using a new partition for swap - which combines the advantages of both (and much more) - is documented here: ExtendedRootFilesystem

The advantage of a swap partition instead of a swap file is that the swap partition remains available if you connect your Nokia 770 via USB to the PC, while the filesystem on the memory-card is unmounted. (Still you have to swapoff before removal of the memory-card, otherwise the Nokia 770 will crash. You might use the CPU/Mem/Screenshot applet with SwapOn/Off (load-plugin-aw) to swapoff before you remove (hot-unplug) the memory-card.) To create a swap partition on your RS-MMC memory-card, do the following: Backup your memory-card, then repartition it from a PC via USB. Create and format /dev/mmcblk0p1 as VFAT and /dev/mmcblk0p2 as SWAP partition using the PC. (Keep the swap partition below 24MB, use the rest for the filesystem partition.) See http://www.dillernet.com/apple/2005/12/27/making-swap/ for a more detailed discussion about having a swap partition on the memory-card. -- ArminMWarda

/!\ There might be some correlation between enabling swap and poor system stability even if swap file does not exceed 24MB: http://maemo.org/pipermail/maemo-users/2006-January/000555.html

ITOS2006 / Maemo 2.0

**Note:''' John Costigan's 'load-applet-run' can execute and store arbitrary commands. http://gnuite.com:8080/nokia770/ This can be used for swapon/off, which is very useful for those of us who prefer to continue to have their swap in a dedicated partition on the MMC, e.g. '/dev/mmcblk0p2'.

Default now with ITOS2006 is to have a swap file '/media/mmc1/.swap', which is within the filesystem in '/dev/mmcblk0p1'. You do not need the modified applet if you are happy with the new default swap file in ITOS2006!

''There are pros and cons with swap files versus swap partitions. For example ITOS2006 automagically swapoffs the swap file if the filesystems gets umounted when you connect the device via USB to the PC (and automagically swapons after the USB disconnect caused to mount '/media/mmc1' again). On the other hand, a swap partition simply can remain active in this situation, it is not affected by USB handling.''

/!\ ''The downside of swap partition versus swap file comes with phyiscal MMC ejection: With a swap partition you have to manually swapoff (via the applet or xterm) before you eject the card (and manually swapon again after MMC insertion), while ITOS2006 somehow automagically swapoffs the swap file before ejection (and swapons after MMC insertion). If you fail to swapoff before MMC ejection the device will crash.''

Note: If you want to use swapon/off of the modified CPU/Mem/Screenshot applet you have to edit /etc/sudoers, which requires you to gain root.

Warning: Swap on dedicated partitions, messing around on your device being root, and editing /etc/sudoers is not intended for end-users but only for experts. Use with care. You have been warned. Create a backup. If unsure - stay with the default swap file in ITOS2006.