How to increase swap size?

Recently, I put more ram into my server and now I have got a total of 24GB of RAM. Originally, I setup the OS to have a 2GB swap size.

/dev/sdc1               1         281     2257101   82  Linux swap / Solaris
/dev/sdc2   *         282       60801   486126900   83  Linux

2GB is allocated for swap currently, but reading around it seems it is not much. For a system with 24GB, I am thinking to allocate at least 10GB of swap.

My questions is: Can I do it while the OS is running? Do I have to reinstall? I am using OpenSuse 11.3


You decided to create a separate swap partition upon installation. You can't resize it online - even an offline resize is going to take a considerable amount of time and bear the potential risk of damaging your subsequent filesystem on /dev/sdc2.

The easiest option to work around this is to either create a new swap partition on a different disk you don't currently use (or can afford to offline for re-partitioning) or simply use a swap file within an existing filesystem (which comes with some minor performance penalty due to the filesystem overhead).

The general procedure to add a swap partition/file:

  • create either a new partition of type 82h or a new 8 GB file using dd if=/dev/zero of=/swapfile bs=1M count=8192
  • initialize it using mkswap /swapfile or mkswap /dev/sdXX
  • use swapon /swapfile or swapon /dev/sdXX respectively to enable your new swap space on-the-fly
  • add an entry to /etc/fstab to make sure your new swap space gets activated upon reboot

Your current swap partition remains in use, you may want to get rid of it for the sake of complexity reduction. Just use swapoff /dev/sdc1 to disable its usage for the moment and remove the reference in /etc/fstab


Would you be needing swap in this case? I do not know what you have running on your system system, but i try to have enough memory in my servers to avoid swap completely... (i do have it, but only as a failsafe, if my server starts swapping, i buy more memory...)