How to Create Swap File Using Virtualmin Interface

Hi guys,
using the Virtualmin interface, how can we create a swapfile and size it to say 2GB?

i can create the file in Virtualmin File Manager, however, i dont know how we size it?

Also, are the any other things that have to be done to a swap file?

I don’t know how you’d do it in the GUI.

Here’s the basic steps (note below I’m using /swapfile as the swap name…which is the same name the Virtualmin install.sh uses if you created swap at install time; you probably want to delete it and create bigger one instead of adding another…see below for how):

Make an empty file of e.g. 2GB (must be root or use sudo):

# dd if=/dev/zero of=/swapfile bs=1024 count=2097152

Set it to only be readable by root (because memory can contain anything, including sensitive data):

# chmod 600 /swapfile

Format it for swap usage:

# mkswap /swapfile

Enable it in /etc/fstab (skip this if you already had swap on /swapfile):

# echo '/swapfile    none    swap    sw    0    0' >> /etc/fstab

Turn it on:

# swapon -a

If you already have swap on /swapfile, do the following first:

# swapoff -a
# rm /swapfile

And, then do the above steps.

5 Likes

ok. i missed that part in the other thread about this. i have actually just turned off the swapfile and increased its size, then chmod 600 and then turned it back on again.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.