Help - Search - Members - Calendar
Full Version: Don't Know How To Install Swap File
Linuxhelp > Support > Technical Support
I am installing my first version of Debian Linux on a new 80GB slave hard drive and I can't figure out how to make a swap file in the partitioning section. I finally went on without making one. Can I repartition my hard drive with cfdisk and how do I do it? It just wasn't one of the options avaiable when I was partitioning. By the way, this is my first install of Linux, so I am a very green newbie. Thanks in advance.
What version of Debian (stable, testing, unstable) ... what version was the installer (3.0r2, etc.)?

Is this for a workstation or server?

If you left any free space on the drive, you can create a swap partition now. Since it is an 80gb drive, I would use 1gb for swap.

Personally, I would use fdisk if it is available on your install.


fdisk /dev/hda

(use a different device than /dev/hda if required ... that is for primary master)

You should be at the fdisk prompt ... now do m to see the options available ...

press p tp print the current partition table...

to create a new partition, press n ...

If you don't have any space to create partitions, you can try and resize the main partition, but I don't recommend it.

If you are able to create a new partition, pick the start and for end use +1G

after that, you need to print the partition table again using the p command, making sure your new partition is there.

Now we need to change the type to swap ... use the command:


to change a partition's system id. Enter the partition number of the new partiton you created (maybe either 2 or 3 ... it is on the printout of the partition table) then, Enter 82 for the new type.

When completed, do p again to print the partition table ... if eveything looks good (a new partition, 1 gb, type Linux Swap) we can write this new table to disk

{so far nothing has been changed, so if it is wrong, use q to quit ... and reenter fdisk and try again.}

If everything looks good, use the command w to write the partition table.

fdisk should exit ... then use the command:

fdisk -l

to verify the swap partition is written...

if it is there, you can do the command:

mkswap /dev/hda3

(make sure you use the partition that is labeled as swap ... in my example I use hda3 ... yours may be different)

now you need to edit the /etc/fstab and add a swap entry .... it will look like this (again .. I'll assume /dev/hda3 ... you use the correct partition number):

/dev/hda3       none            swap    sw              0       0

Now you should be able to issue the command:

swapon and be using the swap ...

use the command:


and you should see the swap info ... here is an example from my debian test system:
top - 06:33:01 up 27 min,  2 users,  load average: 2.04, 1.79, 1.04
Tasks:  74 total,   4 running,  70 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3% us, 99.7% sy,  0.0% ni,  0.0% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    777296k total,   772492k used,     4804k free,    88880k buffers
Swap:  2104464k total,        0k used,  2104464k free,   551388k cached

If everything looks good ... it should also be there when you reboot.
So just to jump in here and ask a question, why would you need a gig of swap space? I think I have like 512 and I have never seen my swap meter move from zero. The fact that I have a gig of ram might have something to do with that, but still a gig of swap seems like over kill. Just wondering.
On a workstation, without alot of running processes, little (or no) swap is fine. Especially if you have 1-4 gb of RAM...but if you are going to start alot of processes, having lots of SWAP is good. The recommended amount of swap is normally 2x the amount of physical RAM in your machine .... but I would not install more than 1 GB on a normal install.

The real benefit of swap ... especially on a server ... is the ability to put little (or never) used memory ... after a period of time, into swap.

That allows memory to be used more efficiently for things that are necessary.

I have a machine that has 2 processors (2.4Ghz P4 Xeons) and 3gb of RAM as my workstation. It contains a TV Card and I use it to record movies to 240gb of hard drive space. When recording an Hour long show ... it uses almost all the RAM for disc cache ... and swaps other things out. It would be much less efficient without swap.

My 2 processor (1.8ghz P4 Xeon) 1GB Firewall / Mail Server / Web Server almost always has swap in use (right now it's 80 mb).

On my (2) 4 processor (3.06ghz p4 Xeon) Oracle servers with 8gb RAM, I have 2GB swap ... it is normally about 128mb full.

512mb is probably fine, but on an 80gb hard drive ... might as well setup 1gb swap. If I am not hurting for hard drive space ... I normally setup 1gb as swap. There is not a real right answer for this either ... here is a very interesting discussion at ... and the real experts are also equally split on this issue (if you need swap and how much swap).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.