swap file

swap file

Postby Maroman » 26 Dec 2013, 11:39

imagine situation we need either more swap or we do not have partition for swap. there is a solution. we can create file as a swap. all must be done as a root so first enter
Code: Select all
sudo su
swapoff -a
to switch off all swaps (here and further on -a means all defined in fstab file).
next step is to create empty file. let say pagefile (here in root directory. well it's a little windowish vocabulary/name) of 256MB (this is scalable. you can use any number but remember the rule). we can use dd command
Code: Select all
dd if=/dev/zero of=/pagefile bs=1024 count=262144
to create empty file /pagefile of 1kB block, consists of 256*1024 blocks.
Code: Select all
mkswap /pagefile
to define /pagefile as a swap.
we need to modify /etc/fstab so using pluma
Code: Select all
pluma /etc/fstab
we can add (or exchange) a swap line
Code: Select all
/pagefile   swap swap   defaults   0   0
(there are tab signs between every elements).
save and mount partitions/files and swich on swap(s)
Code: Select all
mount -a
swapon -a
the result can be see using
Code: Select all
swapon -s
command (we can see all swaps - names and sizes) or
Code: Select all
free -m
(only size) and exit. close terminal. all is done. after every next boot the swap(s) is/are defined in fstab.

I hope any of you have no problem to delete swap file if not needed :good: .

ride my bike,
User avatar
Posts: 369
Joined: 02 Jun 2013, 09:17
Location: Warsaw Metropolitan Area, Poland

Return to Tutorials and Howtos

Who is online

Users browsing this forum: No registered users and 1 guest