Guide: Using A Usb Thumb Drive As Swap


mindlord

Notices Two Things
Joined
Mar 10, 2006
Messages
1,786
Location
In a cave.
Website
Visit site
Ok, so dig it. I have a bunch of of flash disks, ranging from 64MB up to 1GB that I don't have much use for anymore. What's a good way to abuse them? Turn them into additional memory for my Pandora.

"That's LUNACY!", you say? "You'll kill your drive! It's dangerous! Think of the children! Oh, the humanity!"

Well, there's plenty of people on the Interwebs who will argue that using flash as swap in tight memory configurations is a dandy way to run larger programs when a physical drive is not available. So you crazy people who want to compile huge applications directly on the Pandora, have a way of extending your RAM, even if just temporarily. You could always format the drive back when you're done abusing it. Contrary to popular belief this will not burn the flash drive out in a matter of weeks or months. It will shorten it's life considerably, sure. In one example a fella has been using the same 2GB flash drive in an old computer with 256MB of RAM for FIVE YEARS! I wouldn't suggest doing this to your nice expensive 32GB SD card, but for cheap flash drives you don't need anymore... I say "Do it! Burn those suckers up".

The process is very simple.

1. Plug in your flash drive

2. Open a Termial

3. Type "sudo mkswap /dev/disk/by-id/" but don't hit return - hit Tab twice instead

4. You'll get a list of disk devices active in your system.
something like this:
Code:
mmc-SD-2G_0x204e732c
mmc-SD-2G_0x204e732c-part1
usb-Generic_STORAGE_DEVICE_000000009407-0:0
usb-Generic_STORAGE_DEVICE_000000009407-0:0-part1

We are obviosly looking for a USB device here, the mmc card is your SD card and we don't want to make it swap, although you could if you wanted to. Type the first few letters of the drive you want to make swap and hit Tab to autocomplete it. Don't worry if the drive has a "-part1" because you're about to wipe it out completely. Make a note of the drive id, you're going to need it again later.

5. Press enter and the Pandora will convert that USB disk into swap, but it's not active yet.

6. Once you've converted a disk to swap you don't have to repeat the previous steps - create two shell scripts:
usbswapon.sh
Code:
#!/bin/sh
gksudo swapon -p 32767 /dev/disk/by-id/[The id of the drive you plugged in]
usbswapoff.sh
Code:
#!/bin/sh
gksudo swapoff /dev/disk/by-id/[The id of the drive you plugged in]

You can check to see if you're swap is active with this command:
Code:
sudo swapon -s

The ID is unique, so even if you plug several USB drives into a hub, the Pandora will know which one it's supposed to use as swap.

*** Beware, so not unplug the USB stick while the swap is turned on unless you want your Pandora to crash immediately. Always "usbswapoff.sh" first.

Edit: Fixed "mkwap" typo.
 
Great guide!

Using swap is a _must_ in my opinion. I use it successfully on my N800's internal SD Card for years and I really see no problem using flash as swap. There is wear leveling after all.

It's also possible to adjust swappiness and other settings via config file to increase multitasking performance even further.
 
If I got a class 10 8gb SDHC for £18 on amazon, that would do nicely wouldn't it? I was thinking about getting a 16GB class 10 for £35, but if I get 2x8GBs I can shag one by using it as swap, and use the other for popping on my own bootable OS (with the bare minimun linux and DOSBOX/PUAE on top...)
 
You don't need to make a swap file from a whole SD card. It can be any size and you can use the rest for data.
 
I currently have a 4gb sd always in the pandora used for data ,could we have a tutorial on how i could partition 1 gb for swap ,or would 512 do the job ?
 
Suppose you could use the loopback idea that was talked about in the SDHC filesystem compression thread. Can you actually partition an SDHC anyway, and is there a read/write performance hit from doing so?
 
TitanUranus said:
Can you actually partition an SDHC anyway, and is there a read/write performance hit from doing so?
Yes. No.
I've partitioned my SDHC card for my BeagleBoard (as recommended) with no problems.
There's no guarantee that every device will be able to read such a partitioned card, however. Your camera, for example, may not be able to handle multiple partitions. Worst case, it doesn't read the card; best case, it can only use the first partition.
 
Last edited by a moderator:
I'm neither a Linux expert, nor Pandora owner. I suppose searching Google should reveal enough info. I suppose you can use a whole partition as swap if you partition with gparted or just create the swapfile itself somewhere. Kernel tweaks to adjust the swap behaviour can be done via sysctl.
 
mindlord said:
3. Type "sudo mkwap /dev/disk/by-id/" but don't hit return - hit Tab twice instead
Should be "mkswap". </nitpick>
 
Last edited by a moderator:
I have a couple questions as I'm new to the Pandora. How do I create a shell file? I've typed in all the script but when I get to that point it doesn't seem to work. Thanks for any help.

It says " MISSING OPTIONS OR ARGUMENTS you need to provide --desciption or --message."

I should also mention I'm doing this with a 4g sd card and not a usb drive.
 
Back
Top