Swap files management

Post your tutorials and howtos here.
User avatar
just
Posts: 297
Joined: 07 Nov 2013 08:06
Location: Rovaniemi, Finland

Swap files management

Postby just » 22 Oct 2014 01:36

swap file(s) management in linux is an extremely easy task. the job is done with a few simple commands.

before create or manage something, let's discover how much swap space is currently avaiable in the system:

Code: Select all

sudo swapon -s
let's create a new swap file. in this example it will be called justswap, and placed in the /1st directory. swap files may be created anywhere in the filesystem. we only need to have the read-write access to that location.

seems like it's possible to have any number of active swap files. i'm not aware of any limit for it.

let's say we will be creating 1G (1000M) swap file. first, we will make a zero-filled file of that size:

Code: Select all

sudo dd if=/dev/zero of=/1st/justswap bs=1M count=1000
then, tell the system it will be a swap file:

Code: Select all

sudo mkswap /1st/justswap
and finally, activate it:

Code: Select all

sudo swapon /1st/justswap
we have just added 1G to currently available swap space in our system.

if we don't need it anymore, we can flush and switch off either only one specific swap file at a time:

Code: Select all

sudo swapoff /1st/justswap
or flush and deactivate all swap file(s) and partition(s) at once:

Code: Select all

sudo swapoff -a
all swap files are flushed and switched off now. but the physical files still remain intact. to activate all available swap file(s) and partition(s) again:

Code: Select all

sudo swapon -a
to avoid manually create the swap file on each boot, we can simply add it to /etc/fstab:

Code: Select all

/1st/justswap none swap sw 0 0
or, if we have some partition(s) already formatted as linux-swap, add them to /etc/fstab as well:

Code: Select all

/1st/justswap none swap sw 0 0
/dev/sda3 none swap sw 0 0
/dev/sdb3 none swap sw 0 0
hopefully these few commands cover all practical needs.

User avatar
Snap
Posts: 1244
Joined: 25 Aug 2013 20:01
Location: Spain

Re: swap files

Postby Snap » 22 Oct 2014 07:16

Thanks for putting this together, just.
This likely means that your installation is broken. -Mr Pixbuf.

Image


Return to “Tutorials”

Who is online

Users browsing this forum: No registered users and 2 guests