Operating System - Linux
1830226 Members
1592 Online
109999 Solutions
New Discussion

How to create swap space on Linux.

 
SOLVED
Go to solution
walter crasto_1
Frequent Advisor

How to create swap space on Linux.

Hi,

Please let us know how to create new swap space on Red Hat Linux AS 2.1 & Red Hat Linux ES 3.0 OS.

Regards

Varian
2 REPLIES 2
Alexander Chuzhoy
Honored Contributor
Solution

Re: How to create swap space on Linux.

If you have free (unpartitioned) space on HD, then create a swap partition using fdisk. Then ,after reboot,
issue a command:
mkswap /dev/part
where part is the partition which you make swap.It can be /dev/hda{number} if it's an IDE drive or /dev/sda{number} if it's SCSI.

If all space is occupied by pertitions and you still wich to have swap:
1.
dd if=/dev/zero of=/swp.file bs=1048576 count=64
This command will create swp.file in root folder with size 64 MB.

Now you have to make it a swap file:
2.mkswap /swp.file

To activate the additional swap:
3. swapon /swp.file

If you want this swap to remain across reboots-add a respective entry to /etc/fstab.

Best regards.
Gopi Sekar
Honored Contributor

Re: How to create swap space on Linux.


I believe Alexander gave all required information.

Sample entry in /etc/fstab for swap:

swap swap defaults 0 0

incase a file is used for swap, then:
/path/to/file swap swap defaults 0 0

Remember the file path should be existing at the time of swap activation. i.e. incase you have this swap file on /mnt/disk then when the swap is trying to load the file /mnt/disk should be mounted and accessible. Easy way would be to have this entry as the final entry in /etc/fstab

Hope this helps,
Gopi
Never Never Never Giveup