Here’s the way I added swap file in AWS EC2, t2.medium. At that time, I was using Jenkins in the computer, and Jenkins didn’t work because of less swap area.
Procedure
-
Create a file for swapping. I created 4GB file.
1234$ sudo dd if=/dev/zero of=/var/swapfile bs=1M count=40964096+0 records in4096+0 records out4294967296 bytes (4.3 GB) copied, 57.8032 s, 74.3 MB/s -
Format the file for swap.
123$ sudo mkswap /var/swapfileSetting up swapspace version 1, size = 4194300 KiBno label, UUID=b32db3ee-02db-4e1c-9a7a-06b5aa19b790 -
Change permission of the file.
1$ sudo chmod 600 /var/swapfile -
Enable swapping.
1$ sudo swapon /var/swapfile -
Check swapping.
123cat /proc/swapsFilename Type Size Used Priority/var/swapfile file 4194300 0 -1 -
Modify
/etc/fstab
for auto mounting.123456LABEL=/ / ext4 defaults,noatime 1 1tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /proc proc defaults 0 0swap /var/swapfile swap defaults 0 0