1. Run the free command to view the Swap partition size in the system. Free-mtotalusedfreesharedbuffers &
1. Run the free command to view the Swap partition size in the system.
Free-m
Total used free shared buffers cached
Mem: 2012 1960 51 0 748 950
-/+ Buffers/cache: 260 1751
Swap: 255 0 255
We can see that Swap is only 255 M. Next we will expand it to 2G.
2. Create a Swap file.
Mkdir/swapfile
Cd/swapfile
Sudo dd if =/dev/zero of = swap bs = 1024 count = 2000000
The following message is displayed. The count in the preceding command indicates the swap file size.
Recorded 2000000 + 0 reads
Records 2000000 + 0 writes
2048000000 bytes (2.0 GB) Copied, 63.3147 seconds, 32.3 MB/second
Convert the generated file to a Swap file
Sudo mkswap-f swap
Setting up swapspace version 1, size = 1999996 KiB
No label, UUID = fee9ab21-9efb-47c9-80f4-57e48142dd69
3. Activate the Swap file.
Sudo swapon swap
View the free-m result again.
Total used free shared buffers cached
Mem: 2012 1971 41 0 572 1156
-/+ Buffers/cache: 241 1770
Swap: 2209 0 2209
Added successfully.
Extension:
If you need to uninstall the swap file, you can enter the created swap file directory. Run the following command.
Sudo swapoff swap
If you need to keep this swap, you can write it into the/etc/fstab file.
/Swapfile none swap defaults 0 0