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

4 Answers 4


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

  • @synticon-dj thanks. the data on the disk where the swap is is crucial, and I have another disk which I can use. Do you think setting a different disk as swap will affect performance? Will I have to swapoff the /dev/sdc1?
    – x-man
    Jan 9, 2012 at 13:37
  • It will affect it one way or the other - if /dev/sdc2 is seeing a lot of use, this I/O competes with swap I/O. If you add another disk's partition as swap, you just add the swap I/O load to this disk. What is going to be beneficial for swap performance, is inevitably detrimental to your other I/O on the affected disk. That being said, nothing is as bad for your system's performance as a high number of pageout/pagein requests. If you see this, fix it by adding memory or reducing your system's memory footprint.
    – the-wabbit
    Jan 9, 2012 at 13:44
  • having two swap devices on different spindles will help your swap performance (as there are two disks which can be addressed simultaneously instead of just one to read from and write to). But as you should not see high I/O activity due to swapping anyway, you might prefer using just a single device/partition/file to ease administration
    – the-wabbit
    Jan 9, 2012 at 13:49
  • 1
    Note that a swapfile won't work if you're on a BtrFS. Two work-arounds are (1) make a loopback device or (2) use btrfs-swapon.
    – Diagon
    Dec 15, 2017 at 0:37
  • 1
    @the-wabbit How does one actually create the /etc/fstab entry to make sure the new swap gets activated on reboot? Jan 28, 2018 at 17:05

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

  • I'm on your side here, swap is mainly used to prevent crashes in case of (volatile) memory exhaustion and as soon as you start hitting platters your server is taking a hit I/O and/or bandwith wise, although SSDs can help they are at least 10 times slower than RAM which nowadays is really cheap. Prices of DDR3 ECC 1333MHz is about $1000 for 64GB (8x8GB)
    – Shadok
    Jan 9, 2012 at 14:12

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

  • Not every filesystem can be shrunk, even offline. Unfortunately, this affects popular choices like XFS (xfs.org/index.php/Shrinking_Support).
    – Sven
    Jan 9, 2012 at 13:28
  • @Stone does this mean reinstalling the OS?
    – x-man
    Jan 9, 2012 at 13:28
  • No. It means making backups:), booting a LiveCD, shrink the linux filesystem then the sdc2 partition and make a new swap at the end of the disk and reboot your system.
    – Stone
    Jan 9, 2012 at 13:30

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .