Swap file creation guide on Ubuntu 12.04

Linux partition of random access memory (RAM) into memory partitions called pages (pages). To free up RAM, Linux can use swap to copy the page down hard. Linux swap enables the system with more memory.

To ensure optimal server should not use swap with the normal hard drive, it’s best to use if the server uses the SSD hard drive. Best swap file size of the physical RAM of the server.

To create a swap file on Ubuntu 12.04, you follow the steps below

Check the swap file

Before proceeding to create swap file needs to check that the current system has created this file by running:

sudo swapon-s

If no swap file will display:

Filename Type Size Used Priority

Check free space

Use the command df to check free space

Filesystem 1 k-blocks Used Available Use% Mounted on
/dev/sda 20907056 1437188 18421292 8%/
udev 121588 121584 4 1%/dev
tmpfs 49752 49544 208 1%/run
5120 5120 0 none 0%/run/lock
none 0 0 124372 124372%/run/shm

Create a swap file

Run the command dd. here I create 1 GB swap for VPS 512RAM

sudo dd if =/dev/zero of =/swapfile bs = 1024 count = 1024k

Create a swap partition

sudo mkswap/swapfile


Setting up swapspace version 1, size = 1048572 KiB
no label, UUID = f79c0154-084b-4095-a846-88dfcdabbb60

Activate swap

sudo/swapfile swapon

Information swap file

Filename Type Size Used Priority
/swapfile file 262140 0-1

Set the swap is automatically used each time reboot the server.

echo/swapfile none swap defaults 0 0 > >/etc/fstab
echo swappiness = 0 vm. > > sysctl-p & &/etc/sysctl.conf

Swap file security by chmod

sudo chown root: root/swapfile
sudo chmod 0600/swapfile

Leave a Reply

Your email address will not be published.