How to setup SWAP on ddwrt router

Posted on November 5, 2011

1



By default there is no SWAP on the ddwrt routers, in case you need it you have to setup it on your own, but that is not so complicated, just read the documentations.

Source documentation:
http://www.dd-wrt.com/wiki/index.php/Linux_SWAP#Requirements

Here is what I have done:

1. Create a file for the swap

root@mygateway:/# dd if=/dev/zero of=/mnt/myswap.swp bs=1k count=80000

80000+0 records in
80000+0 records out

2. Install busybox (optional, it is already installed)

root@mygateway:/# ipkg-opt install busybox
Installing busybox (1.10.3-1) to /opt/…
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/cross/stable/busybox_1.10.3-1_mipsel.ipk
Installing busybox-base (1.10.3-1) to /opt/…
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/cross/stable/busybox-base_1.10.3-1_mipsel.ipk
Installing busybox-links (1.10.3-1) to /opt/…
Downloading http://ipkg.nslu2-linux.org/feeds/optware/ddwrt/cross/stable/busybox-links_1.10.3-1_mipsel.ipk
Configuring busybox
Configuring busybox-base
Configuring busybox-links
update-alternatives: Linking //opt/bin/[ to /opt/bin/busybox
update-alternatives: Linking //opt/bin/[[ to /opt/bin/busybox
update-alternatives: Linking //opt/bin/arping to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ash to /opt/bin/busybox
update-alternatives: Linking //opt/bin/awk to /opt/bin/busybox
update-alternatives: Linking //opt/bin/basename to /opt/bin/busybox
update-alternatives: Linking //opt/bin/bunzip2 to /opt/bin/busybox
update-alternatives: Linking //opt/bin/bzcat to /opt/bin/busybox
update-alternatives: Linking //opt/bin/bzip2 to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cal to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cat to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chattr to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chgrp to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chmod to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chown to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chroot to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chrt to /opt/bin/busybox
update-alternatives: Linking //opt/bin/chvt to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cksum to /opt/bin/busybox
update-alternatives: Linking //opt/bin/clear to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cmp to /opt/bin/busybox
update-alternatives: Linking //opt/bin/comm to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cp to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cpio to /opt/bin/busybox
update-alternatives: Linking //opt/bin/cut to /opt/bin/busybox
update-alternatives: Linking //opt/bin/date to /opt/bin/busybox
update-alternatives: Linking //opt/bin/dd to /opt/bin/busybox
update-alternatives: Linking //opt/bin/deallocvt to /opt/bin/busybox
update-alternatives: Linking //opt/bin/df to /opt/bin/busybox
update-alternatives: Linking //opt/bin/diff to /opt/bin/busybox
update-alternatives: Linking //opt/bin/dirname to /opt/bin/busybox
update-alternatives: Linking //opt/bin/dmesg to /opt/bin/busybox
update-alternatives: Linking //opt/bin/dos2unix to /opt/bin/busybox
update-alternatives: Linking //opt/bin/du to /opt/bin/busybox
update-alternatives: Linking //opt/bin/echo to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ed to /opt/bin/busybox
update-alternatives: Linking //opt/bin/egrep to /opt/bin/busybox
update-alternatives: Linking //opt/bin/eject to /opt/bin/busybox
update-alternatives: Linking //opt/bin/env to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ether-wake to /opt/bin/busybox
update-alternatives: Linking //opt/bin/expr to /opt/bin/busybox
update-alternatives: Linking //opt/bin/false to /opt/bin/busybox
update-alternatives: Linking //opt/bin/fgrep to /opt/bin/busybox
update-alternatives: Linking //opt/bin/find to /opt/bin/busybox
update-alternatives: Linking //opt/bin/free to /opt/bin/busybox
update-alternatives: Linking //opt/bin/grep to /opt/bin/busybox
update-alternatives: Linking //opt/bin/gunzip to /opt/bin/busybox
update-alternatives: Linking //opt/bin/gzip to /opt/bin/busybox
update-alternatives: Linking //opt/bin/head to /opt/bin/busybox
update-alternatives: Linking //opt/bin/hexdump to /opt/bin/busybox
update-alternatives: Linking //opt/bin/hostname to /opt/bin/busybox
update-alternatives: Linking //opt/bin/id to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ifconfig to /opt/bin/busybox
update-alternatives: Linking //opt/bin/install to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ip to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ipcrm to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ipcs to /opt/bin/busybox
update-alternatives: Linking //opt/bin/kill to /opt/bin/busybox
update-alternatives: Linking //opt/bin/killall to /opt/bin/busybox
update-alternatives: Linking //opt/bin/killall5 to /opt/bin/busybox
update-alternatives: Linking //opt/bin/less to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ln to /opt/bin/busybox
update-alternatives: Linking //opt/bin/logger to /opt/bin/busybox
update-alternatives: Linking //opt/bin/logname to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ls to /opt/bin/busybox
update-alternatives: Linking //opt/bin/lsattr to /opt/bin/busybox
update-alternatives: Linking //opt/bin/md5sum to /opt/bin/busybox
update-alternatives: Linking //opt/bin/mkdir to /opt/bin/busybox
update-alternatives: Linking //opt/bin/mkfifo to /opt/bin/busybox
update-alternatives: Linking //opt/bin/mknod to /opt/bin/busybox
update-alternatives: Linking //opt/bin/mount to /opt/bin/busybox
update-alternatives: Linking //opt/bin/mv to /opt/bin/busybox
update-alternatives: Linking //opt/bin/nc to /opt/bin/busybox
update-alternatives: Linking //opt/bin/netstat to /opt/bin/busybox
update-alternatives: Linking //opt/bin/nice to /opt/bin/busybox
update-alternatives: Linking //opt/bin/nmeter to /opt/bin/busybox
update-alternatives: Linking //opt/bin/nohup to /opt/bin/busybox
update-alternatives: Linking //opt/bin/od to /opt/bin/busybox
update-alternatives: Linking //opt/bin/openvt to /opt/bin/busybox
update-alternatives: Linking //opt/bin/patch to /opt/bin/busybox
update-alternatives: Linking //opt/bin/pidof to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ping to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ping6 to /opt/bin/busybox
update-alternatives: Linking //opt/bin/printf to /opt/bin/busybox
update-alternatives: Linking //opt/bin/ps to /opt/bin/busybox
update-alternatives: Linking //opt/bin/pwd to /opt/bin/busybox
update-alternatives: Linking //opt/bin/readlink to /opt/bin/busybox
update-alternatives: Linking //opt/bin/realpath to /opt/bin/busybox
update-alternatives: Linking //opt/bin/renice to /opt/bin/busybox
update-alternatives: Linking //opt/bin/reset to /opt/bin/busybox
update-alternatives: Linking //opt/bin/resize to /opt/bin/busybox
update-alternatives: Linking //opt/bin/rm to /opt/bin/busybox
update-alternatives: Linking //opt/bin/rmdir to /opt/bin/busybox
update-alternatives: Linking //opt/bin/script to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sed to /opt/bin/busybox
update-alternatives: Linking //opt/bin/seq to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sh to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sha1sum to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sleep to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sort to /opt/bin/busybox
update-alternatives: Linking //opt/bin/stat to /opt/bin/busybox
update-alternatives: Linking //opt/bin/strings to /opt/bin/busybox
update-alternatives: Linking //opt/bin/stty to /opt/bin/busybox
update-alternatives: Linking //opt/bin/sync to /opt/bin/busybox
update-alternatives: Linking //opt/bin/tail to /opt/bin/busybox
update-alternatives: Linking //opt/bin/tar to /opt/bin/busybox
update-alternatives: Linking //opt/bin/tee to /opt/bin/busybox
update-alternatives: Linking //opt/bin/test to /opt/bin/busybox
update-alternatives: Linking //opt/bin/time to /opt/bin/busybox
update-alternatives: Linking //opt/bin/top to /opt/bin/busybox
update-alternatives: Linking //opt/bin/touch to /opt/bin/busybox
update-alternatives: Linking //opt/bin/tr to /opt/bin/busybox
update-alternatives: Linking //opt/bin/true to /opt/bin/busybox
update-alternatives: Linking //opt/bin/tty to /opt/bin/busybox
update-alternatives: Linking //opt/bin/umount to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uname to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uncompress to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uniq to /opt/bin/busybox
update-alternatives: Linking //opt/bin/unix2dos to /opt/bin/busybox
update-alternatives: Linking //opt/bin/unzip to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uptime to /opt/bin/busybox
update-alternatives: Linking //opt/bin/usleep to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uudecode to /opt/bin/busybox
update-alternatives: Linking //opt/bin/uuencode to /opt/bin/busybox
update-alternatives: Linking //opt/bin/vi to /opt/bin/busybox
update-alternatives: Linking //opt/bin/watch to /opt/bin/busybox
update-alternatives: Linking //opt/bin/wc to /opt/bin/busybox
update-alternatives: Linking //opt/bin/which to /opt/bin/busybox
update-alternatives: Linking //opt/bin/who to /opt/bin/busybox
update-alternatives: Linking //opt/bin/whoami to /opt/bin/busybox
update-alternatives: Linking //opt/bin/xargs to /opt/bin/busybox
update-alternatives: Linking //opt/bin/yes to /opt/bin/busybox
update-alternatives: Linking //opt/bin/zcat to /opt/bin/busybox
update-alternatives: Linking //opt/libexec/syslogd to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/arp to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/fdisk to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/fsck to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/hdparm to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/httpd to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/hwclock to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/insmod to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/klogd to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/losetup to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/lsmod to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/mkswap to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/modprobe to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/pivot_root to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/rdate to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/rmmod to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/route to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/start-stop-daemon to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/swapoff to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/swapon to /opt/bin/busybox
update-alternatives: Linking //opt/sbin/sysctl to /opt/bin/busybox
Successfully terminated.

3. Set up a Linux Swap area

root@mygateway:/# /opt/bin/busybox mkswap /mnt/myswap.swp
Setting up swapspace version 1, size = 81915904 bytes
root@mygateway:/#
root@mygateway:/# /opt/bin/busybox swapon /mnt/myswap.swp
root@mygateway:/#

4. Lets check if we see it with free command:

root@mygateway:/# free
total used free shared buffers
Mem: 58656 50540 8116 0 856
Swap: 79992 0 79992
Total: 138648 50540 88108
root@mygateway:/#

Okay, its there. After starting a couple of snort and tcpdump and a torrent download, the router started to use the swap:

root@mygateway:/tmp/mnt# free
total used free shared buffers
Mem: 58656 53064 5592 0 92
Swap: 79992 3380 76612
Total: 138648 56444 82204
Advertisements
Tagged: ,
Posted in: ddwrt, Linux