Linux expand swap virtual memory

The memory of my linux machine is a bit small, but last time I only allocated 2G of memory to swap, I suddenly felt that it was not enough today

Then expand the 10G swap virtual memory


1. First close the 2G swap memory in use:

swapoff /var/swap 
  • /var/swapThe location of the swap virtual memory file for my machine, according to their respective conditions.
  • If swap is not in use and execute this command, swap will be turned off immediately, if it is in use, it will wait for a while...

2.Delete the swap virtual memory file:

rm /var/swap
  • Or according to the actual situation of the respective swap file location

3. Use the dd command to create a file:

dd if=/dev/zero of=/var/swap bs=1M count=10240
  • The size is 1M*10240=10GB, allocate memory according to their respective conditions
  • of is followed by the location where you need to create swap
  • if no need to manage

4. Format the file just now as a swap file:

mkswap /var/swap
  • If there is no formatting, an error will be reportedswapon: /var/swap: read swap header failed

5.Open the swap file:

swapon /var/swap  
  • Followed by your swap file location

6. Set the system to automatically mount swap after booting

nano /etc/fstab

Add to/var/swap swap swap defaults 0 1

  • If your swap file location is the same as last time, no need to modify
  • If you change it, please delete the previous one and add it again

6.Check the swap situation:

free -m

Guess you like

Origin blog.csdn.net/qq_41490274/article/details/88690504