How to add swap space online - without repartitioning?

Instead of resizing swap partition you can create a swap file. Example:

(Create (almost) 1GB file filled with zeros)
# dd if=/dev/zero of=/tmp/swap_file bs=1000 count=1000000
("Format" file as swap)
# mkswap /tmp/swap_file
("Mount" it)
# swapon /tmp/swap_file

Now you can use free or top to verify that available swap space really increased. Of course the trick above works only until reboot - if you want it to persist, just add (on your Gentoo) server swapon /tmp/swap_file to /etc/conf.d/local.start.

Comments

Kalyn

Kalyn wrote

Touchdown! That's a really cool way of pttuing it!

Dina

Dina wrote

That's the smart thinking we could all beineft from.

Comment