Use an SD card as swap space on the XO laptop

Xo-Mmcsd

I posted this over at the OLPC News Forums, and decided to share it with Hackszine readers as well.

Most of the time, the 256MB in the XO Laptop is sufficient. But I use yum to install software, and it can be very memory hungry. I often run out of RAM when installing more than a few packages at once (or a single package that decides it needs a bunch of other packages to work properly). There are two things I suggest before using yum: 1) quit all activities except terminal and cross your fingers or 2) enable some swap space and not worry.

The quick and dirty way to enable swap space is to put an SD card that you don't care about into the XO, and run one of these commands:

Note that this will destroy whatever's on the SD card, and in the long run is not good for it because it puts a lot of wear and tear on it.

On the default operating system that came with your XO:

su
mkswap /dev/mmcblk0
swapon /dev/mmcblk0
exit

On a joyride, Update.1, or later:

sudo mkswap /dev/mmcblk0
sudo swapon /dev/mmcblk0

You can replace swapon /dev/mmcblk0 with swapoff /dev/mmcblk0 when you are done and want to remove the SD card, or shut down the machine then remove the SD card. Don't remove it while you're using it as a swap drive or the system will probably crash.

As with anything that has "su" or "sudo" in it, if you mistype something, you may damage the operating system. One safety tip I can suggest is that you type the command like this:

swapon /dev/mmc[TAB][TAB]

That invokes tab filename completion, where it will either type out mmcblk0 for you, or show you a bunch of options. If you see anything other than mmcblk0, or mmcblk0p1/2/3, you might have mistyped the command. (The p1, p2, etc variants may appear if the SD card has multiple partitions on it).

I use this all the time to give myself some extra memory. It is slow because it's swapspace on an SD card, but it's much better than running out of memory while running yum. (The consequence of running out of memory is that you end up with improperly installed software). This is also handy if you are going to run a ton of activities at once, or if you are planning to use memory-intensive apps that you install with Yum, such as openoffice, gnumeric, etc.

Posted by Brian Jepson | Jan 25, 2008 05:23 AM
Linux, olpc | Permalink | Comments (5) Bookmark and Share

Recent Entries

Comments

Newest comments listed first.

Posted by: Rick on January 26, 2008 at 9:23 PM

It did not work right away for me, swapon failed.
I had to do a mkswap /dev/mmcblk0 first


Posted by: Brian Jepson on January 27, 2008 at 3:03 PM

Thanks, Rick! I've updated the instructions (I mkswap'd this SD card a while back and forgot this essential step)


Posted by: Andrew Burgess on February 15, 2008 at 12:44 PM

You must disable suspend or your machine will
crash when suspending (suspend is enabled in
joyride builds and the soon to be released
update.1

Simply
echo 1 > /etc/ohm/inhibit-suspend
will do it.

You don't use a partition table, there is a bug
where shutting down with swap running can mash the
partition table of your sd card. So you need to
swapoff before shutting down or get very familiar
with repartitioning :-)

I like a partition table because bigger sd cards
can be partitioned 1G swap and the rest ext2

HTH


Posted by: Brian Jepson on February 15, 2008 at 12:49 PM

Thanks, Andrew! These are very good tips.

I have become very familiar with the repartitioning routine you describe. At one time, I tried formatting an SD card as an ext3 filesystem for supplementary storage, but it would get trashed so often that I decided to use it as swap. I haven't experienced a crash when suspending with the SD card in, but I suppose it's only a matter of time.

Has anyone tried modifying the shutdown scripts to umount and swapoff any SD card that happens to be in use before the bug kicks in?


Posted by: helmingstay on March 31, 2008 at 4:30 PM

here are relevant links to 2 major bugs between suspend and SD cards:


http://dev.laptop.org/ticket/6532
http://dev.laptop.org/ticket/4013


Leave a comment



Bloggers

Welcome to the Hacks Blog!

Brian Jepson.Brian Jepson


Jason Striegel.Jason Striegel


Philip Torrone.Phillip Torrone



See all of the books in the Hacks Series!
Advertise here.

Recent Posts

www.flickr.com
photos in Hacks More photos in Hacks