OK, here's what's going on.

I've got a RedHat 5 server with a swap partition (/dev/sda3) that's 3GB.

For some reason swap memory is still being taken up on / (/dev/sda2), and fills up the drive on occasion. Is there a way I can tell my system that if it needs to use HD space for swap, to use a different drive?

  • Are you sure that swap is filling up /, and not temporary files (or log files, or something else)? – mattdm Apr 7 '11 at 15:40

To find really what is using your space, use df to see the partition layout and disk usage, and du / -h --max-depth=1 to get an estimative of directory sizes and from that see what is happening.

Also, swapon -s will show exactly what swap devices are being used and how much of each one is occupied.

  • I've done searches for large files, tmp files, and even moved some larger stuff off the partition to another one. Space keeps filling up. After a fresh reboot I get the space back, then it fills up again eventually. – Devar-TTY Apr 7 '11 at 15:15
  • @rkalajian That sounds like /tmp or some kind of logfile, not swap. Do you have tmpfs or ramfs? Add the output of your df to your question. – coredump Apr 7 '11 at 15:17
  • @coredump Logs are on a seperate partition, and /tmp is clean. 'df' shows: /dev/sda2,2972268,1933592,885256,69% / - /dev/sda,131581128,33872852,90916400,28%,r5 - /dev/sdb1,481711200,142404696,314442304,32%,/data2 - tmpfs,4155412,0,4155412,0%,/dev/shm – Devar-TTY Apr 7 '11 at 15:21
  • Yeah that output shows nothing really wrong. See if free is showing your swap enabled. – coredump Apr 7 '11 at 15:27
  • 1
    You can also use files; you don't have to use partitions, and you don't have to use something like swapd to do so. – mattdm Apr 7 '11 at 15:37

Ignoring all the parts of your question that make no sense, you can use mkswap to format a device to use as swap, and you can use swapon to activate it. Add it to /etc/fstab if you want to make it permanent.

  • I've already got a swap device, and no means to add a new device for additional swap space right now. I'm looking into creating a swap file on an additional partition, but I need to know it'll take precedence over filling up / when the actual swap drive overflows. – Devar-TTY Apr 7 '11 at 15:26
  • 1
    @rkalajian — look at man swapon for how to set the relative priority of your swap devices. (This can go in fstab, too.) – mattdm Apr 7 '11 at 15:39
  • @mattdm - That sounds like exactly what I need. – Devar-TTY Apr 7 '11 at 15:43

You can simply follow the below steps to create a additional swap partition on Linux.

  • Just create a partition with fdisk command and change it's partition code for Linux swap partition e.g. 82.

  • now use command mkswap drive_name to create the swap signature, then use swapon drive name command to activate the swap partition.

For example, to create swap partition type:

mkswap /dev/sdb1

and to activate it

swapon /dev/sdb1

Note : I have mentioned /dev/sdb1 for example purposes, you use the drive as per your scenario.

now mount the created swap partition on /etc/fstab file.

for testing you can use below commands :-

swapon -s shows swap usage summary by device

free -m Display amount of free and used memory in the system

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.