-->
Previous Table of Contents Next


Linux and a Swap Disk

If you are using a PC with 4 megabytes of RAM, you may want to set up a swap partition. This partition is treated by the system as extended RAM; if you run low on memory (and with 4 megabytes of RAM, you’re guaranteed to), Linux can treat this hard disk section as RAM, or virtual memory. You’ll take a performance hit, as a hard disk will always be slower than real RAM, and you’ll have the joy of watching your hard disk churn furiously when you try to use a few applications. However, a swap partition can be used only for swap space by Linux; it can’t be used for any other storage. Therefore, you need to weigh your RAM needs versus your hard disk storage needs, keeping in mind that Linux should have as much hard disk territory for storage as possible.

You may also want to consider a swap partition if you have more than 4 megabytes of RAM. We’ve found that XFree86 is a little tight when running under only 8 megabytes of RAM, and some swap space can’t hurt, especially if you have a very large hard disk. (XFree86 won’t tell you that it’s low on RAM; it will simply refuse to do anything, such as failing to load an application.) Some Linux experts recommend that you have 16 megabytes of virtual memory. If you have only 8 megabytes of RAM, this would mean that you would want to set up at least an 8MB swap partition.

If you do want to create a swap partition, read on. If you don’t, you can skip to the next section, “Creating the Main Linux Partition.”

Your first move is to create a swap partition with the fdisk command. You’ll need to decide how large to make this partition. That will depend on how much free space you think you can give up on your hard drive. For the purposes of this chapter, we’ll devote 10 megabytes to swap space.

Run the fdisk command and choose the n option, for creating a new partition. You’ll see the following:


     Command action

        e   extended

        p   primary partition (1-4)

Type p, and enter the partition number. If you’ve already installed a DOS or OS/2 partition, you’ll need to select the number 2, as partition number 1 is already is use:


     Partition number (1-4): 2

You’ll then be asked where to place the partition and how large to make it. Generally speaking, you’ll want to place the partition immediately after the previous partition:


     First cylinder (64-1010): 64

Your numbers will undoubtedly be different. The point here is that fdisk automatically lists the first unassigned cylinder here (in this case, it was cylinder 64), and you should go with that number.

You’ll then be asked how large you want to make the partition:


     Last cylinder or +size or +sizeM or +sizeK (64-1010): +10M

Because we’re not into figuring out how many cylinders or kilobytes it would take to make up 10 megabytes, we use the easy way out and specify 10 megabytes directly as +10M.


NOTE:  This won’t apply to most users, but Linux doesn’t do very well if it’s installed as a boot partition on cylinder 1023 or above. (This occurs with very large hard drives—1 gigabyte or larger.) This has nothing to do with Linux, but rather with the limitations in the PC’s BIOS. Thus, you should avoid installing the Linux boot partition on a partition containing this cylinder or higher.

Fdisk then creates the partition. To make sure that everything went correctly, type p to see a list of the current partitions:


   Device Boot  Begin   Start    End  Blocks   Id  System

/dev/hda1   *      1       1     63   20762+   4   DOS 16-bit (32M)

/dev/hda2         63      64     95   10560   83   Linux native


NOTE:  The number of blocks listed here will be handy when you actually make this partition a swap partition. Jot it down.

Fdisk then gives you its command prompt; type w and exit.


NOTE:  You may notice that the hard disk is pretty quiet when you’re making all these changes to the partition. The fdisk command doesn’t make its changes until you type the w command to exit. You can make all the changes you want and change your mind many times, but until you type w, it won’t matter.

You’ll then want to use the mkswap command to make the partition a swap partition. The command line is quite simple: You list the partition you want to make a swap partition (remembering that Linux lists partitions as /dev/hda1, /dev/hda2, and so on) and the size of the partition in blocks. The command line would look like the following:


     # mkswap -c /dev/hda2 10560

We told you the number of blocks would come in handy!

The -c option checks for bad blocks on the partition. If mkswap returns any errors, you can ignore them, as Linux already knows of their existence and will ignore them.

After creating the swap partition, you’ll need to activate it with a command line like:


     #  swapon /dev/hda2

Finally, you need to tell the filesystem that /dev/hda2 is indeed a swap partition, again using the fdisk command. In this instance, you’ll need to change the type of the partition. When you created this partition, it was set up as a Linux native partition. However, Linux needs to explicitly know that this is a swap partition, so you need to change the type with the t command:


     Partition number (1-4): 2

     Hex code (type L to list codes): 82

Linux supports a wide range of partition types, as you’d see if you typed L. However, you can take our word for it; 82 is the proper hex code. (You don’t need to know every single hex code; there’s little reason for you to know that 8 is the hex code for AIX or that 75 is the hex code for PC/IX.)

Quit fdisk using w, making sure that your changes are written to disk. It will take a few seconds for this to happen.

You’re now ready to create your main Linux partition.


Previous Table of Contents Next