Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A server I am using was setup incorrectly with only 1G of swap space.

There are no more hard disk physical slots.

There is content on the existing disks.

I would like to resize the partition, but that has been said to be "questionable" with parted.

Does anyone have any suggestions on how to increase the amount of swap space without loss of data?

NFS-mounting swap space is not an option :)

share|improve this question
Could you say what kind of partitions do you use on your server, and how the partitions look like? Resize depends on the fs mostly. – Shiki Feb 2 '12 at 23:30
up vote 4 down vote accepted

Consider creating a swap file rather than a swap partition:

Create the file:

dd if=/dev/zero of=/swapfile bs=1M count=8192

Make it into swap:

mkswap /swapfile

Protect it:

chown root:root /swapfile
chmod 0600 /swapfile

Activate it:

swapon /swapfile

Activate each boot:

vi /etc/fstab
/swapfile1 swap swap defaults 0 0
share|improve this answer
This is probably the most sensible solution. On modern linux systems, there's not much of a performance hit compared to a swap partition. – Journeyman Geek Feb 2 '12 at 23:51
It solves the immediate problem without downtime so that the server can be scheduled in for restructuring the volumes at a business friendly time. – Paul Feb 3 '12 at 0:00
Paul++ Thank you this solved it! – Daniel Feb 3 '12 at 19:46

You will want to use gparted, not parted, which does not handle resizing the filesystems within the partitions. There is a chance something can go wrong, but for the most part, it is quite reliable. As always, have a backup. BTW, had you set up the server initially using LVM, expanding the swap partition would be a snap. Not only reliable, but also wouldn't even require any downtime.

share|improve this answer
+1 for the LVM suggestion: that's the better solution for handy scalability. – dag729 Feb 2 '12 at 23:54

You do not make it clear how much downtime you can afford on the server. If it is nothing too important, I suggest that you make a decent full backup of the server, store it on another machine, think thoroughly about how to restore your server from that backup in case everything goes wrong -- and then just go ahead and resize your partitions. Yes, that is always a bit risky, but I had an excellent success rate in the past years.

As a side note -- it would be good operating practice to always have a good backup handy, anyway. If you had that, this question would not arise ;-)

share|improve this answer

You must log in to answer this question.

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