Swap space in Linux is used when the amount of physical memory (RAM) is full. If the system needs more memory resources and the physical memory is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM. Swap space is located on hard drives, which have a slower access time than physical memory.
The size of your swap space should be equal to twice your computer's RAM, or 32 MB, whichever amount is larger, but no more than 2048 MB
Adding Swap Space
1) Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:
* At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.
* At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.
* At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.
Warning
Changes take place immediately; be careful when you type.
* Exit parted by typing quit.
2) Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:
Quote:
mkswap /dev/hdb2
3) To enable the swap partition immediately, type the following command:
Quote:
swapon /dev/hdb2
4) To enable it at boot time, edit /etc/fstab to include:
Quote:
/dev/hdb2 swap swap defaults 0 0
The next time the system boots, it will enable the new swap partition.
5) After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command
cat /proc/swaps or free.
The size of your swap space should be equal to twice your computer's RAM, or 32 MB, whichever amount is larger, but no more than 2048 MB
Adding Swap Space
1) Create the swap partition using parted or fdisk. Using parted is easier than fdisk; thus, only parted will be explained. To create a swap partition with parted:
* At a shell prompt as root, type the command parted /dev/hdb, where /dev/hdb is the device name for the hard drive with free space.
* At the (parted) prompt, type print to view the existing partitions and the amount of free space. The start and end values are in megabytes. Determine how much free space is on the hard drive and how much you want to allocate for a new swap partition.
* At the (parted) prompt, type mkpartfs part-type linux-swap start end, where part-type is one of primary, extended, or logical, start is the starting point of the partition, and end is the end point of the partition.
Warning
Changes take place immediately; be careful when you type.
* Exit parted by typing quit.
2) Now that you have the swap partition, use the command mkswap to setup the swap partition. At a shell prompt as root, type the following:
Quote:
mkswap /dev/hdb2
3) To enable the swap partition immediately, type the following command:
Quote:
swapon /dev/hdb2
4) To enable it at boot time, edit /etc/fstab to include:
Quote:
/dev/hdb2 swap swap defaults 0 0
The next time the system boots, it will enable the new swap partition.
5) After adding the new swap partition and enabling it, make sure it is enabled by viewing the output of the command
cat /proc/swaps or free.