Saturday, July 25, 2015

How To Add Swap on Ubuntu

How To Add Swap on Ubuntu

If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. While swap space can help machines with a small amount of RAM,it should not be considered a replacement for more RAM.It will improve the system performance.



Faster way to Add Swap Space on Ubuntu

non-root account command:-

ubuntu@ip-192-168-100-222:~$ sudo dd if=/dev/zero of=/swapfile bs=1G count=4
4+0 records in
4+0 records out
4294967296 bytes (4.3 GB) copied, 83.598 s, 51.4 MB/s

root account command:-

ubuntu@ip-192-168-100-222:~# dd if=/dev/zero of=/swapfile bs=1G count=4
4+0 records in
4+0 records out
4294967296 bytes (4.3 GB) copied, 83.598 s, 51.4 MB/s


Standard Way to Add Swap Space on Ubuntu

non-root account command:-

ubuntu@ip-192-168-100-222:~$sudo fallocate -l 4G /swapfile

ubuntu@ip-192-168-100-222:~$ ls -lh /swapfile
-rw-r--r-- 1 root root 4.0G Apr 30 03:37 /swapfile

ubuntu@ip-192-168-100-222:~$ sudo chmod 600 /swapfile

ubuntu@ip-192-168-100-222:~$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=7d048ff0-2908-4c4b-9759-d0f59563684f

ubuntu@ip-192-168-100-222:~$ sudo swapon /swapfile

ubuntu@ip-192-168-100-222:~$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/swapfile                               file            4194300 0       -

ubuntu@ip-192-168-100-222:~$ free -m
             total       used       free     shared    buffers     cached
Mem:          2000        908       1092         16        129        676
-/+ buffers/cache:        102       1897
Swap:         4095          0       4095

****auto mount swap space after restart / shut down *****

ubuntu@ip-192-168-100-222:~$ sudo vi /etc/fstab
/swapfile   none    swap    sw    0   0

No comments:

Post a Comment

Gitlab Automation Project Showcase

My GitLab Projects Showcase 🚀 Welcome to my portfolio of GitLab projects. Each repository reflects my journey as an engineer, focusing...