XMLTagsEditHistoryDiscussion (2)

Introduction

This document explains how to add more swap to a FreeBSD machine. We are focusing on FreeBSD Release 5.4. You can consult The FreeBSD HandBook for more information.

When you install FreeBSD with the defaults settings it will create a swap partition doubling the size of the available physical memory (RAM). If you want to add more swap later without reinstalling the entire OS in order to make room for a new swap partition then check out this commands that will allow you to make a swap file.

The Swap File

The swap file is just a file with special features that you can create and then use to add add more swap to the running system.

Kernel Config

First, you need to check our kernel config file, if you had never compiled a custom FreeBSD kernel before, check this link first.

Let's get started. Go to the config file directory:

# cd /sys/i386/conf

Open the config file (It's often called GENERIC. In my case YGGDRASIL):

# vi YGGDRASIL

Check whether the following line is uncommented. By default this line it not commented in the GENERIC kernel configuration file. This rule is available in the 5.x FreeBSD kernel.

device   md   # Memory "disks"

Abracadabra

The magic is going to begin now! We will create the swap file using the dd command. The filename is swap0, you can use any name for it, and we will create it on the /usr dir. The count flag its the file size, in this case its 128MB, because the block size (bs=1024k) is 1MB ;), try man dd for more information :)

# dd if=/dev/zero of=/usr/swap0 bs=1024k count=128

Then we set the right permissions on ''/usr/swap0' and then it will be ready to be used in on our system.

# chmod 0600 /usr/swap0

System Setup

You need to edit the rc.conf file to enable the swap file whenever the system boots.

# vi /etc/rc.conf

Add this line to the rc.conf file:

swapfile="/usr/swap0"

Now you can reboot the system.

If you want to enable the swap file without rebooting, then type

# mdconfig -a -t vnode -f /usr/swap0 -u 0 && swapon /dev/md0

That's all.

neb at gigax dot org

Last update: 2005-05-30 (Rev 2697)

svnwiki $Rev: 12966 $