• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
sharadchhetri

sharadchhetri

AI, Linux, Cloud and DevOps

  • Home
  • Resources
    • Learn Linux
    • Articles
  • My Projects & Work
    • My Nagios Plugin
    • My Dockerhub Repo
    • My WordPress plugins
    • My Github Repos
  • Facebook Page
  • Contact
  • Privacy Policy
  • About Me
You are here: Home / Articles / Linux: Add swap without rebooting system

Linux: Add swap without rebooting system

August 5, 2013 by Sharad Chhetri Leave a Comment

In this tutorial we will learn how to add additional swap file in Linux after Operating System installation without rebooting the system. There is another method of adding swap space but the condition is you should have free space in Disk partition. Means additional partition is required to create swap space.

Problem Statement

What happen when your application require more swap and you do not have free space in Disk partition or additional disk in system ?

Solution :We have another method in which we will create a blank file with desired size and create as swap and mount in system.

ByDefault in AWS or Digital Ocean etc. the swap space is not present when you create a new instance or server in Cloud network.
This method will help you to add swap in system as well it can be use in any system (It is not cloud specific).

Create swap file in Linux

Step 1: Create a file with some size. Here in this example I am creating 1 GB means 1024 MB of file in a system

dd if=/dev/zero of=/swapfile-additional bs=1M count=1024

References:

dd = It is a unix command used for convert and copy a file

if = read from FILE instead of stdin

/dev/zero = /dev/zero is a special file in Unix-like operating systems that provides as many null characters (ASCII NUL, 0x00) as are read from it

of = write to FILE instead of stdout

/swapfile-additional = file named swapfile-additional will be created in /

bs = Read and write bytes at a time but if you do not mention MB or GB like only number it will read as bytes. for eg. bs=1024 means 1024 bytes

count = Copy input blocks in our case it is 1024 (1M * 1024 = 1GB)

Step 2: Make the file as swap area

mkswap /swapfile-additional

Step 3: Now edit the /etc/fstab file and append the below given lines

/swapfile-additional			swap swap    0   0

Step 4: Now mount the swap area (This command helps in mounting as well as system reboot is not required after using this)

mount -a

Step 5: Enable all swap area

swapon -a

Step 6: Now check how many swap area you have in your system

swapon -s

Below is the reference of my Linux Box after hitting the “swapon -s” command. Because one swap was already present in system after addition it is showing two swap area

root@ubuntu:/# swapon -s
Filename Type Size Used Priority
/dev/mapper/ubuntu-swap_1 partition 1044476 364 -1
/swapfile-additional file 1048572 0 -2
root@ubuntu:/#

Step 7: Now verify Swap is activated or not

free -m

Given below is the output

root@ubuntu:/# free -m
total used free shared buffers cached
Mem: 1001 921 80 0 30 736
-/+ buffers/cache: 154 846
Swap: 2043 0 2043
root@ubuntu:/#

Share this:

  • Share on X (Opens in new window) X
  • Share on Facebook (Opens in new window) Facebook
  • More
  • Print (Opens in new window) Print
  • Email a link to a friend (Opens in new window) Email
  • Share on LinkedIn (Opens in new window) LinkedIn
  • Share on Reddit (Opens in new window) Reddit
  • Share on Tumblr (Opens in new window) Tumblr
  • Share on Pinterest (Opens in new window) Pinterest
  • Share on Telegram (Opens in new window) Telegram
  • Share on WhatsApp (Opens in new window) WhatsApp
  • Share on Mastodon (Opens in new window) Mastodon

Articles

How to find swap partition or file in linux
6 df Command Examples To Check Mounted Filesystem On Linux
fatal error: error writing to /tmp/ccwAjc9Z.s: No space left on device
Essential Linux Commands Every Beginner Should Know | With Examples
Learn tar command and know about its precaution
Recover Linux Grub Password in linux rescue mode CentOS/Red Hat
Install and compile Nginx on Ubuntu 18.04 LTS server
Create new swap file on CentOS 7 / RHEL 7
How to create own Git Server with Gitolite and Gitweb in Ubuntu
Linux enable or disable multiple swap space
list files and directories by 4 commands in linux
How To Upgrade Ubuntu 16.04 To 18.04 LTS Desktop
Create bootable usb key for CentOS 7 installation
How to know how many swap space exist in linux system
How to fix read only USB pen drive in Ubuntu

Filed Under: Articles Tagged With: swap

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Articles

  • Install n8n docker in Ubuntu for practicing
  • Bash Script: MySQL Database backup to AWS S3
  • Automate no touch Jenkins setup wizard on docker (jcac)
  • How to run and configure Jenkins in Docker container
  • Complete Guide: How to install Nagios Monitoring on AlmaLinux / Rocky Linux
  • Install KVM on Ubuntu 24.04 LTS ( Bash Script )
  • How to install GIMP 2.10 on Ubuntu / Debian
  • 5 ways to check Ubuntu version of system (commands and GUI)
  • How To Solve Forgot MySQL / MariaDB Root Password
  • Create Self Hosted Build Agent Docker Image for Azure DevOps

Copyright © 2026 ยท
The material in this site cannot be republished either online or offline, without our permission.
Proudly Blogging From India.

  • Contact
  • About Me
  • My WordPress plugins
  • Privacy Policy