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

sharadchhetri

Tutorials On Linux, Unix & Open Source

  • Home
  • Linux Commands
  • Resources
    • Learn Linux
  • My WordPress plugins

Add swap file in linux without reboot after OS installation

August 5, 2013 by Sharad Chhetri Leave a Comment

Add swap file in linux without reboot after OS installation

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.

Question: What happen when your application require more swap and you do not have free space in Disk partition or additional disk in system ?
Answer: We have another method in which we will create a blank file with desired size and create as swap and mount in system.

Now a days cloud computing is in hype and it is good to give example of Cloud Server or Instances.

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).

To create a swap file follow the given below steps

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

What is –

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

Below is the output of my linux system

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:

  • Twitter
  • Facebook
  • More
  • Print
  • Email
  • LinkedIn
  • Reddit
  • Tumblr
  • Pinterest
  • Pocket
  • Telegram
  • WhatsApp
  • Mastodon

Related posts:

  1. Set hostname and FQDN in Ubuntu without reboot
  2. How to find swap partition or file in linux
  3. Create new swap file on CentOS 7 / RHEL 7
  4. Linux enable or disable multiple swap space
  5. How to know how many swap space exist in linux system
  6. Yum command to download rpm file without installing in linux system
  7. How to add/install Ubuntu fonts in CentOS/Red Hat Linux
  8. NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/vshell.conf file
  9. How to enable direct ssh to EC2 linux instance without keypair file
  10. Read the file inside compressed .gz files without extract

Filed Under: Linux 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

Our Social Media Presence

  • Facebook
  • GitHub
  • Twitter

Linux Command

What is Linux Internal And External Command

Linux Basic Commands With Examples For Every Beginner

tr command to convert lines to space , tab and vertical tab

smbpasswd command not found on CentOS 7 and RHEL 7

Solution : semanage command not found

Unix / Linux : How to print duplicate lines from file

More Posts from this Category

You Might Like These Articles!

simplecodesyntax wordpress plugin

SimpleCodeSyntax : My Another WordPress Plugin

Install Nginx

How To Install Nginx On Ubuntu 22.04 LTS

Install Latest Git package in Ubuntu Operating System

How To Always Install Latest Git Package In Ubuntu Operating System

Bash script for installing VirtualBox on Ubuntu 22.04 LTS Desktop

Install VirtualBox On Ubuntu 22.04 LTS Desktop (Bash Script)

libfuse

dlopen(): error loading libfuse.so.2 – Got Error On Ubuntu

Failed to open/create the internal network

VirtualBox Error: Failed to open/create the internal network

Always Useful Tips And Tricks

30 useful Linux terminal keyboard shortcuts

Change default editor of crontab in Ubuntu

Agent admitted failure to sign using the key ssh

Non interactive ,without typing password do ssh to Server : By sshpass

Protect from w00tw00t.at.blackhats.romanian.anti-sec

How to reset forgot root password in CentOS 6.x and Redhat 6.x

How to put slider shortcode only in home page in WordPress

Explore 90+ Article On "Linux Tips And Tricks"

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

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