How to enable or disable multiple swap space in Linux
In this tutorial we will learn how to disable and enable the swap space. In this post we will see different scenario.The practical has been performed in Red Hat based Linux OS and Debian based OS.
Scenraio 1: How to disable and enable all swap space.
For eg. in your system if you have single swap space or multiple swap space follow the given below steps to enable /disable the swap space.
To Disable swap:
swapoff -a
To Enable swap
swapon -a
Scenario 2: If you have multiple swap space but want to enable or disable only particular swap area.
Use the below given syntax for particular swap space to enable or disable it
To enable (swapon), to disable(swapoff)
swapoffswapon swapoff swapon swapoff swapon
See below example of my system
Note: The command swapon -s
with show how many swap space are there and they are created in which device or file
root@ubuntu:/# swapon -s Filename Type Size Used Priority /swapfile-additional file 1048572 0 -1 /dev/mapper/ubuntu-swap_1 partition 1044476 0 -2 root@ubuntu:/# root@ubuntu:/# swapoff /dev/mapper/ubuntu-swap_1 root@ubuntu:/# root@ubuntu:/# swapon -s Filename Type Size Used Priority /swapfile-additional file 1048572 0 -1 root@ubuntu:/# root@ubuntu:/# swapoff /swapfile-additional root@ubuntu:/# root@ubuntu:/# swapon -s Filename Type Size Used Priority root@ubuntu:/# root@ubuntu:/#
Disable Multiple but selective Swap Area: You can select more than one swap device or file, in my case I have now 3 swap space in system, I will disable 2 swap space similarly you can select many swap space as you want.
root@ubuntu:/# swapon -s Filename Type Size Used Priority /dev/mapper/ubuntu-swap_1 partition 1044476 0 -1 /swapfile-additional file 1048572 0 -2 /swapfile-2 file 524284 0 -3 root@ubuntu:/# root@ubuntu:/# root@ubuntu:/# swapoff /swapfile-2 /dev/mapper/ubuntu-swap_1 root@ubuntu:/# root@ubuntu:/# swapon -s Filename Type Size Used Priority /swapfile-additional file 1048572 0 -1 root@ubuntu:/# root@ubuntu:/#
Enable Multiple but selective Swap Area:
root@ubuntu:/# swapon -s Filename Type Size Used Priority /swapfile-additional file 1048572 0 -1 root@ubuntu:/# root@ubuntu:/# swapon /swapfile-2 /dev/mapper/ubuntu-swap_1 root@ubuntu:/# root@ubuntu:/# swapon -s Filename Type Size Used Priority /swapfile-2 file 524284 0 -2 /swapfile-additional file 1048572 0 -1 /dev/mapper/ubuntu-swap_1 partition 1044476 0 -3 root@ubuntu:/#
If you want to know How to create swap file in Linux without reboot,Click Here