Zaurus

2006/4/27 05:35 PM 更新

SWAPの作成

SDカードをext3フォーマットにしたのでSDカード上にSWAPを作成できる。
SWAPの作り方にはSWAPパーティションを作成する方法とSWAPファイルを作成する方法があるが、今回はSWAPファイルを作成する方法をとる。

まずはSWAPファイルの元となる空のファイルを作成する。
今回は128MBのファイルを作成するが、他のサイズの場合は以下を参照のこと。
 ・32MBならcount=65536
 ・64MBならcount=131072
# dd if=/dev/zero of=/mnt/card/.swap bs=512 count=262144
262144+0 records in
262144+0 records out
作成されただファイルを確認。
# ls -al /mnt/card/
drwxr-xr-x    3 root     root              1024 Mar 23 12:08 .
drwxr-xr-x    7 root     root                    0 Mar 23 10:47 ..
-rw-r--r--      1 root     root      134217728 Mar 23 12:26 .swap
drwx------     2 root     root            12288 Mar 23 11:58 lost+found
空のファイルをSWAPファイルにする。
# mkswap /mnt/card/.swap
Setting up swapspace version 1, size = 134213 kB
SWAPを有効にする。
# swapon /mnt/card/.swap
SWAPが有効になったか確認する。
# free
                      total           used            free       shared      buffers
  Mem:         61888        13320         48568                0             40
 Swap:       131064              0       131064
Total:         192952        13320       179632
SWAPを有効にしたままSDカードをZaurusから抜くと不具合が起こるのでSDカードの抜き差し時に自動的にSWAPを有効/無効になるようにする。
  /etc/sdcontrol
'insert')
        (省略)
        if [ -f /usr/bin/ipkg-link ]; then
            /usr/bin/ipkg-link mount $MOUNT_POINT
        fi
        swapon /mnt/card/.swap
        ;;

'eject')
        swapoff /mnt/card/.swap
        if [ "$STORAGE_DEV" = "$DEVICE" ]; then
            if [ $STORAGE_PID ]; then
                kill -HUP "$STORAGE_PID"
            fi
        fi
        (省略)

'compeject')
        swapoff /mnt/card/.swap
        if [ "$STORAGE_DEV" = "$DEVICE" ]; then
            if [ $STORAGE_PID ]; then
                kill -HUP "$STORAGE_PID"
            fi
        fi
        (省略)

ext3化してしまったSDカードはWindowsで認識させることができないのでSDカードは抜かないものとしてしまえばより安全になる。