OpenWrt Forum Archive

Topic: WRT54g->Make a swap partition on a SD-CARD?

The content of this topic has been archived on 20 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I bought a wrt54g 2.2,and now use open-wrt
and want to add a sd-card(1G),
Can i build a swap partition on SD-card to increase the poor memory of 16M?
how can i do that?need to rebuilt the knnel?
how to bulid?

If you can live with slooooooow swap... probably yes. Last time I measured throughput I ended up with something about 200kB/s.
Make sure that your SD mod will work with a 1GB card (I have tested several cards up to 512MB - successfully - but there have been reports of failure).
Kernel building instructions have been spotted in the wiki,

Thanks, has anyone tested to increase the memory of 16M to 32M or more?
I think more memory can execute more program and can increase the speed and stability of hard works,such as BT and Emule,is that true?

(Last edited by sdzx on 13 Jun 2006, 03:48)

I have looked around on how to build portable apps on http://portableapps.com/ which are designed for USB flash drives and remember the author specifically talking about methods of reducing cache, swap, etc to flash devices b/c it will destroy the flash device after so many writes. I am not certain of the differences b/w SD and other flash technologies as far as how many writes / flashes until that area of the chip goes bad but you may want to consider this as a swap partition may wear the chip away.

You could always buy older chips on sale once every 6 months though.

I have 20M of Swapspace on a SD-Card, just because one can do that. If its reasonable, i don't know... since the cards are cheap, i don't care if it's destroyed or useless. Perhaps it gets usefull if i load more work onto the router...

Unfortunatelly i lost the step-by-step tutorial i wrote while building the image via the image-builder, but because of much smoother ways to get swap onto the SD-Card, it's not that big loss. But i have the whole root filesystem on the SD-Card and don't use the build-in read-write flash. Thus, i get another _fast_ empty storage, but i don't use this either 0o.

For simple swap on the sd-card, simply get the mmc.o somewhere for your kernel (not that hard via some search engine [or just ask]), or read instructions to build it yourself (harder). Additional, some filesystem modules via ipkg ... kmod-ext2/ext3 or whatever you like most. Last but not least, you might need e2fsprogs to format your card. Write some nifty initscript, and you are done.

The only odd think i encountered was some limitation on the filesize of the swapfiles, but i didn't investigated this and simply created two times 10M.

ulmen wrote:

I have 20M of Swapspace on a SD-Card, just because one can do that. If its reasonable, i don't know... since the cards are cheap, i don't care if it's destroyed or useless. Perhaps it gets usefull if i load more work onto the router...
.

oh,bad news.  THE tutorial is very very important for me and other poor man,can you just even repeart the great thing again?best with pictures,hehe,hard works ,thanks

As said, the way i got my swap on the sd-card is very complex and propably not what one might want to use.

The first step was to get the whole root filesystem on the sd-card, as described in http://cryptomilch.de/~ulmen/openwrt/rootonmmchowto.
At this point, i would recommend just to mount the sd-card anywhere and use this mountpoint instead of /etc below instead of using my howto. The following steps apply either way.

Having a read-writeable root (or a read-writeable mountpoint), simply create a emtpy file of the desired size anywhere.

dd if=/dev/zero of=/etc/swapfile count=<desired size in blocks>

This may take quite long, because the speed of the sd-card is very poor.

Then, turn the file into a swapfile.

mkswap /etc/swapfile

The last step is to write a initscript to autoenable the swap at boot-time.

vi /etc/init.d/S15swapon
#!/bin/sh
swapon /etc/swapfile

and make it executable with

chmod +x /etc/init.d/S15swapon

Reboot or execute it by hand to have the swap enabled.

OH,thanks.
emm,i'd to test it sunday.Thanks any well

how to get mkswap and swapon?

Up,

The tutorial isn't online anymore... someone do know another one ?

Hi Guys,

As I see the idea here is to have more RAM.

Could the following approach be applied?
OS kernel itself and root-file system to be built for execution in-place (XIP) in the board flash – not compressed, and not copied to RAM?
I guess it will require a lot of changes – boot-loader, kernel, the image, but it will save some RAM usage.

boomer wrote:

Could the following approach be applied?
OS kernel itself and root-file system to be built for execution in-place (XIP) in the board flash – not compressed, and not copied to RAM?

On most platforms you have 4M flash and 16M ram, while you could technically use XIP it would mean using uncompressed code and the result would be that the flash would be full with little more than the kernel. Thus, it was decided that compressing the kernel and root filesystem was more important and no effort was spent on XIP.

SD is one of the few cases for XIP, but you won't be able to use it on the root filesystem (sd isn't direclty accessable) so the only place you'll be able to use it is the kernel. The amount of RAM you'd save, is limited by your ability to use the flash, meaning the most you'd save is maybe 3M. Is it really worth the trouble?

The discussion might have continued from here.