How to Add Swap manually in Linux

Step-1: Go to directory /var/lib under root '/'
             logon to Linux, enter cd /var/lib
             confirm if you are in the mentioned directory or no,enter pwd, it must show /var/lib

Step-2: Enter the command to add the swap size, check below screenshot

Step-3: Now, initialize the swap to make use of it
             mkswap /var/lib/swap/swapnw

Step-4: Activate now
             swapon /var/lib/swap/swapnw

Step-5: Check if swap is maintained or no
             enter the command, cat /proc/swaps
             You can enter,
             free -m

Step-6: Adding swap without mount to the  file system might cause to lose the data, for this we probably need to mention and mount in the fstab(called File System Table).
            vi /etc/fstab
            Enter letter 'I' to Insert mode and edit
            Add as per the screenshot
            :wq! in order to save and quit from /etc/fstab
            To check;
            cat /etc/fstab

No comments:

Post a Comment