Thursday, 29 February 2024

swap increase in linux

 

Option # 3 - Create a swap file.

 

1. Create a swap file on the current File system for example on root, for this a new Directory can be created.

  

[opc@<HOSTNAME> ~]$ sudo mkdir /swap

 

2. Create a new file into this new directory, in this example a new file for 2Gb is create.

  

[opc@<HOSTNAME> ~]$ sudo dd if=/dev/zero of=/swap/swapfile1 bs=1M count=2048

  

3.  Create a new swap area on the file that has been created.

  

[opc@<HOSTNAME> ~]$ sudo mkswap  /swap/swapfile1

 

4. Change the permissions on the file.

 

  

[opc@<HOSTNAME> ~]$ sudo chmod 600 /swap/swapfile1

  

 

5. Add the swap partition to the /etc/fstab file as indicated below on this step

 

/swap/swapfile1    swap   swap      defaults       0 0


 

 

6. Load the new swap space that had been created for the Instance.

 

[opc@<HOSTNAME> ~]$ sudo swapon -a

  

 

7. To list the swap devices run the below command.

 

[opc@<HOSTNAME> ~]$ sudo swapon -s

 

 

The new swap area that the instance will have available can be checked with this command below.

 

  

opc@<HOSTNAME> ~]$ sudo free -m
total used free shared buff/cache available
Mem: 14763 256 11898 65 2608 14102
Swap: 12661 0 12661                 <<<====  Total Swap area
 
====
 

command Line Usage

# mount -o remount,size=1024M /dev/shm

The required filesystem size is set during the mount(8) operation.  Resize a mounted filesystem by using the remount option along with the new filesystem size.

/etc/fstab Usage

tmpfs /dev/shm tmpfs size=1024M,defaults 0 0

Using /etc/fstab allows the size to be set automatically during system reboot.  If the line is missing just add it and reboot the O/S.

========