20

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

x-man
  • 387

4 Answers4

26

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

the-wabbit
  • 41,352
3

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...)

2

You have to repartition the disk. If I remember well moving the begining of Linux partition isn't supported in parted but you can shrink your linux filesystem and partition as well and then make another swap at the end of your disk. You can't do this while the system is online.

Alternate solution is to use a big file as swap. (Don't know if it is a good idea nowdays.)

Stone
  • 7,279
0

1 Turn off all swap processes

sudo swapoff -a

2 Resize the swap

sudo dd if=/dev/zero of=/swapfile bs=1G count=8

if = input file
of = output file
bs = block size
count = multiplier of blocks

3 Make the file usable as swap

sudo mkswap /swapfile

4 Activate the swap file

sudo swapon /swapfile

5 Check the amount of swap available

grep SwapTotal /proc/meminfo