• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
sharadchhetri.com

sharadchhetri.com

Linux,Cloud Computing And DevOps

  • Home
  • Linux
  • CloudComputing
    • Introduction Cloud Computing
    • Amazon AWS
  • Free E-Books
  • About Me

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:/#

Do'nt be greedy, share the knowledge!

  • Click to share on Facebook (Opens in new window)
  • Click to share on WhatsApp (Opens in new window)
  • Click to share on Twitter (Opens in new window)
  • Click to share on Pinterest (Opens in new window)
  • Click to share on Reddit (Opens in new window)
  • Click to share on Pocket (Opens in new window)
  • Click to share on LinkedIn (Opens in new window)

Related

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

Follow Us

  • Facebook
  • Twitter
  • GitHub
  • YouTube

Recent Posts

  • Activate.ps1 cannot be loaded because running scripts is disabled on this system
  • How to install Java (OpenJDK) on Ubuntu Linux
  • How to install Groovy on Ubuntu 20.04 LTS
  • How to Disable selinux in Red Hat or CentOS
  • How to remove date from WordPress Post URL

Top Posts & Pages

  • How to delete mail queue in Postfix
  • How to fix read only USB pen drive in Ubuntu
  • How to start / stop / restart / reload iptables on CentOS 7 / RHEL 7
  • 4 different commands to check the load average in linux
  • How to set hostname and FQDN on CentOS 7 and RHEL 7
  • How to find absolute path of command on Linux / Unix : which command
  • How to create Jenkins user by command line and GUI
  • How to print particular line number by using sed command
  • How to setup Jenkins Credentials for Git repo access
  • make command not found in linux CentOS Red Hat ubuntu Debian

DevOps Posts

  • vagrant cloud flow

    Install Vagrant on Ubuntu and create first VM

  • git jenkins credential github

    How to setup Jenkins Credentials for Git repo access

  • terraform

    how to install terraform in Linux : CentOS-Ubuntu

  • docker image

    How to create Ubuntu docker base image

  • Install Ansible on Ubuntu / CentOS / RHEL

Footer

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Sharad Chhetri is an experienced Linux - Cloud Engineer & freelancer. Working on Open Source Technology since RHEL 4.0 (Red Hat Enterprise Linux). He loves sharing the knowledge which earned from real scenarios. Don't be surprised if you find him in technology seminars and meetup groups. You can contact him on email for freelance projects at admin@sharadchhetri.com. Read More…

Tags

Amazon AWS apache automation awk bash script CentOS centos 7 debian devops docker freebsd ftp ghost git grep hostname jenkins kvm linux linux command linux commands MariaDB Server mysql Nagios nginx Octopress owncloud Owncloud 6 php postfix postgres python Red Hat rpm sed selinux ssh swap ubuntu user management vagrant varnish virtualbox vsftp wordpress

Recent Comments

  • Sharad Chhetri on How to fix read only USB pen drive in Ubuntu
  • iain mckeand on How to fix read only USB pen drive in Ubuntu
  • Sharad Chhetri on Secondary Logging : save all users history command output as log
  • Sharad Chhetri on How to fix read only USB pen drive in Ubuntu
  • er on What is /dev/shm and how to mount /dev/shm
  • Bala on Send nagios report as pdf file via email
  • Terry on How to fix read only USB pen drive in Ubuntu
  • Terry on How to fix read only USB pen drive in Ubuntu

Copyright © 2009 - 2022 · All Rights Reserved sharadchhetri.com · · Privacy Policy ·
· sitemap.xml · ·The content is copyrighted to sharadchhetri.com and may not be reproduced on other websites without our permission. ·

Copyright © 2022 · Genesis Sample on Genesis Framework · WordPress · Log in