4.1 Create Swap space

-

Swap is disk space that is used when the amount of physical RAM memory is full. Inactive pages are moved from the RAM to the swap space. With a RAM of only 1G, creating swap space is recommended.

Check if swap is enabled. No swap shows as a blank line.

sudo swapon --show

This will add a 1G swap file. This is about right for doubling our RAM.

Create a file to be used for swap

sudo fallocate -l 1G /swapfile

Set file permissions only for root.

sudo chmod 600 /swapfile

Set up a Linux swap area.

sudo mkswap /swapfile

$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=c83cd3a3-08e4-4997-ad46-6e8113528c16

Activate

sudo swapon /swapfile

Check your new swap space.

sudo swapon --show

 
 $  sudo swapon --show
NAME      TYPE  SIZE USED PRIO
/swapfile file 1024M   0B   -2

Edit the available disk partition on the file systems table.

sudo nano /etc/fstab

Paste the following line at the end of the file. This will retain the swap after a reboot.

/swapfile swap swap defaults 0 0

My fstab looks like this:

LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
LABEL=UEFI      /boot/efi       vfat    defaults        0 0
/swapfile swap swap defaults 0 0

Additional Reading

How to Add Swap Space on Ubuntu 18.04

No comments:

Post a Comment

Introduction to Linux Command Line

SSH is the way you will connect to your Linux server. You will need to understand the basics of the Linux Command Line.