InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Ubuntu tutorials

  • How to add a user on Linux with sudo access
  • How to check if a user has password on Linux
  • How to install ViewVC for svn repository on Ubuntu Linux
  • How to setup ssl (https) for your site on Ubuntu Linux
  • Install rabbitmq on Ubuntu Linux
  • LXC (Linux Containers) - quick start tutorial on Ubuntu
  • Linux - command to check swap size
  • Linux - how to add a user using useradd
  • Linux - how to create a large file like 1GB
  • Linux - how to create swap partition
  • Linux - how to remove user from a group
  • Linux - number of cpus (lscpu)
  • Linux du - find disk usage of directories or files
  • NFS client and server handy commands
  • Setup svn repository on AWS Ubuntu with apache auth
  • Ubuntu - check if a service is upstart based
  • Ubuntu - dpkg and apt-get beginner tutorial
  • Ubuntu - find file to package
  • Ubuntu - find where will a package be installed from
  • Ubuntu - how to auto start services on boot using update-rc.d (sysv init)
  • Ubuntu - how to find boot autostart status of a service
  • Ubuntu - reload iptables rules during boot
  • Use x2go to access remote Ubuntu Linux
 
  • Home
  • > Tutorials
  • > Devops

Linux – how to create swap partition

| Last updated on Jan 29, 2017

Step to create swap partition on Ubuntu Linux. It should work on any other Linux also.

  1. Create storage file (say 4GB) using fallocate for swap partition
    $ sudo fallocate -l 4G /swap1
    
    Alternatively dd (slower) can also be used. To create file using 1M buffer size using dd

    $ sudo dd if=/dev/zero of=/swap1 bs=1M count=4096
    
  2. Make swap file only accessible by root
    $ sudo chmod 0600 /swap1
    
  3. Setup linux swap area in created file
    $ sudo mkswap /swap1
    Setting up swapspace version 1, size = 4194300 KiB
    no label, UUID=9551f5f9-5565-4753-81fd-9cc43a546daf
    
  4. To enabled swap file immediately
    $ sudo swapon /swap1
    
  5. To enable swap at boot time add the following to /etc/fstab
    /swap1 swap swap defaults 0 0
    
  6. To print swap summary
    $ sudo swapon -s
    Filename				Type		Size	Used	Priority
    /swap1                                  file		4194300	0	-1
    
    Alternatively use free -m to see swap size, etc.

    $ free -m 
                 total       used       free     shared    buffers     cached
    Mem:           992        778        214         64         28        231
    -/+ buffers/cache:        517        474
    Swap:         4095          0       4095
    
  7. To disable swap
    $ sudo swapoff /swap1
    

    This also removes it from /etc/fstab to not set it at boot time.

Suggested posts:

  1. AngularJS animattion using ng-class
  2. HTML – is closing li tag required?
  3. Linux – how to run a command as different user
  4. How to fix a broken sudoers file on AWS/EC2 Linux
  5. Linux – providing sudo access to a users – some best practices
  6. Linux – how to add a user using useradd
  7. Top 5 Free Screen Recorder Software For Windows 10
  8. document querySelector examples
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Devops, Linux, Tutorials, Ubuntu Linux
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress