Categories: Ubuntu

How to Create the Swap File on Ubuntu 12.04

What is swap?

Swap space is the area on a hard disk which is part of the Virtual Memory of your machine, which is a combination of accessible physical memory (RAM) and the swap space. Swap space temporarily holds memory pages that are inactive. Swap space is used when your system decides that it needs physical memory for active processes and there is insufficient unused physical memory available. If the system happens to need more memory resources or space, inactive pages in physical memory are then moved to the swap space therefore freeing up that physical memory for other uses. Note that the access time for swap is slower therefore do not consider it to be a complete replacement for the physical memory. Swap space can be a dedicated swap partition (recommended), a swap file, or a combination of swap partitions and swap files.

We will create a file called swapfile in our root (/) directory. The file must allocate the amount of space we want for our swap file.

Create the Swap File on Ubuntu 12.04

 

 1) Using the dd command 

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

 

2) Prepare the swap file by creating a linux swap area:

sudo mkswap /swapfile

3) The results display:

Setting up swapspace version 1, size = 262140 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb

4)  Activating the swap file:

sudo swapon /swapfile

 

 
How to Create the Swap File on Ubuntu 12.04, Hostripples Web HostingHow to Create the Swap File on Ubuntu 12.04, Hostripples Web Hosting
Vishwajit Kale
Vishwajit Kale blazed onto the digital marketing scene back in 2015 and is the digital marketing strategist of Hostripples, a company that aims to provide affordable web hosting solutions. Vishwajit is experienced in digital and content marketing along with SEO. He's fond of writing technology blogs, traveling and reading.
AddThis Website Tools

Recent Posts

Connecting to Amazon EC2 via WinSCP (SFTP): A Complete Guide

Managing files on your Amazon EC2 instances can often feel like navigating a complex maze, especially when you prefer a…

2 weeks ago

How Can I Connect to a Database with MySQL Workbench?

Welcome to the world of database management with MySQL Workbench! If you're new to databases or looking for a powerful,…

2 weeks ago

The Ultimate Favicon Guide for 2025: Get Started Today

Setting up a favicon for your website might seem like a small detail, but in 2025, it's more crucial than…

2 weeks ago

ChatGPT vs Google Gemini: The Ultimate Showdown

Due to the growing demand for artificial intelligence, two names stand out as titans in the realm of conversational AI:…

3 weeks ago

Core Web Vitals: The Future of Google Ranking Explained

Search engines are evolving rapidly, and they’re equivalent to refining their algorithms to sort the user experience. A significant manifestation…

4 weeks ago