Create Swap Space in Linux

Linux

[[email protected]]# free

          total        used        free      shared  buff/cache   available

Mem: 1014976 81368 122336 12944 811272 734480

Swap: 0 0 0

[[email protected]]# dd if=/dev/zero of=/swapfile bs=1024 count=1048576

1048576+0 records in

1048576+0 records out

1073741824 bytes (1.1 GB) copied, 13.2398 s, 81.1 MB/s

[[email protected]]# ls -lh /swapfile

-rw-r–r–. 1 root root 1.0G May 8 10:05 /swapfile

[[email protected]]# chmod 600 /swapfile

[[email protected]]# ls -lh /swapfile

-rw——-. 1 root root 1.0G May 8 10:06 /swapfile

[[email protected]]# mkswap /swapfile

Setting up swapspace version 1, size = 1048572 KiB

no label, UUID=ba9da34a-d07a-40a4-bd13-c869a982349a

[[email protected]]# swapon /swapfile

[[email protected]]# free

          total        used        free      shared  buff/cache   available

Mem: 1014976 77136 72720 12944 865120 746420

Swap: 1048572 0 1048572