Next | Prev | Up | Top | Contents | Index

Increasing Swap Space on a One-Disk System

Suppose you don't have the luxury of a multiple-disk system. This section explains how to increase the size of the swap partition on a single disk. You can increase your available swap space by repartitioning your disk, as described earlier in this chapter, or you can add space with the swap(1M) command.

The swap(1M) command allows you to designate a portion of any disk partition as additional swap space. You can add swap space at any time and delete the new swap space when you no longer need it. There are several options available with this command, and the command is described completely in the swap(1M) reference page, but the most convenient method to use is to specify a normal system file as additional swap space.

To specify a file as additional swap space, you first create an empty file of appropriate size with the mkfile(1M) command. For example, if you wish to add 10 megabytes of swap space to your system, and you wish that space to be taken from the /usr file system, use the following mkfile command:

mkfile -v 10m /usr/tmp.O/moreswap

In this command, the -v option directs mkfile to be verbose in its output to you, which means that you see the following message as a confirmation that the file has been created:

/usr/tmp.O/moreswap 10485760 bytes

If you do not specify the -v option, mkfile does its work silently. The second field in the mkfile command is the size of the file. In this case, 10m specifies a file that is 10 megabytes in size. You can use b, k, or m as a suffix to the size argument to indicate that the size number is in bytes, kilobytes, or megabytes, respectively. For example, the following commands all produce files of 10 megabytes:

mkfile -v 10485760b /usr/tmp.O/moreswap

mkfile -v 10240k /usr/tmp.O/moreswap

mkfile -v 10m /usr/tmp.O/moreswap

Once your file is created, you can use the swap command to add it as additional swap space on the system. When you make your file, be certain that the file resides in the file system from which you wish to take the space. The /usr/tmp.O directory is a good place to use if you wish to use space from the /usr file system. Typically /usr will have more available space than the root file system (/). Note, however, that you can also use file systems mounted remotely via NFS. Complete information on using remote mounted file systems for swap space is available in the swap(1M) reference page.

To begin using your new file as swap space, give the following command:

/sbin/swap -a /usr/tmp.O/moreswap

The -a option indicates that the named file is to be added as swap space immediately. To check your new swap space, use the command:

swap -l

This command lists all current swap spaces and their status.

To make your new swap file permanent (automatically added at boot time), add the following line to your /etc/fstab file:

/usr/tmp.O/moreswap swap swap pri=3 0 0

Note that if you create a swap file in the /tmp directory of your root file system, the file is removed when the system is booted. The /usr/tmp.O directory of the /usr file system is not cleaned at boot time, and is therefore a better choice for the location of swap files. If you wish to create your swap files in the root file system, first create a /swap directory, and then create your swap files within that directory.


Next | Prev | Up | Top | Contents | Index