-->
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, youre guaranteed to), Linux can treat this hard disk section as RAM, or virtual memory. Youll take a performance hit, as a hard disk will always be slower than real RAM, and youll 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 cant 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. Weve found that XFree86 is a little tight when running under only 8 megabytes of RAM, and some swap space cant hurt, especially if you have a very large hard disk. (XFree86 wont tell you that its 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 dont, 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. Youll 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, well devote 10 megabytes to swap space.
Run the fdisk command and choose the n option, for creating a new partition. Youll see the following:
Command action e extended p primary partition (1-4)
Type p, and enter the partition number. If youve already installed a DOS or OS/2 partition, youll need to select the number 2, as partition number 1 is already is use:
Partition number (1-4): 2
Youll then be asked where to place the partition and how large to make it. Generally speaking, youll 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.
Youll then be asked how large you want to make the partition:
Last cylinder or +size or +sizeM or +sizeK (64-1010): +10M
Because were 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 wont apply to most users, but Linux doesnt do very well if its installed as a boot partition on cylinder 1023 or above. (This occurs with very large hard drives1 gigabyte or larger.) This has nothing to do with Linux, but rather with the limitations in the PCs 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 youre making all these changes to the partition. The fdisk command doesnt 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 wont matter.
Youll 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, youll 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, youll 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 youd see if you typed L. However, you can take our word for it; 82 is the proper hex code. (You dont need to know every single hex code; theres 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.
Youre now ready to create your main Linux partition.
Previous | Table of Contents | Next |